Transformers Integrations
Use this sub-skill when the task is about loading or preparing models through Hugging Face ecosystem APIs with bitsandbytes quantization. The key API is usually transformers.BitsAndBytesConfig; it is provided by Transformers, not by the bitsandbytes Python package.
Route Here
- Build
BitsAndBytesConfigforload_in_8bit,load_in_4bit, NF4, double quantization, compute dtype, or quantized storage dtype. - Load a model with
AutoModelForCausalLM.from_pretrained(..., quantization_config=..., device_map=...). - Prepare QLoRA with PEFT using
prepare_model_for_kbit_training,LoraConfig, andget_peft_model. - Plan FSDP-QLoRA, especially
bnb_4bit_quant_storageand dtype alignment. - Explain Diffusers, Accelerate, or Transformers integration decisions without direct layer replacement.
- Validate a quantization config in CI without downloading model weights.
Route Elsewhere
- For install, import, missing native library, backend visibility,
python -m bitsandbytes, or CUDA/XPU/HPU/MPS/CPU diagnostics, useinstallation-diagnostics. - For direct
bitsandbytes.nn.Linear8bitLt,Linear4bit,Params4bit,QuantState, or low-level functional APIs, usequantized-modules-functions. - For standalone 8-bit or paged optimizer training loops,
Trainer(optim=...), orbitsandbytes.optim, useoptimizers-training.
Start Points
- Read
references/integration-workflows.mdfor 8-bit inference, 4-bit/NF4 loading, QLoRA, Diffusers/Accelerate notes, validation, and model-download safety. - Read
references/fsdp-qlora.mdfor FSDP-QLoRA dtype, storage, sharding, and state-dict caveats. - Read
references/troubleshooting.mdwhen integrations fail at import, model loading, device mapping, dtype, offload, or distributed save time. - Run
scripts/transformers-bnb-config-check.py --mode qlorato validate optional dependency imports and print no-download config snippets.
Working Rules
- Separate config construction from execution:
BitsAndBytesConfigcan often be constructed on CPU-only CI, but actual quantized model loading may require a compatible accelerator, memory plan, model access, and network/cache availability. - Prefer
quantization_config=BitsAndBytesConfig(...)over legacy directload_in_8bit=Trueorload_in_4bit=Truearguments tofrom_pretrained. - Treat model IDs, tokens, gated repositories, and remote code as deployment inputs; never assume downloads are allowed.
- Keep backend failures routed to installation diagnostics before changing model-loading code.
