vllm.model_executor.layers.quantization.utils.flashinfer_mxint4_moe ¶
Utility helpers for MxInt4 + FlashInfer fused-MoE path
__all__ module-attribute ¶
__all__ = [
"prepare_static_weights_for_trtllm_mxint4_moe",
"flashinfer_trtllm_mxint4_moe",
"is_flashinfer_mxint4_moe_available",
]
flashinfer_trtllm_mxint4_moe ¶
flashinfer_trtllm_mxint4_moe(
x: Tensor,
router_logits: Tensor,
w13_weight_packed: Tensor,
w13_weight_scale: Tensor,
w2_weight_packed: Tensor,
w2_weight_scale: Tensor,
global_num_experts: int,
top_k: int,
intermediate_size_per_partition: int,
local_num_experts: int,
ep_rank: int = 0,
num_expert_group: int | None = None,
topk_group: int | None = None,
e_score_correction_bias: Tensor | None = None,
routing_method_type: int | None = None,
) -> Tensor
Apply FlashInfer TensorRT-LLM MxInt4 MoE kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Tensor | Input hidden states. dtype: bfloat16 | required |
router_logits | Tensor | Router logits for expert selection. dtype: bfloat16/float32 | required |
w13_weight_packed | Tensor | Packed gate+up weights. dtype: uint8 | required |
w13_weight_scale | Tensor | Scales for gate+up weights. dtype: bfloat16 | required |
w2_weight_packed | Tensor | Packed down weights. dtype: uint8 | required |
w2_weight_scale | Tensor | Scales for down weights. dtype: bfloat16 | required |
global_num_experts | int | Total number of experts across all ranks | required |
top_k | int | Number of experts to select per token | required |
intermediate_size_per_partition | int | Intermediate size per partition | required |
local_num_experts | int | Number of experts on this rank | required |
ep_rank | int | Expert parallelism rank (default: 0) | 0 |
num_expert_group | int | None | Number of expert groups (default: None -> 0) | None |
topk_group | int | None | Top-k within groups (default: None -> 0) | None |
e_score_correction_bias | Tensor | None | Optional routing bias. dtype: bfloat16 | None |
routing_method_type | int | None | FlashInfer RoutingMethodType enum value | None |
Returns:
| Type | Description |
|---|---|
Tensor | Output tensor from MoE layer. dtype: same as x (bfloat16) |
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_mxint4_moe.py
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 212 213 214 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 | |
is_flashinfer_mxint4_moe_available cached ¶
is_flashinfer_mxint4_moe_available() -> bool
Return True when FlashInfer MxInt4 kernels can be used.
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_mxint4_moe.py
prepare_static_weights_for_trtllm_mxint4_moe ¶
prepare_static_weights_for_trtllm_mxint4_moe(
gemm1_weights: Tensor,
gemm1_scales: Tensor,
gemm2_weights: Tensor,
gemm2_scales: Tensor,
) -> dict[str, Tensor]
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:
| Type | Description |
|---|---|
dict[str, Tensor] | Dict with keys 'gemm1_weights', 'gemm1_scales', 'gemm2_weights', 'gemm2_scales' containing shuffled/packed tensors ready for kernel |
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_mxint4_moe.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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 | |