vllm.model_executor.kernels.mhc.flashinfer_mega
¶
MHCFusedPostPreOp on FlashInfer's fused mHC kernel (flashinfer.mega_mhc).
One persistent kernel computes a sublayer's mHC post block, the next
sublayer's pre block and its RMSNorm: the work the TileLang path does in two
launches for up to 32 tokens, and in post + projection GEMM + pre beyond that.
FlashInfer ships it as the experimental prepare_mega_mhc API; its
sf_layout="bf16" programs serve hidden size 4096 with four residual
streams in normal (non-delayed) mode. The model decides which steps use it.
A FlashInfer plan binds the tensors it is prepared with, so a plan is prepared
for each call. The kernel reads the FP32 projection through its three BF16
pieces (fn_split), which the model owns and refreshes when its weights
change. The cross-CTA counters and the scratch live in vLLM's workspace
manager. FlashInfer JIT-builds the program a token count selects; the JIT
warmup (MegaMHCKernel) builds every program before serving.
Functions:
-
mega_mhc_supported–Whether FlashInfer has a fused mHC program for this shape and device.
-
mhc_fused_post_pre_flashinfer_mega–MHCFusedPostPreOp (with its RMSNorm) as one FlashInfer launch.
-
split_mhc_fn–The three BF16 pieces of the FP32 projection
fnthe kernel reads.
MegaMHCKernel
¶
Bases: VllmJitKernel['MegaMHCKernel.CompileKey']
Builds every FlashInfer mega mHC program the op can select.
FlashInfer picks the program from the token count, and builds it on first use. Startup reaches only the profile run and the CUDA graph sizes, so a program for a size between them would be built mid-serving.
_counters(device, num_sms)
¶
Zeroed (split barriers, launch epochs) per launch grid, or None.
Every CTA advances its own epoch slot, so only launches of one grid may share a pair. All pairs are made on the first call of each ubatch, before CUDA graph capture locks the workspace.
_flashinfer_mega_mhc()
cached
¶
(prepare_mega_mhc, host rules module), or None if FlashInfer lacks them.
_launch_grid(num_tokens, num_sms)
cached
¶
(split count, grid) FlashInfer's plan uses for num_tokens.
mega_mhc_supported(hidden_size, hc_mult)
¶
Whether FlashInfer has a fused mHC program for this shape and device.
mhc_fused_post_pre_flashinfer_mega(x, residual, post_layer_mix, comb_res_mix, fn, fn_split, hc_scale, hc_base, rms_eps, hc_pre_eps, hc_sinkhorn_eps, hc_post_mult_value, sinkhorn_repeat, norm_weight, norm_eps)
¶
MHCFusedPostPreOp (with its RMSNorm) as one FlashInfer launch.
Same contract as mhc_fused_post_pre_tilelang, plus fn_split, the
BF16 pieces of fn (split_mhc_fn).
split_mhc_fn(fn, out=None)
¶
The three BF16 pieces of the FP32 projection fn the kernel reads.
Writes into out when given, so captured CUDA graphs see the new values.