LLM Compressor
Turn a Hugging Face model into a compressed-tensors checkpoint (FP8, INT8, W4A16, NVFP4, MXFP4, ...) that vllm serve loads directly, then prove it still works.
Scope: this one library: install, scheme and algorithm choice, calibration, big-model memory tricks, saving, vLLM serving, troubleshooting, updating. Choosing between quantization tools, GGUF/EXL3/MLX, quality gates and publishing belong to model-quantization.
There is no CLI: every run is a short Python script around oneshot() (or model_free_ptq()). Python snippets live in the references; write them to a script file in the user's work dir, never into this skill. Load a reference only when a step names it.
Discover first
Read-only. Never print tokens.
nvidia-smi --query-gpu=name,compute_cap,memory.total --format=csv 2>/dev/null
free -h 2>/dev/null; df -h . ~/.cache/huggingface 2>/dev/null
python3 --version
python3 -m pip show llmcompressor compressed-tensors transformers torch vllm 2>/dev/null | grep -E '^(Name|Version):'
command -v vllm uv conda
test -n "$HF_TOKEN" && echo "HF_TOKEN set" || echo "HF_TOKEN not set"
scripts/inspect-checkpoint.sh <dir-or-hub-id> # is a model already compressed-tensors, and which scheme?
Ask only what cannot be discovered: the base model and revision, the GPU/engine that will serve it, the size or quality target, and whether calibration data from the real workload exists.
Decision flow
- A compressed-tensors checkpoint for this model and scheme already exists and is trusted: use it (
self-hosted-llms), skip quantizing.
- Pick the scheme from the GPU's compute capability (
references/recipes.md, Choosing a scheme): 8.9+ FP8, 10.0+ NVFP4/MXFP4, older GPUs W4A16 (or INT8 W8A8).
- No calibration data needed (FP8_DYNAMIC, FP8_BLOCK, MXFP4 with RTN, weight-only data-free): run
oneshot(model=..., recipe=QuantizationModifier(...)). Needs data (GPTQ, AWQ, SmoothQuant, NVFP4, static activation scales): add dataset=, num_calibration_samples=, max_seq_length= (references/calibration-data.md).
- The model has no transformers definition,
oneshot fails on it, or the scheme is data-free and the model is huge: model_free_ptq() (references/big-models.md).
- The model does not fit in RAM or VRAM: sequential onloading,
auto_offload disk offload, DDP (references/big-models.md).
- The target is TensorRT-LLM, or you want NVIDIA's own recipes: use
nvidia-modelopt instead.
Rules
- Pick the scheme from the GPU, not the other way round. FP8 W8A8 needs compute capability 8.9+, NVFP4 acceleration needs Blackwell (10.0+); on other GPUs vLLM runs these weight-only. Check
references/recipes.md first.
- Keep
lm_head out of quantization, and for MoE models also the router/gate (ignore=["lm_head", "re:.*mlp.gate$"]); multimodal vision towers are not quantized.
- Use a separate venv from vLLM. Upstream says they can have dependency mismatches;
llmcompressor pins torch, transformers and compressed-tensors exactly (references/install.md).
- Calibrate on workload-like data, chat-formatted for chat models, 128 to 512 samples to start; record dataset, split, sample count and sequence length.
- Save with
save_pretrained(dir, save_compressed=True) (or output_dir= in oneshot) and save the tokenizer next to it.
- Test in vLLM, not transformers. A compressed-tensors model run through plain transformers decompresses and gains nothing.
- Cap memory and stop serving first. Calibration loads the full model; on unified-memory machines use a memory-capped scope (
model-quantization, memory-safety).
- Keep the script with the checkpoint and the output of
pip freeze for llmcompressor, compressed-tensors, transformers, torch.
- Secrets never touch output.
HF_TOKEN stays in the environment or a 0600 file.
Workflows
Quantize a model
Fit a huge or MoE model
Debug a failed run
Update
Reference index
references/install.md: pinned dependencies, venv, DGX Spark and containers, import check.
references/recipes.md: scheme names, GPU matrix, algorithms, copy-paste recipes for FP8, INT8, W4A16, AWQ, NVFP4, KV cache, W4AFP8.
references/calibration-data.md: built-in dataset names, custom datasets, sample counts, chat templates.
references/big-models.md: memory math, sequential onloading, disk offload, DDP, model_free_ptq, MoE, REAP.
references/vllm-integration.md: vllm serve flags, kernel selection, KV cache, SGLang status, verifying the load.
references/troubleshooting.md: errors and fixes.
references/updating.md: upgrading llmcompressor, compressed-tensors, vLLM.
scripts/inspect-checkpoint.sh: prints the quantization_config summary of a local dir or Hub repo (bash, curl, jq).
Companion skills
model-quantization: pick a format for an engine, memory caps, quality checks and Hub publishing. Install: npx skills add ScaleDockHQ/llm-skills --skill model-quantization.
vllm: serve the checkpoint and tune the engine. Install: npx skills add ScaleDockHQ/llm-skills --skill vllm.
nvidia-modelopt: NVIDIA's PTQ path for TensorRT-LLM, vLLM and SGLang. Install: npx skills add ScaleDockHQ/llm-skills --skill nvidia-modelopt.
kv-cache-quantization: KV cache dtype choices at serve time. Install: npx skills add ScaleDockHQ/llm-skills --skill kv-cache-quantization.
llm-evals: task evals and quality gates for the quant. Install: npx skills add ScaleDockHQ/llm-skills --skill llm-evals.
sglang: serve compressed-tensors checkpoints on SGLang (partial support). Install: npx skills add ScaleDockHQ/llm-skills --skill sglang.
1---2name: llm-compressor3description: Quantize LLMs for vLLM with LLM Compressor (llmcompressor, vllm-project/llm-compressor). Covers oneshot() recipes for FP8, INT8, W4A16 (GPTQ, AWQ), NVFP4, MXFP4, KV cache, MoE and multimodal models, saved as compressed-tensors checkpoints. Use to quantize a Hugging Face model, pick a scheme for a GPU, choose calibration data, fit a huge model with disk offload or DDP, serve with vllm serve, or fix OOM during calibration, transformers version errors and FP8 not supported on this GPU. Not for GGUF, EXL3, MLX or ModelOpt (see model-quantization, nvidia-modelopt).4license: MIT5compatibility: Linux with an NVIDIA GPU (calibration) and Python 3.10 or newer; pip installs llmcompressor. Serving needs vLLM in a separate venv. Needs curl and jq for the helper script. Installs, long calibration runs and Hub uploads need the user's approval.6metadata:7 source: https://skillmd.com/skills/scaledockhq/llm-compressor8 author: ScaleDockHQ9 version: "0.1.0"10---1112# LLM Compressor1314Turn a Hugging Face model into a compressed-tensors checkpoint (FP8, INT8, W4A16, NVFP4, MXFP4, ...) that `vllm serve` loads directly, then prove it still works.1516**Scope:** this one library: install, scheme and algorithm choice, calibration, big-model memory tricks, saving, vLLM serving, troubleshooting, updating. Choosing between quantization tools, GGUF/EXL3/MLX, quality gates and publishing belong to `model-quantization`.1718There is no CLI: every run is a short Python script around `oneshot()` (or `model_free_ptq()`). Python snippets live in the references; write them to a script file in the user's work dir, never into this skill. Load a reference only when a step names it.1920## Discover first2122Read-only. Never print tokens.2324```bash25nvidia-smi --query-gpu=name,compute_cap,memory.total --format=csv 2>/dev/null26free -h 2>/dev/null; df -h . ~/.cache/huggingface 2>/dev/null27python3 --version28python3 -m pip show llmcompressor compressed-tensors transformers torch vllm 2>/dev/null | grep -E '^(Name|Version):'29command -v vllm uv conda30test -n "$HF_TOKEN" && echo "HF_TOKEN set" || echo "HF_TOKEN not set"31scripts/inspect-checkpoint.sh <dir-or-hub-id> # is a model already compressed-tensors, and which scheme?32```3334Ask only what cannot be discovered: the base model and revision, the GPU/engine that will serve it, the size or quality target, and whether calibration data from the real workload exists.3536## Decision flow37381. A compressed-tensors checkpoint for this model and scheme already exists and is trusted: use it (`self-hosted-llms`), skip quantizing.392. Pick the scheme from the GPU's compute capability (`references/recipes.md`, Choosing a scheme): 8.9+ FP8, 10.0+ NVFP4/MXFP4, older GPUs W4A16 (or INT8 W8A8).403. No calibration data needed (FP8_DYNAMIC, FP8_BLOCK, MXFP4 with RTN, weight-only data-free): run `oneshot(model=..., recipe=QuantizationModifier(...))`. Needs data (GPTQ, AWQ, SmoothQuant, NVFP4, static activation scales): add `dataset=`, `num_calibration_samples=`, `max_seq_length=` (`references/calibration-data.md`).414. The model has no transformers definition, `oneshot` fails on it, or the scheme is data-free and the model is huge: `model_free_ptq()` (`references/big-models.md`).425. The model does not fit in RAM or VRAM: sequential onloading, `auto_offload` disk offload, DDP (`references/big-models.md`).436. The target is TensorRT-LLM, or you want NVIDIA's own recipes: use `nvidia-modelopt` instead.4445## Rules4647- **Pick the scheme from the GPU, not the other way round.** FP8 W8A8 needs compute capability 8.9+, NVFP4 acceleration needs Blackwell (10.0+); on other GPUs vLLM runs these weight-only. Check `references/recipes.md` first.48- **Keep `lm_head` out of quantization,** and for MoE models also the router/gate (`ignore=["lm_head", "re:.*mlp.gate$"]`); multimodal vision towers are not quantized.49- **Use a separate venv from vLLM.** Upstream says they can have dependency mismatches; `llmcompressor` pins `torch`, `transformers` and `compressed-tensors` exactly (`references/install.md`).50- **Calibrate on workload-like data,** chat-formatted for chat models, 128 to 512 samples to start; record dataset, split, sample count and sequence length.51- **Save with `save_pretrained(dir, save_compressed=True)`** (or `output_dir=` in `oneshot`) and save the tokenizer next to it.52- **Test in vLLM, not transformers.** A compressed-tensors model run through plain transformers decompresses and gains nothing.53- **Cap memory and stop serving first.** Calibration loads the full model; on unified-memory machines use a memory-capped scope (`model-quantization`, memory-safety).54- **Keep the script with the checkpoint** and the output of `pip freeze` for `llmcompressor`, `compressed-tensors`, `transformers`, `torch`.55- **Secrets never touch output.** `HF_TOKEN` stays in the environment or a `0600` file.5657## Workflows5859### Quantize a model6061- [ ] Run the discovery block; confirm GPU compute capability and free RAM, VRAM, disk (about 2 bytes per parameter for the BF16 source, plus the output).62- [ ] Create a venv and install (`references/install.md`).63- [ ] Choose scheme and algorithm (`references/recipes.md`).64- [ ] Choose calibration data if the recipe needs it (`references/calibration-data.md`).65- [ ] Write the script, run it inside a memory-capped scope, read the sample generation it prints.66- [ ] Inspect the output with `scripts/inspect-checkpoint.sh` (scheme, ignore list, format).67- [ ] Serve and smoke-test in vLLM (`references/vllm-integration.md`); hand quality gates to `model-quantization` and `llm-evals`.6869### Fit a huge or MoE model7071- [ ] Estimate CPU and GPU memory per algorithm (`references/big-models.md`, Memory).72- [ ] Load with `load_context()` and `device_map="auto_offload"` and a disk `offload_folder`.73- [ ] MoE: keep `moe_calibrate_all_experts=True` (default) and ignore the router (`references/big-models.md`, MoE).74- [ ] Several GPUs: run the same script under `torchrun` with `init_dist()`.7576### Debug a failed run7778- [ ] Match the symptom in `references/troubleshooting.md` (OOM, `transformers` version, saving errors, accuracy drop, vLLM load errors).79- [ ] Compare versions with `pip freeze` and the pins in `references/install.md`.8081### Update8283- [ ] Follow `references/updating.md`: read the release notes, bump in a fresh venv, re-run one small model before a big one.8485## Reference index8687- `references/install.md`: pinned dependencies, venv, DGX Spark and containers, import check.88- `references/recipes.md`: scheme names, GPU matrix, algorithms, copy-paste recipes for FP8, INT8, W4A16, AWQ, NVFP4, KV cache, W4AFP8.89- `references/calibration-data.md`: built-in dataset names, custom datasets, sample counts, chat templates.90- `references/big-models.md`: memory math, sequential onloading, disk offload, DDP, `model_free_ptq`, MoE, REAP.91- `references/vllm-integration.md`: `vllm serve` flags, kernel selection, KV cache, SGLang status, verifying the load.92- `references/troubleshooting.md`: errors and fixes.93- `references/updating.md`: upgrading llmcompressor, compressed-tensors, vLLM.94- `scripts/inspect-checkpoint.sh`: prints the `quantization_config` summary of a local dir or Hub repo (bash, curl, jq).9596## Companion skills9798- `model-quantization`: pick a format for an engine, memory caps, quality checks and Hub publishing. Install: `npx skills add ScaleDockHQ/llm-skills --skill model-quantization`.99- `vllm`: serve the checkpoint and tune the engine. Install: `npx skills add ScaleDockHQ/llm-skills --skill vllm`.100- `nvidia-modelopt`: NVIDIA's PTQ path for TensorRT-LLM, vLLM and SGLang. Install: `npx skills add ScaleDockHQ/llm-skills --skill nvidia-modelopt`.101- `kv-cache-quantization`: KV cache dtype choices at serve time. Install: `npx skills add ScaleDockHQ/llm-skills --skill kv-cache-quantization`.102- `llm-evals`: task evals and quality gates for the quant. Install: `npx skills add ScaleDockHQ/llm-skills --skill llm-evals`.103- `sglang`: serve compressed-tensors checkpoints on SGLang (partial support). Install: `npx skills add ScaleDockHQ/llm-skills --skill sglang`.