Skip to content

Commit 6526c0f

Browse files
authored
Merge pull request #11 from FujitsuResearch/develop/v1-1-0
Develop/v1 1 0
2 parents 6bc6642 + 7e9defa commit 6526c0f

219 files changed

Lines changed: 24766 additions & 4350 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@ build/
66
models
77
.vscode/
88
.cursor/rules/benchmark-directory.mdc
9+
.cursor/rules/example-workflow.mdc
910
.cursor/rules/merge-request-review.mdc
1011
.cursor/rules/test-workflow.mdc
12+
.cursor/rules/gitlab-integration.mdc
13+
.cursor/rules/slurm-submit.mdc
1114
.hydra/
1215
*.out
1316
*.err
1417
md/*.md
1518
example/run_example.sh
16-
work/issue-*
19+
work/
1720
site/
1821
debug_code/
1922
.pytest_cache/
2023
*.pt
2124
# Large test data (download separately if needed for regression tests)
2225
tests/onecomp/quantizer/jointq/data/model_layers_0_self_attn_k_proj.pth
26+
.uv-sync.lock
27+
.uv-sync.done
28+
.uv-sync-vllm.lock
29+
.uv-sync-vllm.done
30+
.venv-vllm/

CHANGELOG.md

Lines changed: 242 additions & 2 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,43 @@
22

33
Fujitsu One Compression (OneComp) is a Python package for LLM compression.
44

5+
<p align="center">
6+
<img src="docs/assets/onecomp.gif" alt="OneComp" />
7+
</p>
8+
9+
## ⚡ Just one line.
10+
11+
```bash
12+
onecomp <generative AI>
13+
```
14+
15+
**That's all you need.** OneComp detects your GPU VRAM, picks the best bit-width per layer, quantizes with error propagation, evaluates, and saves — fully automatic.
16+
17+
```bash
18+
# Example
19+
onecomp meta-llama/Llama-2-7b-hf
20+
```
21+
22+
Or from Python:
23+
24+
```python
25+
from onecomp import Runner
26+
27+
Runner.auto_run(model_id="meta-llama/Llama-2-7b-hf")
28+
```
29+
530
## 📖 Documentation
631

732
Full documentation is available at **[https://FujitsuResearch.github.io/OneCompression/](https://FujitsuResearch.github.io/OneCompression/)**.
833

934
## 📦 Features
1035

1136
- **Quantization Error Propagation (QEP)**: A post-training quantization method that corrects quantization errors by propagating them to subsequent layers, improving the accuracy of quantized LLMs. See [Arai & Ichikawa, NeurIPS 2025](https://openreview.net/forum?id=a3l3K9khbL) for details. The original reference implementation is available at [FujitsuResearch/qep](https://github.com/FujitsuResearch/qep).
12-
- **vLLM Plugin Integration**: Serve OneComp-quantized models with [vLLM](https://docs.vllm.ai/) via built-in plugins for DBF and Mixed-GPTQ quantization methods.
37+
- **Layer-Projected Coordinate Descent (LPCD)**: A unified Post Training Quantization (PTQ) framework that extends layer-wise quantization to arbitrary submodules by optimising relaxed objectives and projecting the solutions with layer-wise quantizers. See [Ichikawa et al., 2025](https://arxiv.org/abs/2512.01546) for details.
38+
- **vLLM Plugin Integration**: Serve OneComp-quantized models with [vLLM](https://docs.vllm.ai/) via built-in plugins for DBF and Mixed-GPTQ quantization methods. Pair with [Open WebUI](https://github.com/open-webui/open-webui) for a ChatGPT-like chat experience on your local machine.
1339
- **AutoBit**: Mixed-precision quantization with ILP-based bitwidth assignment. Automatically estimates the target bitwidth from available VRAM and assigns per-layer bitwidths to minimize quantization error under the memory budget.
1440
- **JointQ**: Joint quantization method that optimizes weight assignments and scale parameters simultaneously for improved quantization accuracy. Supports group-wise quantization (e.g., 4-bit, groupsize=128).
41+
- **Block-wise PTQ**: Post-quantization block-wise distillation that minimises intermediate-representation MSE against an FP16 teacher model at Transformer-block granularity. Includes Phase 1 (greedy per-block optimisation) and Phase 2 CBQ (cross-block sliding-window optimisation). Supports GPTQ, DBF, and OneBit quantizers.
1542
- **LoRA SFT Post-Process**: Fine-tune quantized models with LoRA adapters for accuracy recovery or domain-specific knowledge injection. Supports SFT loss, teacher distillation, and intermediate block alignment.
1643
- **Rotation Preprocessing**: SpinQuant/OstQuant-based rotation preprocessing that reduces quantization error by learning optimal rotation matrices before quantization. Rotation/scaling matrices are absorbed into model weights, with online Hadamard hooks automatically registered at load time. Supports Llama and Qwen3 architectures.
1744
- (TBD)
@@ -25,6 +52,8 @@ Other Hugging Face-compatible models may work but are currently untested.
2552
|---|-------------|-----------------|--------|
2653
| 1 | Llama | TinyLlama, Llama-2, Llama-3 | ✅ Verified |
2754
| 2 | Qwen3 | Qwen3-0.6B ~ 32B | ✅ Verified |
55+
| 3 | Gemma | Gemma 2, Gemma 3, Gemma 4 | ✅ Verified |
56+
2857

2958
> **Note:** Support for additional architectures is planned. Contributions and test reports are welcome.
3059
@@ -52,6 +81,7 @@ Choose the appropriate CUDA version for your system:
5281
| CUDA 12.4 | `pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124` |
5382
| CUDA 12.6 | `pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126` |
5483
| CUDA 12.8 | `pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128` |
84+
| CUDA 13.0 | `pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130` |
5585

5686
Check your CUDA version:
5787
```bash
@@ -97,18 +127,21 @@ uv sync --extra cu128 --extra dev --extra visualize
97127
The `uv sync` command creates a Python virtual environment and installs all dependent libraries.
98128

99129
The `--extra cu128` option installs the CUDA-enabled version of PyTorch (along with `torchvision` from the same CUDA index).
100-
Replace `cu128` with the appropriate variant for your environment: `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, or `cu128`.
130+
Replace `cu128` with the appropriate variant for your environment: `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, `cu128`, or `cu130`.
101131
PyTorch will be automatically downloaded by `uv`, so you do not need to install it beforehand.
102132

103133
Adding `--extra dev` installs development tools (black, pytest, pylint).
104134
Adding `--extra visualize` installs matplotlib for visualization features.
135+
Adding `--extra hydra` installs `hydra-core` for the example scripts and `model_validation/` runners that use Hydra-based configuration.
105136

106-
To use vLLM for serving quantized models, add `--extra vllm`:
137+
To use vLLM for serving quantized models, add `--extra vllm` together with `--extra cu130`:
107138

108139
```bash
109-
uv sync --extra cu128 --extra dev --extra visualize --extra vllm
140+
uv sync --extra cu130 --extra dev --extra visualize --extra vllm
110141
```
111142

143+
> **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.
144+
112145
> **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.
113146
114147
#### Running commands (uv environment)
@@ -119,7 +152,7 @@ In the environment created by `uv sync`, you can run commands in two ways:
119152

120153
```bash
121154
uv run pytest tests/ -v
122-
uv run python example/example1.py
155+
uv run python example/example_gptq.py
123156
uv run black --check onecomp/
124157
```
125158

@@ -128,7 +161,7 @@ uv run black --check onecomp/
128161
```bash
129162
source .venv/bin/activate
130163
pytest tests/ -v
131-
python example/example1.py
164+
python example/example_gptq.py
132165
black --check onecomp/
133166
```
134167

@@ -144,7 +177,7 @@ pip install torch --index-url https://download.pytorch.org/whl/cu128
144177
pip install -e ".[dev]"
145178
```
146179

147-
Replace `cu128` with the appropriate variant for your environment: `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, or `cu128`.
180+
Replace `cu128` with the appropriate variant for your environment: `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, `cu128`, or `cu130`.
148181

149182

150183
### Building Documentation Locally
@@ -162,30 +195,34 @@ Then open [http://127.0.0.1:8000](http://127.0.0.1:8000) in your browser.
162195
|----------|--------|-------------|
163196
| Quantization | [example_gptq.py](./example/example_gptq.py) | GPTQ quantization |
164197
| | [example_qep_gptq.py](./example/example_qep_gptq.py) | GPTQ + QEP (error propagation) |
198+
| | [example_lpcd_gptq.py](./example/example_lpcd_gptq.py) | GPTQ + QEP + LPCD quantization |
165199
| | [example_jointq.py](./example/example_jointq.py) | JointQ quantization |
166200
| | [example_autobit.py](./example/example_autobit.py) | AutoBit mixed-precision quantization |
167201
| | [example_auto_run.py](./example/example_auto_run.py) | AutoBit with automatic VRAM estimation |
202+
| Calibration | [example_custom_calibration.py](./example/example_custom_calibration.py) | Custom calibration dataset with CalibrationConfig |
168203
| Save / Load | [example_save_load.py](./example/example_save_load.py) | Save and load quantized models |
169204
| Rotation Preprocessing | [example_llama_preprocess_rtn.py](./example/pre_process/example_llama_preprocess_rtn.py) | Rotation preprocessing + RTN (TinyLlama) |
170205
| | [example_preprocess_save_load.py](./example/pre_process/example_preprocess_save_load.py) | Save and load rotation-preprocessed quantized models |
171-
| Post-Process | [example_lora_sft.py](./example/post_process/example_lora_sft.py) | LoRA SFT post-quantization fine-tuning |
206+
| Post-Process | [example_blockwise_ptq.py](./example/post_process/example_blockwise_ptq.py) | Block-wise PTQ (GPTQ + Phase 1 & CBQ) |
207+
| | [example_lora_sft.py](./example/post_process/example_lora_sft.py) | LoRA SFT post-quantization fine-tuning |
172208
| | [example_lora_sft_knowledge.py](./example/post_process/example_lora_sft_knowledge.py) | LoRA SFT knowledge injection |
173209
| vLLM | [example_gptq_vllm_inference.py](./example/vllm_inference/example_gptq_vllm_inference.py) | GPTQ + QEP quantization and vLLM inference |
174210
| | [example_autobit_vllm_inference.py](./example/vllm_inference/example_autobit_vllm_inference.py) | AutoBit quantization and vLLM inference |
175211

176212
## 🔌 vLLM Inference
177213

178214
OneComp-quantized models can be served with [vLLM](https://docs.vllm.ai/) via built-in plugins (DBF, Mixed-GPTQ).
215+
Combined with [Open WebUI](https://github.com/open-webui/open-webui), you can chat with your quantized model through a ChatGPT-like browser interface — entirely on your local machine.
179216

180217
```bash
181-
# uv users
182-
uv sync --extra cu128 --extra vllm
218+
# uv users (vLLM requires cu130; see Installation for details)
219+
uv sync --extra cu130 --extra vllm
183220

184221
# pip users
185222
pip install vllm
186223
```
187224

188-
See the [vLLM Inference guide](https://FujitsuResearch.github.io/OneCompression/user-guide/vllm-inference/) for details.
225+
See the [vLLM Inference guide](https://FujitsuResearch.github.io/OneCompression/user-guide/vllm-inference/) for details, including Open WebUI setup instructions.
189226

190227

191228
## 📄 License
@@ -220,3 +257,15 @@ year={2025},
220257
url={https://openreview.net/forum?id=a3l3K9khbL}
221258
}
222259
```
260+
261+
LPCD (Layer-Projected Coordinate Descent):
262+
263+
```
264+
@article{ichikawa2025lpcd,
265+
title={LPCD: Unified Framework from Layer-Wise to Submodule Quantization},
266+
author={Yuma Ichikawa and Yudai Fujimoto and Akira Sakai},
267+
journal={arXiv preprint arXiv:2512.01546},
268+
year={2025},
269+
url={https://arxiv.org/abs/2512.01546}
270+
}
271+
```

benchmark/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
count_accepted_lambda.py

0 commit comments

Comments
 (0)