vllm.model_executor.layers.quantization.online.nvfp4
¶
Classes:
-
Nvfp4OnlineMoEMethod–Online NVFP4 MoE quantization.
-
Nvfp4WeightOnlyOnlineLinearMethod–Online weight-only NVFP4 (W4A16) linear method.
Nvfp4OnlineMoEMethod
¶
Bases: OnlineMoEMethodBase
Online NVFP4 MoE quantization.
Quantizes fp16/bf16 expert weights to NVFP4 at load time. With the default per-token activation key, the FlashInfer TRTLLM kernel computes per-token activation scales at runtime (Blackwell SM100 only). With no activation key, activations stay in the model dtype and the experts run on the platform's W4A16 NVFP4 MoE backend.
Source code in vllm/model_executor/layers/quantization/online/nvfp4.py
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 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
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.
Source code in vllm/model_executor/layers/quantization/online/nvfp4.py
_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.
Source code in vllm/model_executor/layers/quantization/online/nvfp4.py
_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.