Skip to content

vllm.model_executor.layers.quantization.online.nvfp4

Classes:

Nvfp4OnlineMoEMethod

Bases: OnlineMoEMethodBase

Online NVFP4 MoE quantization with per-token activation scales.

Quantizes fp16/bf16 expert weights to NVFP4 at load time; the FlashInfer TRTLLM kernel computes per-token activation scales at runtime. Blackwell (SM100) only.

Nvfp4WeightOnlyOnlineLinearMethod

Bases: OnlineLinearBase

Online weight-only NVFP4 (W4A16) linear method.

Quantizes fp16/bf16 weights to NVFP4 during loading, with one global scale per weight shared across TP ranks, and runs them on the platform's W4A16 kernel. Activations stay in the model dtype.

_quantize_moe_weight_to_nvfp4(weight, moe_tp_size=1)

Quantize stacked MoE expert weights (E, N, K) to NVFP4.

One FP32 global scale per expert plus per-block (group-16) FP8 scales, matching the ModelOpt NVFP4 checkpoint layout. Returns packed FP4 weights (E, N, K // 2), block scales (E, N, K // 16), and the per-expert global scale (E,) stored as amax / (fp4_max * fp8_max).

weight may be staged on the CPU: experts then move to the accelerator one at a time, where all outputs are returned.

_quantize_nvfp4(weight, amax, chunk_rows=8192)

NVFP4-quantize the rows of weight, with the native quant kernel where the GPU has one and a PyTorch reference elsewhere (the W4A16 kernels also run on GPUs without it).

amax sets the global scale. Returns packed E2M1 codes (low nibble first), E4M3 scales per 16 values and the fp32 dequantization global scale, in the checkpoint layout.