百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

OneCompression

> AI 编程
开源

用于 LLM 压缩的 Python 包

398 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

用于 LLM 压缩的 Python 包

Fujitsu One Compression

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

⚡ Just one line.

bash
onecomp 

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.

bash
# Example
onecomp meta-llama/Llama-2-7b-hf

Or from Python:

python
from onecomp import Runner

Runner.auto_run(model_id="meta-llama/Llama-2-7b-hf")

Documentation

Full documentation is available at https://FujitsuResearch.github.io/OneCompression/.

Features

  • 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 for details. The original reference implementation is available at FujitsuResearch/qep.
  • 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 for details.
  • vLLM Plugin Integration: Serve OneComp-quantized models with vLLM via built-in plugins for DBF and Mixed-GPTQ quantization methods. Pair with Open WebUI for a ChatGPT-like chat experience on your local machine.
  • 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.
  • 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).
  • MDBF (Multi-Envelope Double Binary Factorization): A binary factorization quantizer that approximates each weight matrix as a sum of multi-path sign matrices with multi-scale FP16 envelopes, generalizing DBF and LittleBit for aggressive low-bit (sub-1-bit) compression. Supports ADMM/gradient refinement, activation-aware initialization, and a GemLite-accelerated 1-bit inference path. See the MDBF guide for details.
  • 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.
  • 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.
  • 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.
  • Web Dashboard (HPC): A browser-based dashboard for launching quantization jobs, deploying models, and validating chat-based inference in HPC environments. See dashboard/README.md for details.
  • GGUF Export & Hugging Face Hub Integration: Convert models to the GGUF v3 format (F16) for llama.cpp/Ollama with a dependency-free built-in writer, generate model cards with quantization recipes and evaluation results, and push save directories to the Hugging Face Hub. Supports Llama (SentencePiece or Llama-3-style BPE) and Qwen2 (BPE) architectures, including multi-EOS stop-token mapping. See the GGUF Export guide.
  • (TBD)

Supported Models

OneComp has been verified with the following model architectures. Other Hugging Face-compatible models may work but are currently untested.

# Architecture Verified Models Status
1 Llama TinyLlama, Llama-2, Llama-3 ✅ Verified
2 Qwen3 Qwen3-0.6B ~ 32B ✅ Verified
3 Gemma Gemma 2, Gemma 3, Gemma 4 ✅ Verified
4 GPT-OSS openai/gpt-oss-20b, gpt-oss-120b ✅ Verified
5 Qwen3.6 Qwen3.6-27B, Qwen3.6-35B-A3B ✅ Verified

Note: Support for additional architectures is planned. Contributions and test reports are welcome.

Installation

for users (pip)

1. Install PyTorch

Please install the appropriate version of PyTorch.

✅ CPU-only

bash
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

✅ CUDA-enabled

Choose the appropriate CUDA version for your system:

CUDA Version Installation Command
CUDA 11.8 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
CUDA 12.1 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
CUDA 12.4 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
CUDA 12.6 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
CUDA 12.8 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
CUDA 13.0 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130

Check your CUDA version:

bash
nvcc --version

or

bash
nvidia-smi

Verify PyTorch GPU support:

python
import torch
print(torch.cuda.is_available())

✅ macOS (MPS)

On macOS, install PyTorch from PyPI (default wheels include MPS support). You do not need the CUDA index URLs above.

bash
pip install torch torchvision torchaudio

Verify MPS:

python
import torch
print(torch.backends.mps.is_available())

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) only if you are contributing to OneComp.

MPS device placement (GPTQ vs QEP)
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:

  • 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.
  • 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.

DBF-based AutoBit fallback and multi-GPU quantization are not supported on MPS.

2. Install onecomp

Once PyTorch is installed, you can install onecomp:

bash
pip install onecomp

To enable multi-GPU training features (DeepSpeed), install with the distributed extra:

bash
pip install "onecomp[distributed]"

for developers (uv : recommended)

Install uv

uv is a fast Python package and project manager written in Rust. It offers a drop-in replacement for pip and pip-tools while also managing virtual environments and Python installations. With its Rust-based dependency resolver and the uv.lock lockfile, uv provides deterministic and reproducible environments across development machines and CI pipelines.

bash
# install uv (for macOS or Linux)
curl -LsSf https://astral.sh/uv/install.sh | sh

git clone https://github.com/FujitsuResearch/OneCompression.git
cd OneCompression

The uv sync command creates a Python virtual environment and installs all dependent libraries.

Linux (CUDA quantization / vLLM)

bash
uv sync --extra cu128 --extra dev --extra visualize

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

macOS (development / MPS inference)

bash
uv sync --extra mps --extra dev --extra visualize

On macOS, use --extra mps only. CUDA extras (cu118–cu130), --extra cpu (Linux-only), and --extra vllm are not supported on macOS. After uv sync, you can run GPTQ quantization and Hugging Face generate() inference on MPS; vLLM serving still requires Linux with an NVIDIA GPU. See the MPS device placement (GPTQ vs QEP) note under macOS (MPS) above for why GPTQ runs on CPU while QEP correction uses MPS.

Adding --extra dev installs development tools (black, pre-commit, pytest, pylint). Adding --extra visualize installs matplotlib for visualization features. Adding --extra distributed installs DeepSpeed for multi-GPU training. Adding --extra hydra installs hydra-core for the example scripts and model_validation/ runners that use Hydra-based configuration.

To use vLLM for serving quantized models on Linux, add --extra vllm together with --extra cu130:

bash
uv sync --extra cu130 --extra dev --extra visualize --extra vllm

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.

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.

Running commands (uv environment)

In the environment created by uv sync, you can run commands in two ways:

Option 1: Use uv run (no activation needed)
bash
uv run pytest tests/ -v
uv run python example/example_gptq.py
uv run black --check onecomp/
Option 2: Activate the virtual environment (traditional approach)
bash
source .venv/bin/activate
pytest tests/ -v
python example/example_gptq.py
black --check onecomp/

for developers (pip)

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) flow (pip install torch then pip install onecomp from PyPI); pip install -e is not needed for MPS.

bash
git clone

Issues· 8 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythonllmqepquantizationvllm

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类AI 编程
定价开源

> 相关工具

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.