vllm.model_executor.layers.quantization.utils.flashinfer_fp4_moe
¶
Utility helpers for NVFP4 + FlashInfer fused-MoE path.
Functions:
-
reorder_w1w3_to_w3w1–Re-order concatenated
[w1, w3]tensors to[w3, w1]in-place.
_shard_nvfp4_moe_weights_per_die(layer, res, w13, w13_scale, w2, w2_scale)
¶
Shard FC1 intermediate rows and FC2 hidden rows across locality domains.
Slice weights and scales along N in [E, N, K] before swizzling each shard.
interleave_linear_and_gate(x, group_size=64, dim=-1)
¶
Interleave gate and linear weight rows for CuteDSL wrapper.
nvfp4_swizzled_scale_to_cutedsl_mma_view(scale)
¶
View a swizzled (E, M_padded, K_sf_padded) block-scale tensor in the MMA layout expected by the CuteDSL MoE kernel.
The returned tensor aliases scale's storage, so in-place updates of the
registered Parameter (weight reloads, EPLB rearrangement) are visible to
the kernel with no extra bookkeeping.
prepare_nvfp4_moe_layer_for_flashinfer_cutedsl(layer, w13, w13_scale, w13_scale_2, a13_scale, w2, w2_scale, w2_scale_2, a2_scale)
¶
Prepare weights for the CuteDSL wrapper-based NvFP4 MoE backend.
Pads the runtime expert tensors to the kernel's GEMM alignment, converts weight scale factors to the MMA layout expected by CuteDslMoEWrapper, and interleaves w13 gate/linear rows for gated activations.
prepare_static_weights_for_trtllm_fp4_moe(gemm1_weights, gemm2_weights, gemm1_scales_linear_fp4_bytes, gemm2_scales_linear_fp4_bytes, hidden_size, intermediate_size, num_experts, is_gated_activation)
¶
Shuffle NVFP4 weights into the FlashInfer TRT-LLM layout.
reorder_w13_to_w31_for_flashinfer_cutedsl(activation, w13, w13_scale)
¶
Normalize gated w13 rows to the [up; gate] order used by FlashInfer.
reorder_w1w3_to_w3w1(weight, scale, dim=-2)
¶
Re-order concatenated [w1, w3] tensors to [w3, w1] in-place.
weight and scale must be contiguous; they remain contiguous on return.