The Problem
Deploying large language and vision‑language models at scale demands aggressive compression to reduce memory, latency, and energy without hurting accuracy. Existing tools either lack support for emerging low‑bit formats (FP8, MXFP8, NVFP4) or are limited to a single framework. The Intel Neural Compressor offers a unified, framework‑agnostic solution that covers static/dynamic quantization, weight‑only, QAT, and sparsity for PyTorch, TensorFlow, and JAX.
What This Does
neural_compressor/ hosts the core library – roughly 284 Python files – that implements the compression algorithms. The examples/ directory contains end‑to‑end scripts (flux/main.py, framepack/main.py, sdxl/main.py, stable_diffusion/main.py) that demonstrate how to load a model, configure quantization, and run inference. The benchmark/ folder supplies reproducible micro‑benchmarks and a VLLM‑QDq plugin (benchmark/vllm-qdq-plugin/pyproject.toml).
The main API surface is in neural_compressor/quantization.py, exposing functions such as quantize and quantize_model. Configuration is via YAML/JSON files in docs/source/, e.g., docs/source/PT_MXQuant.md documents MXFP8 usage. The package ships with a setup.py and pyproject.toml, making it installable with pip install ..
How It Is Wired
Entry Point – The quickest path to a quantized inference run is the example scripts. examples/pytorch/diffusion_model/flux/main.py starts with
from neural_compressor import quantization
model = load_model(...)
q_model = quantization.quantize(model, conf_path="config.yaml")
The quantize call enters neural_compressor/quantization.py, which dispatches to the framework‑specific backend (pytorch_backend.py, tensorflow_backend.py, or jax_backend.py). Inside the backend, the quantization strategy (static, dynamic, QAT, etc.) is selected by reading the YAML config; for FP8 or MXFP8 the code path goes through neural_compressor/auto_round.py. The quantized model is then returned to the example script where inference is invoked.
Side Effects – The only external outputs are:
- An optional
quantized.ptorquantized.onnxfile written by the backend. - Logs to
stderr/stdoutcontrolled by theloggingmodule.
No database or network calls are performed by the compressor itself.
Critical Hub – neural_compressor/quantization.py is the largest call center; every quantization request passes through it. Changing its dispatch logic would ripple across all frameworks.
How To Use It
Setup
The repo can be built in a container that already contains the required PyTorch or TensorFlow installation. A ready‑made dev image is defined in
.azure-pipelines/docker/Dockerfile.devel
docker build -t nc-dev -f .azure-pipelines/docker/Dockerfile.devel .
docker run -it nc-dev /bin/bash
Alternatively, install the library locally:
git clone https://github.com/moses-y/neural-compressor
cd neural-compressor
pip install .
Configuration
Quantization parameters are defined in a YAML file. Example fragments are in examples/pytorch/diffusion_model/flux/requirements.txt and docs/source/PT_MXQuant.md. The file must include entries such as:
model:
path: /path/to/model
framework: pytorch
quantization:
algorithm: mxfp8
bits: 8
backend: auto_round
Running
Execute the desired example:
python examples/pytorch/diffusion_model/flux/main.py
The script will load the model, apply the quantization defined in the YAML, and run inference, printing the result.
Real‑World Use
A cloud inference service can integrate the compressor into its build pipeline:
deploy:
pre:
- git clone https://github.com/moses-y/neural-compressor
- pip install .
- python examples/pytorch/diffusion_model/flux/main.py
post:
- copy quantized.pt to /app/models/
The compressed model is then served by a lightweight TorchServe instance, reducing inference latency by ~30 % on a CPU‑only node.
Code Health & Issues
- Coverage – 85 % (reported by GitHub Actions).
- Dependencies –
benchmark/vllm-qdq-plugin/pyproject.tomldeclares requirements without a lockfile, leading to non‑reproducible builds (Low). - Tests – 181 test files; most live in
test/, with 3‑fold coverage across PyTorch, TensorFlow, and JAX. - Documentation – 125 doc files; API docs are auto‑generated from the source.
- CI – GitHub Actions workflows (
pr-io-build.yaml,pr-pre-commit.yml) enforce linting, tests, and build checks.
No other static‑analysis issues were reported.
The Bottom Line
Intel Neural Compressor delivers a mature, framework‑agnostic compression framework that supports the newest low‑bit formats. Its modular design keeps the core logic in a single dispatch module, simplifying debugging. The project is well‑tested and CI‑driven, but users should be aware of the missing lockfile for the VLLM plugin. It is suitable for teams that need to deploy LLMs on diverse Intel hardware while keeping inference fast and memory‑efficient.