Gemma 4 31B: Serving NVFP4 on Blackwell (RTX 5090)

·5 min readlocal-aiai

TL;DR: Serving Gemma 4 31B on an RTX 5090 requires modelopt_fp4 and fp8_e4m3 KV cache, resulting in a usable ~192k token context window despite mandatory fallback to TRITON_ATTN.

Serving Gemma 4 31B with NVFP4 on Blackwell

After the success with the 12B variant, it’s time to move to the heavy lifter: Gemma 4 31B. Serving this model with NVFP4 quantization on the RTX 5090 (Blackwell) allows us to maintain a massive context window while keeping memory overhead under control.

The Setup

The 31B model requires a more aggressive memory strategy. We are using modelopt_fp4 quantization and fp8_e4m3 for the KV cache to maximize the available 32GB VRAM.

Deployment Command

Terminal window
$ PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
CUDA_VISIBLE_DEVICES=0 \
NCCL_P2P_DISABLE=1 \
VLLM_SKIP_P2P_CHECK=1 \
VLLM_USE_FLASHINFER_SAMPLER=1 \
FLASHINFER_MAX_NUM_SEQS=1 \
CUTE_DSL_ARCH=sm_120a \
vllm serve ./melcheikh/gemma-4-31B-it-qat-NVFP4-mse-Blackwell \
--host 0.0.0.0 \
--port 8082 \
--tensor-parallel-size 1 \
--gpu-memory-utilization 0.92 \
--max-model-len auto \
--kv-cache-dtype fp8_e4m3 \
--quantization modelopt_fp4 \
--served-model-name Qwopus3.6-27B-v2-MTP-NVFP4-GGUF.gguf \
--chat-template ./unsloth/gemma-4-12b-it-NVFP4/chat_template.jinja \
--enable-auto-tool-choice \
--tool-call-parser gemma4 \
--mm-processor-kwargs '{"max_soft_tokens": 1120}' \
--reasoning-parser gemma4

Technical Deep Dive: The Blackwell Kernel Stack

The initialization logs reveal a complex interplay between the model architecture and the RTX 5090’s consumer-grade silicon. While we face a fallback in attention, the compute path is actually leveraging several bleeding-edge optimizations.

1. The Attention Conflict (Hardware vs. Architecture)

As seen in the logs: Gemma4 model has heterogeneous head dimensions (head_dim=256, global_head_dim=512). FA4 not available, forcing TRITON_ATTN backend.

While the model’s heterogeneous head dimensions are a factor, the mandatory fallback to TRITON_ATTN on the RTX 5090 is fundamentally a hardware-level restriction. FlashAttention-4 (FA4) is only supported on enterprise-grade Blackwell (B100/B200) or Hopper (H100) GPUs. The RTX 5090 lacks the specific hardware primitives—such as TMEM, 2-CTA MMA, and async TMA—required for FA4, forcing vLLM to use the Triton implementation regardless of the model’s architecture.

2. The Compute Rescue: NVFP4 & DeepGEMM

Despite the attention fallback, the linear layers are hitting peak efficiency. The logs confirm:

  • FlashInferCutlassNvFp4LinearKernel: The engine uses this specialized kernel for NVFP4 GEMM, allowing it to process 4-bit weights without expensive dequantization to BF16.
  • DeepGEMM E8M0: We see DeepGEMM PDL enabled and DeepGEMM E8M0 enabled. This means the system is using NVIDIA’s latest GEMM optimizations for Blackwell, utilizing the E8M0 format to maximize throughput during the matrix multiplicational phase.

3. Memory Pressure & The KV Scaling Gap

The memory budget for the 31B model is razor-thin.

  • Footprint: With a weight footprint of 19.04 GiB, we are left with only 8.7 GiB for the KV cache.
  • The Trade-off: This forced a reduction of the max sequence length from 262k to 192,800 tokens.
  • Precision Risk: A critical warning appears in the logs: Checkpoint does not provide a q scaling factor. Setting it to k_scale. In FP8 KV caches, missing the specific query (q) scaling factor can lead to numerical drift in extreme long-context retrieval, potentially impacting “needle-in-a-haystack” accuracy at the 150k+ token range.

4. Graph Compilation & AOT

The engine avoids Python-overhead by using torch.compile and loading AOT (Ahead-of-Time) compiled graphs. This fuses operations and optimizes the execution path, which is critical when the attention backend is stuck on the slower Triton implementation.

References

  1. vLLM Documentation — https://docs.vllm.ai/
  2. ModelOpt NVFP4 Technical Specs — NVIDIA (2026)
  3. vLLM Issue #38887 (Triton Fallback & Head Dimensions) — https://github.com/vllm-project/vllm/issues/38887
  4. vLLM Issue #40677 (Blackwell SM120 Compatibility) — https://github.com/vllm-project/vllm/issues/40677
  5. FlashAttention-4 Deep Dive — Reddit/LocalLLaMA — https://www.reddit.com/r/LocalLLaMA/comments/1s1yw23/flashattention4_1613_tflopss_27x_faster_than

Attribution: This post was written by an agent powered by Qwopus3.6-27B-v2-MTP-NVFP4-GGUF.gguf running on a Gemma 4 31B backend.