vllm.models.deepseek_v4.nvidia.ops.prepare_megamoe
¶
Triton input-staging kernel for DeepSeek V4 MegaMoE.
Quantizes hidden states to fp8 with E8M0 group scales and repacks the routing top-k tensors into the int64/float32 layout that the DeepGEMM MegaMoE kernels consume.
Functions:
-
prepare_megamoe_inputs–Quantize hidden states and repack top-k routing for DeepGEMM MegaMoE.
_resolve_hidden_quant(hidden_quant, block_k)
¶
Map a hidden-state QuantKey to the kernel's (GROUP_K, USE_UE8M0).
Source code in vllm/models/deepseek_v4/nvidia/ops/prepare_megamoe.py
prepare_megamoe_inputs(hidden_states, topk_weights, topk_ids, x_fp8, x_sf, topk_idx_out, topk_weights_out, is_padding=None, shared_x_sf=None, shared_block_m=None, hidden_quant=kMxfp8Dynamic)
¶
Quantize hidden states and repack top-k routing for DeepGEMM MegaMoE.
Parameters:
-
(hidden_states¶Tensor) –Input activations of shape
[num_tokens, hidden_dim]. -
(topk_weights¶Tensor) –Router top-k weights of shape
[num_tokens, top_k]. -
(topk_ids¶Tensor) –Router top-k expert ids of shape
[num_tokens, top_k]. -
(x_fp8¶Tensor) –Output buffer for the fp8-quantized hidden states.
-
(x_sf¶Tensor) –Output buffer for the hidden-state scale factors.
-
(topk_idx_out¶Tensor) –Output buffer for the repacked top-k expert ids.
-
(topk_weights_out¶Tensor) –Output buffer for the repacked top-k weights.
-
(is_padding¶Tensor | None, default:None) –Optional per-token mask; padded tokens are not routed.
-
(shared_x_sf¶Tensor | None, default:None) –Optional output buffer for shared-expert scale factors. Must be given together with
shared_block_m. -
(shared_block_m¶int | None, default:None) –Block M used to lay out
shared_x_sf. -
(hidden_quant¶QuantKey, default:kMxfp8Dynamic) –Hidden-state quantization scheme. E8M0 scales are packed four per int32 into
x_sf; fp32 scales are stored directly.
Source code in vllm/models/deepseek_v4/nvidia/ops/prepare_megamoe.py
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 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 | |