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.
Source code in vllm/model_executor/kernels/mhc/flashinfer_mega.py
_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.
Source code in vllm/model_executor/kernels/mhc/flashinfer_mega.py
_flashinfer_mega_mhc()
cached
¶
(prepare_mega_mhc, host rules module), or None if FlashInfer lacks them.
Source code in vllm/model_executor/kernels/mhc/flashinfer_mega.py
_launch_grid(num_tokens, num_sms)
cached
¶
(split count, grid) FlashInfer's plan uses for num_tokens.
Source code in vllm/model_executor/kernels/mhc/flashinfer_mega.py
mega_mhc_supported(hidden_size, hc_mult)
¶
Whether FlashInfer has a fused mHC program for this shape and device.
Source code in vllm/model_executor/kernels/mhc/flashinfer_mega.py
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).
Source code in vllm/model_executor/kernels/mhc/flashinfer_mega.py
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 175 176 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 | |
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.