vllm.model_executor.layers.quantization.utils.flashinfer_utils
¶
Functions:
-
align_fp4_moe_weights_for_fi–Pad intermediate size so FlashInfer kernels' alignment constraints hold.
-
align_moe_weights_for_fi–Pad intermediate size so FlashInfer kernels' alignment constraints hold.
-
convert_moe_weights_to_flashinfer_trtllm_block_layout–Convert expert weights to FlashInfer's block layout.
-
prepare_fp8_moe_layer_for_fi–Convert Fp8 MoE weights to flashinfer kernel format.
-
quantize_nvfp4_per_token_input–Quantize NVFP4 activations with one FP32 decode scale per token.
-
rotate_weights_for_fi_trtllm_fp8_per_tensor_moe–Shuffle weights for FI TRT-LLM Format.
_shuffle_deepseek_fp8_moe_weights(w13, w2)
¶
Preprocess DeepSeek FP8 block-scale weights for the FlashInfer TRT-LLM kernel using the shuffle + BlockMajorK layout variant.
Returns 4D weight tensors in BlockMajorK layout (E, K/block_k, Mn, block_k)
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
_shuffle_mxfp8_moe_weights(w13, w2, w13_scale, w2_scale, is_gated)
¶
Preprocess MXFP8 weights and scales for the FlashInfer TRT-LLM kernel.
All three transforms (gate/up row reorder, shuffle_matrix_a weight
shuffle, shuffle_matrix_sf_a scale shuffle) are fixed row/index
permutations that depend only on the per-expert matrix shape, so the
permutation is computed once and applied to every expert in a single
gather instead of once per expert. block_scale_interleave accepts a
batched (E, M, K) scale tensor directly. Output is bit-identical to
the per-expert loop but ~20x faster (a 288-expert MoE otherwise costs
seconds per layer at load).
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
align_fp4_moe_weights_for_fi(w13, w13_scale, w2, w2_scale, is_act_and_mul, min_alignment=16)
¶
Pad intermediate size so FlashInfer kernels' alignment constraints hold.
Some FlashInfer FP4 MoE kernels require the intermediate size used for GEMM to be divisible by a small alignment value. When this is not satisfied (e.g. with certain tensor-parallel sizes), we pad the gate/up and down projection weights along the intermediate dim.
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
align_moe_weights_for_fi(w13, w2, is_act_and_mul, min_alignment=16)
¶
Pad intermediate size so FlashInfer kernels' alignment constraints hold.
Some FlashInfer MoE kernels require the (gated) intermediate size used for GEMM to be divisible by a small alignment value. When this is not satisfied (e.g. with certain tensor-parallel sizes), we pad the gate/up and down projection weights along the intermediate dim.
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
convert_moe_weights_to_flashinfer_trtllm_block_layout(cache_permute_indices, w13_weight, w2_weight, is_gated_act_gemm=True)
¶
Convert expert weights to FlashInfer's block layout.
This reorders W13 and W2 in place into the expected epilogue-tiled block layout and returns views of the shuffled weight tensors. Using one expert as scratch space avoids allocating another full copy of both weights.
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
prepare_fp8_moe_layer_for_fi(layer, w13, w2, w13_scale, w13_input_scale, w2_scale, w2_input_scale, is_trtllm=False)
¶
Convert Fp8 MoE weights to flashinfer kernel format.
Note that for trtllm we update the model state dict with the scale format needed for these kernels.
Note that for per-tensor, we update the layer's intermediate size if the weights needed padding.
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
quantize_nvfp4_per_token_input(hidden_states)
¶
Quantize NVFP4 activations with one FP32 decode scale per token.
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
rotate_weights_for_fi_trtllm_fp8_per_tensor_moe(gemm1_weights, gemm2_weights, is_gated_activation)
¶
Shuffle weights for FI TRT-LLM Format.