j4flmao/agent-skills/extreme-quantization
Claude Code and agent skill by j4flmao/agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Use this skill when the user says 'quantization', 'int4', 'int8', 'fp8', 'fp4', 'nvfp4', 'mxfp4', 'gptq', 'awq', 'smoothquant', 'w4a16', 'w8a8', 'bitsandbytes', 'nf4'. Selects and applies low-bit weight/activation/KV-cache quantization for LLM inference and training on NVIDIA hardware, and validates accuracy loss. Do NOT use for: generic quantization theory for model formats (ai model-quantization skill), TensorRT engine building (tensorrt-optimization), KV-cache paging (paged-attention), fine-tuning workflows (ml-deep-learning).
Install
npx vskill@latest install j4flmao/agent-skills/extreme-quantizationSKILL.md
Extreme Quantization (sub-16-bit LLMs)
Purpose
Shrink LLM weights, activations and KV cache to 8, 4 or fewer bits so models fit in less memory and run faster. Weight-only quantization speeds up memory-bound decoding; weight+activation quantization speeds up compute-bound prefill and large batches. Every scheme must be validated on task evals, not just perplexity.
Agent Protocol
Trigger
"quantize", "int4", "int8", "fp8", "fp4", "nvfp4", "mxfp4", "gptq", "awq", "smoothquant", "w4a16", "w8a8", "nf4", "bitsandbytes", "kv cache fp8".
Input Context
- Model + size, target GPU generation (Ampere sm_80, Ada sm_89, Hopper sm_90, Blackwell sm_100/sm_120).
- Serving engine (vLLM, SGLang, TensorRT-LLM, llama.cpp) and batch profile (latency vs throughput).
- Accuracy budget and evaluation set.
Output Artifact
Quantization recipe + command/code + evaluation plan. No file unless requested.
Response Format
Completion Criteria
- [ ] Target engine + GPU support the chosen format natively (otherwise it is slower, not faster).
- [ ] Calibration data resembles production prompts.
- [ ] Baseline vs quantized evaluated on the same harness and seeds.
- [ ] Sensitive layers (lm_head, embeddings, sometimes first/last blocks) excluded or kept higher precision.
Formats
| Format | Bits | Notes | |
|---|---|---|---|
| BF16/FP16 | 16 | Baseline. | |
| INT8 | 8 | Per-channel weights, per-token activations. Tensor cores since Turing. | |
| FP8 E4M3 | 8 | 4 exp / 3 mantissa, max 448. Weights + activations (forward). Tensor cores on Ada and Hopper and later. | |
| FP8 E5M2 | 8 | 5 exp / 2 mantissa, max 57344. Wider range; used for gradients in FP8 training. | |
| INT4 (W4A16) | 4 | Weight-only, group-wise scales (group size 128 typical). Dequantized in the GEMM kernel (e.g. Marlin/Machete). | |
| MXFP4 | 4 | OCP microscaling: E2M1 values, one E8M0 (power-of-two) scale per 32 elements. | |
| NVFP4 | 4 | E2M1 values, one FP8 E4M3 scale per 16 elements plus a per-tensor FP32 scale. Native on Blackwell tensor cores. | |
| NF4 | 4 | bitsandbytes NormalFloat for QLoRA; storage format, not a fast inference path. |
Methods
- RTN (round-to-nearest): no calibration. Fine at 8-bit, often poor at 4-bit.
- GPTQ (Frantar et al., 2022): quantizes weights column by column and updates the remaining columns to compensate the error, using second-order information from the layer-input Hessian (H = 2XXᵀ); a Cholesky factorization of H⁻¹ makes it numerically stable and fast. Needs a few hundred calibration samples.
- AWQ (Lin et al., 2023): observes that a small fraction of weight channels (those multiplied by large activations) matter most. Instead of keeping them in FP16 (mixed precision is hardware-unfriendly), it scales those channels up before quantization and folds the inverse scale into the preceding op, so all weights stay uniformly 4-bit.
- SmoothQuant (Xiao et al., 2022): for W8A8, migrates activation outliers into weights with a per-channel scale s_j = max|X_j|^α / max|W_j|^(1-α) (α≈0.5), making both tensors quantizable to INT8.
- FP8 dynamic/static: per-tensor or per-channel scales; nearly lossless for most LLMs and the default first choice on Hopper/Blackwell.
- KV-cache FP8: halves KV memory vs BF16, raising batch size/context; validate on long-context tasks.
Decision Rules
Weight-only 4-bit can be slower than BF16 at large batch sizes because dequantization adds work to a compute-bound GEMM.
Example: GPTQ W4A16 with llm-compressor (vLLM ecosystem)
Example: 4-bit loading for QLoRA (transformers + bitsandbytes)
FP8 Training
NVIDIA Transformer Engine's hybrid recipe uses E4M3 in the forward pass and E5M2 for gradients, with delayed scaling (scale from an amax history). Newer recipes use finer-grained (block/MX) scaling. Keep master weights and optimizer state in higher precision.
Memory Arithmetic
Weights ≈ params x bits / 8. A 70B model: ~140 GB in BF16, ~70 GB in FP8, ~35-40 GB in 4-bit (scales/zeros add overhead). KV cache and activations come on top and often dominate at long context.
Anti-Patterns
- Reporting only perplexity; 4-bit damage shows up first in math, code and long-context tasks.
- Quantizing for a format the GPU lacks tensor-core support for (e.g. FP8 on Ampere falls back to slower weight-only paths or fails).
- Calibrating on generic web text when production is code or another language.
- Relying on unmaintained tooling: AutoGPTQ is archived and AutoAWQ is deprecated; prefer llm-compressor, GPTQModel, or NVIDIA Model Optimizer.
References
- Papers: GPTQ (arXiv:2210.17323), AWQ (arXiv:2306.00978), SmoothQuant (arXiv:2211.10438), FP8 Formats for Deep Learning (arXiv:2209.05433).
- Related:
../tensorrt-optimization/SKILL.md,../paged-attention/SKILL.md.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/hardware-acceleration/extreme-quantization/SKILL.md
Popularity
- Repository stars
- 29
- Repository forks
- 1
- 7-day trend score
- 22
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/j4flmao/agent-skills/extreme-quantization)