vllm.model_executor.layers.quantization.utils.flashinfer_mxint4_moe
¶
Utility helpers for MxInt4 + FlashInfer fused-MoE path.
Functions:
-
flashinfer_trtllm_mxint4_moe–Apply FlashInfer TensorRT-LLM MxInt4 MoE kernel.
-
is_flashinfer_mxint4_moe_available–Return
Truewhen FlashInfer MxInt4 kernels can be used. -
prepare_static_weights_for_trtllm_mxint4_moe–Prepare MxInt4 weights for TRT-LLM kernel.
flashinfer_trtllm_mxint4_moe(x, router_logits, w13_weight_packed, w13_weight_scale, w2_weight_packed, w2_weight_scale, global_num_experts, top_k, intermediate_size_per_partition, local_num_experts, ep_rank=0, num_expert_group=None, topk_group=None, e_score_correction_bias=None, routing_method_type=None, routing_replay_out=None)
¶
Apply FlashInfer TensorRT-LLM MxInt4 MoE kernel.
Parameters:
-
(x¶Tensor) –Input hidden states. dtype: bfloat16
-
(router_logits¶Tensor) –Router logits for expert selection. dtype: bfloat16/float32
-
(w13_weight_packed¶Tensor) –Packed gate+up weights. dtype: uint8
-
(w13_weight_scale¶Tensor) –Scales for gate+up weights. dtype: bfloat16
-
(w2_weight_packed¶Tensor) –Packed down weights. dtype: uint8
-
(w2_weight_scale¶Tensor) –Scales for down weights. dtype: bfloat16
-
(global_num_experts¶int) –Total number of experts across all ranks
-
(top_k¶int) –Number of experts to select per token
-
(intermediate_size_per_partition¶int) –Intermediate size per partition
-
(local_num_experts¶int) –Number of experts on this rank
-
(ep_rank¶int, default:0) –Expert parallelism rank (default: 0)
-
(num_expert_group¶int | None, default:None) –Number of expert groups (default: None -> 0)
-
(topk_group¶int | None, default:None) –Top-k within groups (default: None -> 0)
-
(routing_replay_out¶Tensor | None, default:None) –Optional buffer receiving the routing decisions so they can be replayed later
-
(e_score_correction_bias¶Tensor | None, default:None) –Optional routing bias. dtype: bfloat16
-
(routing_method_type¶int | None, default:None) –FlashInfer RoutingMethodType enum value
Returns:
-
Tensor–Output tensor from MoE layer. dtype: same as x (bfloat16)
is_flashinfer_mxint4_moe_available()
cached
¶
Return True when FlashInfer MxInt4 kernels can be used.
prepare_static_weights_for_trtllm_mxint4_moe(gemm1_weights, gemm1_scales, gemm2_weights, gemm2_scales)
¶
Prepare MxInt4 weights for TRT-LLM kernel.
Input
gemm1_weights: [num_experts, 2intermediate_size, hidden_size//8] int32 (checkpoint uint4b8 packed) or uint8 (already packed signed int4) gemm1_scales: [num_experts, 2intermediate_size, hidden_size//32] bf16 gemm2_weights: [num_experts, hidden_size, intermediate_size//8] int32 (checkpoint uint4b8 packed) or uint8 (already packed signed int4) gemm2_scales: [num_experts, hidden_size, intermediate_size//32] bf16
Returns: