You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* detect current device and be applicable for mps (apple silicon)
* calculate NLL with cpu even user specify for using mps
* send tensors to cpu at the begging of the run_gtpq
* debug for aligning v1.1.0 release
* raise error if quantizer is not gptq
* fix settings and readme
* bugfix: inference
* remove unused import
* fix: comment No3, 4, and 5
* fix: Comment No.7,8, and, 12
* add new test file for comment No.12
* fix: Comment No6 and 10
* fix Comment No2
* fix: comment No1
* fix No.9; add docs
* update lock file
* fix conflict
* fix conflict in CHANGELOG
* add docs for mps
Copy file name to clipboardExpand all lines: CHANGELOG.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,13 @@
1
1
# Change log
2
2
3
+
## [v1.2.0+mps] 2026-06-05
4
+
5
+
### Apple Silicon / macOS support
6
+
7
+
-**MPS quantization**: GPTQ (and AutoBit with GPTQ-only candidates) on `device="mps"`; cross-platform `empty_cache()` via new `onecomp/utils/device.py` (`runner.py`, `quantizer/gptq/_gptq.py`, `quantizer/_quantizer.py`)
8
+
- **MPS device placement (GPTQ on CPU, QEP correction on MPS)**: With `device="mps"`, `run_gptq` moves the Hessian and weights to **CPU** for the full column-wise GPTQ loop (including inverse-Hessian Cholesky). The main reason is not absent Cholesky kernels on MPS (recent PyTorch supports them); if the GPTQ loop stayed on MPS, `maxq.item()` inside `quantize()` would run once per column—each call waits for pending MPS work to finish and read back a single scalar to the host (per-column host sync), not a full matrix copy per column—and that overhead is often several times slower than CPU on Apple Silicon (~4× in internal benchmarks with PyTorch 2.12). When QEP weight correction runs (`adjust_weight`, typically under `qep=True`), per-layer work stays on **MPS** (e.g. `weight @ delta_hatX`); only the Cholesky solve uses CPU via `_safe_cholesky_and_solve` (one solve per layer). A full CPU fallback for QEP does not materially improve speed. Calibration forwards may still use MPS. Details: README (macOS / MPS).
9
+
-**MPS inference**: load saved quantized models on Mac with `QuantizedModelLoader` + Transformers `generate()` (GemLite/vLLM remain Linux + CUDA)
10
+
-**macOS `uv sync`**: added `darwin` to `tool.uv.environments`, `--extra mps` for MPS-enabled PyTorch from PyPI; `--extra cpu` is Linux-only (pytorch-cpu index); Linux-only markers on CUDA extras (`cu118`–`cu130`)
Copy file name to clipboardExpand all lines: README.md
+47-4Lines changed: 47 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,6 +100,30 @@ import torch
100
100
print(torch.cuda.is_available())
101
101
```
102
102
103
+
#### ✅ macOS (MPS)
104
+
105
+
On macOS, install PyTorch from PyPI (default wheels include MPS support). You do **not** need the CUDA index URLs above.
106
+
107
+
```bash
108
+
pip install torch torchvision torchaudio
109
+
```
110
+
111
+
Verify MPS:
112
+
```python
113
+
import torch
114
+
print(torch.backends.mps.is_available())
115
+
```
116
+
117
+
Then install OneComp from PyPI (see step 2 below). GPTQ quantization and Hugging Face `generate()` inference on MPS are supported; vLLM serving requires Linux with an NVIDIA GPU. An editable install from a git clone is **not** required for MPS use — see [for developers (pip)](#for-developers-pip) only if you are contributing to OneComp.
118
+
119
+
> **MPS device placement (GPTQ vs QEP)**
120
+
> With `device="mps"`, calibration and model forward passes can run on the GPU. The bottleneck is usually not missing Cholesky ops on MPS (recent PyTorch builds implement them); the implementation splits work as follows:
121
+
>
122
+
> - GPTQ (`run_gptq`): Hessian and weights are moved to CPU for the full column-wise loop (including inverse-Hessian Cholesky). If that loop stayed on MPS, `quantize()` would call `maxq.item()` once per column; each call triggers **per-column host sync** (wait for pending MPS ops, then read one scalar—not a full Hessian/weight copy every column)—often several times slower than CPU on Apple Silicon (e.g. ~4× in internal benchmarks with PyTorch 2.12). Keeping GPTQ on CPU avoids that overhead. With `mse=True`, `find_params` also calls `quantize()` in a grid loop and benefits from the same CPU placement.
123
+
> - QEP weight correction (`adjust_weight`, when QEP correction runs—typically `qep=True` with error propagation enabled): Per-layer work stays on MPS (e.g. `weight @ delta_hatX`, diagonal damping). Only the Cholesky solve uses CPU via `_safe_cholesky_and_solve` (one solve per layer, not per column); moving all of QEP to CPU does not materially improve speed. The subsequent GPTQ step still uses the CPU path above.
124
+
>
125
+
> DBF-based AutoBit fallback and multi-GPU quantization are not supported on MPS.
126
+
103
127
#### 2. Install `onecomp`
104
128
105
129
Once PyTorch is installed, you can install `onecomp`:
@@ -122,26 +146,41 @@ curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync --extra cu128 --extra dev --extra visualize
126
149
```
127
150
128
151
The `uv sync` command creates a Python virtual environment and installs all dependent libraries.
129
152
153
+
#### Linux (CUDA quantization / vLLM)
154
+
155
+
```bash
156
+
uv sync --extra cu128 --extra dev --extra visualize
157
+
```
158
+
130
159
The `--extra cu128` option installs the CUDA-enabled version of PyTorch (along with `torchvision` from the same CUDA index).
131
160
Replace `cu128` with the appropriate variant for your environment: `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, `cu128`, or `cu130`.
132
161
PyTorch will be automatically downloaded by `uv`, so you do not need to install it beforehand.
133
162
163
+
#### macOS (development / MPS inference)
164
+
165
+
```bash
166
+
uv sync --extra mps --extra dev --extra visualize
167
+
```
168
+
169
+
On macOS, use `--extra mps` only. CUDA extras (`cu118`–`cu130`), `--extra cpu` (Linux-only), and `--extra vllm` are not supported on macOS.
170
+
After `uv sync`, you can run GPTQ quantization and Hugging Face `generate()` inference on MPS; vLLM serving still requires Linux with an NVIDIA GPU.
171
+
See the **MPS device placement (GPTQ vs QEP)** note under [macOS (MPS)](#macos-mps) above for why GPTQ runs on CPU while QEP correction uses MPS.
172
+
134
173
Adding `--extra dev` installs development tools (black, pre-commit, pytest, pylint).
135
174
Adding `--extra visualize` installs matplotlib for visualization features.
136
175
Adding `--extra hydra` installs `hydra-core` for the example scripts and `model_validation/` runners that use Hydra-based configuration.
137
176
138
-
To use vLLM for serving quantized models, add `--extra vllm` together with `--extra cu130`:
177
+
To use vLLM for serving quantized models on Linux, add `--extra vllm` together with `--extra cu130`:
139
178
140
179
```bash
141
180
uv sync --extra cu130 --extra dev --extra visualize --extra vllm
142
181
```
143
182
144
-
> **Note:**`--extra vllm` is only compatible with `--extra cu130`. Recent vLLM releases require `torch>=2.10`, whose wheels are only published for the `cu130` index. Combining `--extra vllm` with `cpu` / `cu118` / `cu121` / `cu124` / `cu126` / `cu128` is rejected by `uv` at lock time.
183
+
> **Note:**`--extra vllm` is only compatible with `--extra cu130`. Recent vLLM releases require `torch>=2.10`, whose wheels are only published for the `cu130` index. Combining `--extra vllm` with `cpu` / `mps` / `cu118` / `cu121` / `cu124` / `cu126` / `cu128` is rejected by `uv` at lock time.
145
184
146
185
> **Note:**`--extra vllm` may take a long time on the first run if a pre-built `xformers` wheel is not available for your Python/CUDA combination (e.g. Python 3.13). Using Python 3.12 typically avoids this.
147
186
@@ -168,6 +207,8 @@ black --check onecomp/
168
207
169
208
### for developers (pip)
170
209
210
+
> **Note:** The editable install below is for developing OneComp from a local clone. **macOS users who only want MPS inference or quantization should use the [for users (pip)](#for-users-pip) flow** (`pip install torch` then `pip install onecomp` from PyPI); `pip install -e` is not needed for MPS.
211
+
171
212
```bash
172
213
git clone <git repository URL>
173
214
cd OneCompression
@@ -217,8 +258,10 @@ uv run pre-commit run --all-files
217
258
218
259
### Building Documentation Locally
219
260
261
+
`--extra docs` alone is sufficient (no PyTorch `mps` / `cu*` extra required):
The `uv sync` command creates a virtual environment and installs all dependencies.
124
+
125
+
### Linux (CUDA quantization / vLLM)
126
+
127
+
```bash
97
128
uv sync --extra cu128 --extra dev --extra visualize
98
129
```
99
130
100
-
The `uv sync` command creates a virtual environment and installs all dependencies (including `torchvision` from the same CUDA index as PyTorch).
101
-
Replace `cu128` with the appropriate CUDA variant for your system: `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, `cu128`, or `cu130`.
131
+
The `--extra cu128` option installs the CUDA-enabled version of PyTorch (along with `torchvision` from the same CUDA index).
132
+
Replace `cu128` with the appropriate variant for your environment: `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, `cu128`, or `cu130`.
133
+
PyTorch will be automatically downloaded by `uv`, so you do not need to install it beforehand.
134
+
135
+
### macOS (development / MPS inference)
136
+
137
+
```bash
138
+
uv sync --extra mps --extra dev --extra visualize
139
+
```
140
+
141
+
On macOS, use `--extra mps` only. CUDA extras (`cu118`–`cu130`), `--extra cpu` (Linux-only),
142
+
and `--extra vllm` are not supported on macOS.
143
+
After `uv sync`, you can run GPTQ quantization and Hugging Face `generate()` inference on MPS;
144
+
vLLM serving still requires Linux with an NVIDIA GPU.
145
+
See the [macOS / MPS guide](../user-guide/mps.md) for device placement and usage details.
102
146
103
147
Adding `--extra dev` installs development tools (black, pytest, pylint).
104
148
Adding `--extra visualize` installs matplotlib for visualization features.
105
149
106
-
To use vLLM for serving quantized models, add `--extra vllm` together with `--extra cu130`:
150
+
To use vLLM for serving quantized models on Linux, add `--extra vllm` together with `--extra cu130`:
107
151
108
152
```bash
109
153
uv sync --extra cu130 --extra dev --extra visualize --extra vllm
110
154
```
111
155
112
156
!!! note "vLLM requires the `cu130` extra"
113
-
Recent vLLM releases depend on `torch>=2.10`, whose wheels are only published for the `cu130` index. The `--extra vllm` declaration in `pyproject.toml` therefore conflicts with `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, and `cu128`; combining any of these with `--extra vllm` is rejected by `uv` at lock time.
157
+
Recent vLLM releases depend on `torch>=2.10`, whose wheels are only published for the `cu130` index. The `--extra vllm` declaration in `pyproject.toml` therefore conflicts with `cpu`, `mps`, `cu118`, `cu121`, `cu124`, `cu126`, and `cu128`; combining any of these with `--extra vllm` is rejected by `uv` at lock time.
114
158
115
159
!!! warning
116
160
Do **not** install vLLM with `uv pip install vllm` after `uv sync`. Packages installed via `uv pip` are not tracked by the lockfile and will be removed or overwritten by subsequent `uv sync` or `uv run` commands. Always use `--extra vllm` instead.
|`--wbits WBITS`|`None` (auto)| Target bitwidth. When omitted, estimated from VRAM |
46
-
|`--total-vram-gb GB`|`None` (auto)| VRAM budget in GB for bitwidth estimation. When omitted, detected from GPU |
46
+
|`--total-vram-gb GB`|`None` (auto)| VRAM budget in GB for bitwidth estimation. When omitted, detected from CUDA GPU. **Required on MPS** when `--wbits` is omitted|
47
47
|`--groupsize GROUPSIZE`|`128`| GPTQ group size (`-1` to disable grouping) |
48
-
|`--device DEVICE`|`cuda:0`| Device to place the model on |
48
+
|`--device DEVICE`|`cuda:0`| Device to place the model on (`mps` on macOS)|
49
49
|`--no-qep`|| Disable QEP (enabled by default) |
50
50
|`--no-eval`|| Skip perplexity and accuracy evaluation |
51
51
|`--eval-original`|| Also evaluate the original (unquantized) model |
Provide exactly one of `model_id` or `path`. A `ValueError` is raised if neither is specified.
28
28
29
+
!!! note "macOS (MPS)"
30
+
On Apple Silicon, set `device="mps"` for GPTQ / AutoBit (GPTQ-only) quantization.
31
+
Only GPTQ quantizers are supported on MPS; DBF fallback and multi-GPU are not.
32
+
See the [macOS / MPS guide](mps.md) for details.
33
+
29
34
## Runner
30
35
31
36
`Runner` is the main entry point for quantization. It manages the full pipeline: loading the model, preparing calibration data, executing quantization, and providing evaluation utilities.
@@ -148,7 +153,7 @@ qep_config = QEPConfig(
148
153
|`general`|`bool`| Use generic (architecture-independent) QEP |`False`|
149
154
|`percdamp`|`float`| Damping percentage for Hessian regularization |`0.01`|
150
155
|`perccorr`|`float`| Correction percentage for error propagation |`0.5`|
151
-
|`device`|`str`|GPU device for QEP computations |`"cuda:0"`|
156
+
|`device`|`str`|Device for QEP computations (`"cuda"`, `"mps"`, `"cpu"`)|`"cuda:0"`|
152
157
|`exclude_layer_keywords`|`list[str]`| Layer keywords excluded from error propagation |`["mlp.down_proj"]`|
0 commit comments