vllm.models.deepseek_v41.nvidia.quantization
¶
DeepSeek-V4.1 quantization methods on NVIDIA GPUs before SM100.
DeepseekV4FP8Config asks this module, on CUDA only, for the methods of
the MXFP8 linear layers and of the MXFP4 routed experts:
- On A100 (SM80) and H100 (SM90) the MXFP8 linear layers run as BF16 GEMMs on weights dequantized once at load, and decode steps of a few rows on an FP8 GEMV kernel that reads a packed copy of the FP8 weights.
- On A100 and H100 the Marlin MXFP4 experts pad the per-rank intermediate
size to a multiple of 64 instead of 128, and leave their top-k reduction to
the next mHC boundary. vLLM picks the experts' backend: Marlin on A100,
Humming on H100 unless
--moe-backend marlinis given.
Every other GPU gets the stock methods.
Classes:
-
DeferringMarlinExperts–Marlin's experts that can leave the top-k reduction to the next mHC
-
MarlinMxfp4MoEMethod–The MXFP4 routed experts on SM80 and SM90: with the Marlin backend, the
Functions:
-
bf16_mxfp8_linear_method_cls–ModelOptLinearMethodwith the MXFP8 weights dequantized to BF16 at -
mxfp4_moe_method–The method of the MXFP4 routed experts:
MarlinMxfp4MoEMethod -
mxfp8_linear_as_bf16–Whether the MXFP8 linear layers run as BF16 GEMMs: on A100 (SM80) and
-
mxfp8_linear_method_cls–The method of the MXFP8 linear layers (
mxfp8_linear_as_bf16). -
pack_for_gemv–The GEMV kernel's copy of an MXFP8 weight
[N, K]with row-expanded
DeferringMarlinExperts
¶
Bases: MarlinExperts
Marlin's experts that can leave the top-k reduction to the next mHC
boundary's fused all-reduce (AllReduceMHC.finalize), as SM100's
TRT-LLM-Gen experts do: when the layer's config defers a call, GEMM2
writes its rows unweighted, one per route, and the boundary weights and
sums them and adds the shared output inside the all-reduce. The rows are
in route order, so the boundary's row index is the identity: one copy
per device (_identity_index) serves every deferred call (Marlin's
post_gemm2_hook path would build it with a kernel per call).
Methods:
-
process_weights_after_loading–Take the deferred calls' row index, outside any CUDA graph.
Source code in vllm/models/deepseek_v41/nvidia/quantization.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
process_weights_after_loading(layer)
¶
Take the deferred calls' row index, outside any CUDA graph.
Source code in vllm/models/deepseek_v41/nvidia/quantization.py
MarlinMxfp4MoEMethod
¶
Bases: Mxfp4MoEMethod
The MXFP4 routed experts on SM80 and SM90: with the Marlin backend, the per-rank intermediate size is padded to a multiple of 64 instead of 128.
Marlin's MXFP4 path rounds the intermediate size up to 128, but Marlin
needs only 64, its smallest N tile of GEMM1 and K tile of GEMM2 (as
marlin_moe_padded_intermediate states). At TP8 the 2304-wide experts
leave 288 columns per rank: 384 with 128, so a quarter of every expert's
bytes are zeros, and 320 with 64. The padded weights are zero, so the
products are unchanged; only FP32 summation orders change (GEMM2's K
split, and how the GEMMs split their work across SMs).
The backend is vLLM's choice: Marlin on SM80; on SM90, Humming with block
FP8 activations unless --moe-backend marlin is given.
Methods:
-
maybe_roundup_sizes–The stock sizes, except the Marlin intermediate size (class
Source code in vllm/models/deepseek_v41/nvidia/quantization.py
maybe_roundup_sizes(hidden_size, intermediate_size_per_partition, act_dtype, moe_parallel_config)
¶
The stock sizes, except the Marlin intermediate size (class docstring).
Source code in vllm/models/deepseek_v41/nvidia/quantization.py
_identity_index(device, length)
cached
¶
arange(length) as INT32 on device, one copy per process: a
weight reload rebuilds the experts, and the captured CUDA graphs keep
reading this address.
Source code in vllm/models/deepseek_v41/nvidia/quantization.py
bf16_mxfp8_linear_method_cls()
cached
¶
ModelOptLinearMethod with the MXFP8 weights dequantized to BF16 at
load (the emulation kernel) instead of the platform's MXFP8 kernel, and
decode steps of at most GEMV_MAX_ROWS rows on the FP8 GEMV kernel.
Source code in vllm/models/deepseek_v41/nvidia/quantization.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
mxfp4_moe_method(moe)
¶
The method of the MXFP4 routed experts: MarlinMxfp4MoEMethod
on A100 (SM80) and H100 (SM90), the stock method elsewhere, with the
checkpoint's MXFP8 activation.
Source code in vllm/models/deepseek_v41/nvidia/quantization.py
mxfp8_linear_as_bf16()
¶
Whether the MXFP8 linear layers run as BF16 GEMMs: on A100 (SM80) and
H100 (SM90), whose MXFP8 kernels (Marlin, Humming) are slower than cuBLAS
on the weights dequantized once at load at decode sizes. SM80 always does
(its attention reads the BF16 wo_a weight); SM90 only when no MXFP8
linear backend is requested explicitly.
Source code in vllm/models/deepseek_v41/nvidia/quantization.py
mxfp8_linear_method_cls()
¶
The method of the MXFP8 linear layers (mxfp8_linear_as_bf16).
Source code in vllm/models/deepseek_v41/nvidia/quantization.py
pack_for_gemv(weight, scales)
¶
The GEMV kernel's copy of an MXFP8 weight [N, K] with row-expanded
UE8M0 scales [N, K / 32], or None for a weight it cannot take: a
shape that is not whole 32 x 32 blocks, scales that differ within a block's
rows, or a scale above 2^7.