Transformers now runs llama.cpp quants
Hugging Face transformers can now load GGUF (llama.cpp) quantized checkpoints via `from_pretrained(..., gguf_file=...)` and serve them through `transformers serve` with an OpenAI-compatible API. Weights stay packed on Apple Silicon, and ggml's Metal kernels are reused via the `kernels` library for quantized matmul, fused RMSNorm, flash attention, gated delta nets and MoE top-k routing. Two `generate` changes, dropping all-ones padding masks and deferring the stopping check asynchronously, cut CPU-GPU synchronization for all models. Benchmarks on an M2 Max show throughput close to llama-bench for Qwen3.5 dense and MoE checkpoints, though llama.cpp remains the recommended engine for pure local inference. The initial packed path is MPS-only, and padded batching is still slower.
Related posts
- Tricks from OpenAI gpt-oss YOU 🫵 can use with transformers
Hugging Face hardMasterHugging Face upgraded transformers to support OpenAI's gpt-oss models, and most of the new features carry over to other models. These include pre-built kernels downloaded from the Hub (Liger RMSNorm, MegaBlocks MoE, Flash Attention 3 with attention sinks), native MXFP4 4-bit quantization via Triton kernels, tensor and expert parallelism, dynamic sliding window caching, continuous batching with paged attention, and faster loading. MXFP4 stores E2M1 values in 32-element blocks with shared scales. That lets gpt-oss-20B run in about 16 GB of VRAM and 120B in about 80 GB, versus roughly 4× the memory in the bf16 fallback. Benchmarks show the custom and MXFP4 kernels pay off mainly at larger batch sizes.
- Making LLMs lighter with AutoGPTQ and transformers
Hugging Face mediumAdeptAutoGPTQ is now integrated into Hugging Face Transformers (via Optimum), letting users quantize and run LLMs at 8, 4, 3 or 2 bits with the GPTQ post-training method. GPTQ needs a calibration dataset and quantizes only the weights: int4 weights are dequantized on the fly in a fused kernel while compute stays in fp16. That gives nearly 4x memory savings with negligible accuracy loss at 4-bit. On an A100 at batch size 1, Llama-2-7B with the exllama kernel dropped peak memory from about 29 GB to 10.5 GB with slightly better per-token latency than fp16. Text-Generation-Inference can now serve a 70B model on a single 80GB GPU and PEFT adapters can be fine-tuned on top, but the kernels slow down at larger batch sizes and W4A8 or Triton kernels remain open work.
- Overview of natively supported quantization schemes in 🤗 Transformers
Hugging Face mediumAdeptbitsandbytes and GPTQ (via auto-gptq), the two quantization schemes built into Transformers, trade off differently. bitsandbytes needs no calibration data, works on any model with nn.Linear layers across modalities, and lets LoRA adapters merge without degradation. GPTQ supports serialization at any bit width, AMD GPUs and much faster text generation, up to 2x at batch size 4 with KV caching on Llama-2-7B. Benchmarks show bitsandbytes is faster for adapter fine-tuning and both lose little accuracy on Open LLM Leaderboard tasks, especially at 13B. The suggested workflow is to fine-tune adapters on a bitsandbytes base, merge them, then quantize the merged model with GPTQ for deployment.
- Quanto: a PyTorch quantization backend for Optimum
Hugging Face mediumAdeptQuanto is a PyTorch quantization backend for Optimum that works in eager mode on any device (CPU, CUDA, MPS), supports int2/int4/int8/float8 weights and int8/float8 activations, and accelerates int8-int8, fp16-int4, bf16-int8 and bf16-int4 matmuls on CUDA. The workflow runs from dynamic quantization through optional activation calibration and quantization-aware training to freezing integer weights, then serializing with safetensors plus a quantization map for reloading via requantize. It integrates with transformers through QuantoConfig, works across modalities such as Whisper, and is torch.compile-friendly when activations are left unquantized.
- Native-speed vLLM transformers modeling backend
Hugging Face hardMasterThe transformers modeling backend in vLLM now matches or beats vLLM's hand-written native implementations in throughput. Benchmarks covered Qwen3-4B on one GPU, Qwen3-32B with tensor parallelism, and Qwen3-235B FP8 MoE with data and expert parallelism on 8×H100. The backend uses torch.fx static analysis to find known patterns, then rewrites the model source via AST to swap in fused vLLM kernels such as QKVParallelLinear, MergedColumnParallelLinear and expert-parallel MoE ops. It also infers TP/PP plans while staying compatible with torch.compile and CUDA Graphs. Any compliant transformers model gets this with `--model-impl transformers`, except linear-attention models and custom Hub-code models.