quantization-integrations
Choose and validate Transformers quantization methods, backend integrations, device placement, PEFT/Accelerate/DeepSpeed/FSDP/kernel interactions, and no-download config smoke checks.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- quantization-integrations
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Choose and validate Transformers quantization methods, backend integrations, device placement, PEFT/Accelerate/DeepSpeed/FSDP/kernel interactions, and no-download config smoke checks.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/compatibility.md7.7 KB
- 参考文档references/integration-workflows.md8.5 KB
- 参考文档references/quantization-methods.md7.9 KB
- 参考文档references/troubleshooting.md7.5 KB
- 脚本scripts/quantization_config_smoke.py10.6 KB
03 SKILL.md 正文
Transformers Quantization Integrations
Use this sub-skill when the task is to reduce model memory, load or create quantized checkpoints, choose a quantization backend, combine quantization with PEFT/training/serving, or diagnose backend-specific optional dependency and device placement failures.
Transformers inspected version: 5.13.0.dev0. Import package: transformers. A minimal environment can import base Transformers, but most quantization workflows require torch plus backend packages such as accelerate, bitsandbytes, gptqmodel, autoawq, torchao, peft, deepspeed, or hardware-specific kernels.
Route Here
- Choose between
BitsAndBytesConfig,GPTQConfig,AwqConfig,TorchAoConfig, GGUF/GGML loading, compressed-tensors, Quanto, HQQ, AQLM, EETQ, FP8, Quark, VPTQ, SpQR, SINQ, Metal, or otherquantization_configmethods. - Decide whether a user needs on-the-fly quantization, a pre-quantized checkpoint, or a calibration/quantization job.
- Configure
AutoModelForCausalLM.from_pretrained(..., quantization_config=..., device_map=..., dtype="auto")without downloading models during planning. - Combine quantized models with PEFT/QLoRA, LoRA adapters, Accelerate
device_map, CPU/disk offload, DeepSpeed, FSDP, tensor parallelism, or custom kernels. - Check install and hardware constraints for CPU, CUDA, ROCm, MPS/Metal, Intel XPU, Gaudi/HPU, and
torch.compile. - Diagnose quantized checkpoint mismatch, missing optional packages, unsupported kernels, serialization limits, offload conflicts, or continuous batching incompatibilities.
Route Elsewhere
- Inference task selection,
pipeline(...)kwargs, and pipeline output behavior: inference-pipelines. - Decoding controls,
GenerationConfig, streamers, and generation-only continuous batching concepts: generation. Trainer,TrainingArguments, datasets, collators, and ordinary fine-tuning loops: training.- Tokenizer, processor, chat template, image/audio/video preprocessing, and special-token choices: tokenizers-processors.
transformersCLI commands, HTTP serving, and endpoint routing: serving-cli.- Adding new architectures, configs, model files, or processors: model-extension.
Fast Decision Checklist
- Identify the goal: memory-only loading, faster inference, CPU-only inference, QLoRA/PEFT fine-tuning, pre-quantized checkpoint loading, or creating a new quantized checkpoint.
- Identify hardware: CPU, CUDA GPU generation, ROCm, Apple Silicon/Metal/MPS, Intel XPU, Gaudi/HPU, multi-GPU, or no backend available.
- Prefer easy on-the-fly paths first:
bitsandbytesfor common 4/8-bit GPU workflows,torchaofor PyTorch/compile-oriented paths, HQQ/SINQ/Quanto when their backend matches the host. - Prefer pre-quantized paths when calibration is expensive: AWQ and GPTQ are often loaded as existing 4-bit checkpoints; creating them requires calibration data and time.
- Keep
dtype="auto"anddevice_map="auto"deliberate: they are useful for large models but can conflict with tensor parallelism, offload, or unsupported backends. - Validate config construction locally before downloads with
scripts/quantization_config_smoke.py. - Separate config validation from model execution: constructing a config does not prove kernels, GPU drivers, checkpoint metadata, or memory capacity.
- For quantized training, update only extra parameters unless the backend explicitly supports broader training; QLoRA usually means frozen 4-bit base weights plus PEFT adapters.
Common Starting Points
- Choose a method and backend matrix: quantization methods.
- Combine with Accelerate, PEFT, DeepSpeed, FSDP, tensor parallelism, kernels, or serving: integration workflows.
- Check optional package, hardware, compile, serialization, and device placement constraints: compatibility.
- Diagnose failures and expected signals: troubleshooting.
Canonical Loading Pattern
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype="bfloat16",
)
model = AutoModelForCausalLM.from_pretrained(
"org/model",
quantization_config=quantization_config,
device_map="auto",
dtype="auto",
)
Use this as a shape, not a universal default. Replace BitsAndBytesConfig when the checkpoint already declares another method, when the host is CPU-only and GGUF is the intended format, or when the backend requires calibration, specialized kernels, or a different package.
No-download Config Smoke Check
Run the bundled helper from this sub-skill directory or pass its path explicitly:
python scripts/quantization_config_smoke.py --method bitsandbytes-4bit --print-json
python scripts/quantization_config_smoke.py --method gptq --bits 4 --dataset c4
python scripts/quantization_config_smoke.py --method awq --bits 4 --fuse-max-seq-len 512
Expected success signal: OK quantization config validated plus a summary of the config class and options. Expected optional-dependency signal: MISSING optional dependency with install guidance. Expected validation failure: nonzero exit with ERROR and the invalid option.
Output Expectations For Agent Answers
For quantization tasks, return the selected method, required packages, required hardware/backend, exact quantization_config or loading skeleton, device_map/offload decisions, PEFT/training/serving interaction notes, smoke-check command, expected success signals, and remaining risks such as calibration time, unsupported kernels, serialization limits, or checkpoint metadata mismatch.
Optional Dependency Boundary
A base transformers import is not enough for real quantized model execution. Many config classes can be inspected or constructed without downloading a model, but model loading typically requires torch, accelerate, and the backend package. Missing dependencies commonly raise optional dependency ImportErrors at class import, config validation, or model load time.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).