Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 15 min read Deep dive hardMaster

Tricks from OpenAI gpt-oss YOU 🫵 can use with transformers

Hugging 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.

Assumes: PyTorch basicstransformer architectureMixture of Experts modelsGPU inference concepts

Related posts

  • Welcome GPT OSS, the new open-source model family from OpenAI!

    Hugging Face mediumAdept

    OpenAI's gpt-oss-120b (117B total, 5.1B active) and gpt-oss-20b (21B total, 3.6B active) are Apache 2.0 open-weight mixture-of-experts reasoning models. Their MoE weights are quantized to MXFP4, so the large model fits on one 80GB H100 and the small one runs in 16GB. Architecture notes cover softmax-after-topk routing, alternating full and 128-token sliding-window attention, and learned per-head attention sinks. The guide shows how to run the models via Inference Providers, transformers (MXFP4 kernels, Flash Attention 3 with sinks on Hopper, MegaBlocks MoE kernels as a bf16 fallback), llama.cpp and vLLM, plus fine-tuning with TRL and chat template handling.

  • Transformers now runs llama.cpp quants

    Hugging Face mediumAdept

    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.

  • Native-speed vLLM transformers modeling backend

    Hugging Face hardMaster

    The 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.

  • 180B Parameters, 32GB of RAM: Pushing MoE Inference to the Limit with Transformers

    Hugging Face hardMaster

    Streaming MoE experts from SSD through a bounded device-side slot pool lets Transformers run Qwen3.8-Flash-Next (121 GB of experts) on a 32 GB MacBook M5 at ~13.9 tok/s, within 6% of the specialized Strata engine on decode and slightly faster on prefill. The key idea is a preallocated cache tensor shared across layers with a per-layer expert-id-to-slot table, so the stock grouped_mm kernel runs on cached experts unchanged; 3-bit experts, 8 I/O threads, router-based prefetch, and custom Metal kernels close most of the gap. A comparison with llama.cpp, vLLM and Accelerate offloading shows why existing approaches fail when experts don't fit in RAM, and the remaining gap is attributed to host-GPU round trips that PyTorch's MPS backend can't avoid today.

  • Making LLMs lighter with AutoGPTQ and transformers

    Hugging Face mediumAdept

    AutoGPTQ 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.

The quest for software engineering knowledge.

Look:
Layout: