vllm.models.minimax_m3.nvidia.specialized_decode.kernels.front
¶
Stage front: the attention front of one sparse layer in one launch.
The device code is CuTe DSL (front_kernel.py, compiled per specialisation
at build). One cluster-of-4 grid does, per decode row:
- boundary: TP all-reduce of the previous sublayer's bf16 partials (Lamport
push exchange), + residual (->
out_residual), Gemma RMSNorm, MXFP8 quantization of the normed row; - QKV + index-Q + index-K MXFP8 GEMV (tcgen05
kind::mxf8f6f4), split-K over the 4 CTAs of a cluster, DSMEM reduce; - epilogue: per-head Gemma RMSNorm + NeoX RoPE, bf16/FP8 Q, FP8 index-Q, FP8 K/V insert into the KV cache, FP8 index-K insert into the indexer cache;
- optionally the step metadata of the layer (one extra cluster).
Exchange modes (prepushed):
False(0): this front pushes its own partialxinto every rank's exchange, then polls. Uses the"front"exchange of the transport.True(2): the producer of the previous sublayer (the fused MoE engine) already pushed into the shared boundary exchange ("g3", see_exchange.py); the front only polls.xmust be None.
Every CTA of the grid spins (the GEMV clusters poll the boundary clusters'
hand-off; the boundary polls peers), so the whole grid must be co-resident:
the constructor checks that against the live device and raises
ResidencyError otherwise.
The per-rank head geometry (nq, nkv, niq) is a compile-time parameter: TP4 is 16 / 1 / 1 (20 head clusters), TP8 8 / 1 / 1 (12 head clusters).
Exchange buffers come from _comm.PeerTransport; cache formats are
checked (FP8 e4m3 only; NVFP4 rejected).
Classes:
-
FinalizeIn–Unfused MoE finalize as the boundary input (prepushed False only):
-
QkvFrontStage–frontfor one layer (one instance per layer; all layers may share -
StepMetaIO–Step metadata the front writes for the indexer of its layer (one extra
FinalizeIn
dataclass
¶
Unfused MoE finalize as the boundary input (prepushed False only): x = sum_k scales[t, k] * fc2[perm[t, k]] (+ x2, the shared expert).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/front.py
QkvFrontStage
¶
front for one layer (one instance per layer; all layers may share
the transport's exchange of their bucket).
Geometry per rank: nq query heads, nkv KV heads, niq index
query heads, one index-K head; the fused weight w is e4m3
[(nq + 2 nkv + niq + 1) * 128, 6144] with 128x4-swizzled UE8M0 scales
wsf (rows: q | k | v | index-q | index-k).
Methods:
-
__call__–One front launch (graph-capturable; no host sync).
-
precompile–Compile every specialisation this stage launches (one per distinct
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/front.py
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 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 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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
__call__(rows, *, residual, norm_w, out_residual, w, wsf, q_w, k_w, iq_w, ik_w, cos_sin, positions, slot_mapping, index_slot_mapping, kv_cache, index_cache, q_fp8, index_q, x=None, x2=None, finalize=None, q_out=None, step_meta=None, single_round=False)
¶
One front launch (graph-capturable; no host sync).
residual bf16 [rows, 6144]; norm_w bf16 [6144] (Gemma: x * (1 + w)); out_residual bf16 [rows, 6144]; cos_sin bf16 [max_pos, rot] ([cos | sin] halves); positions / slot_mapping / index_slot_mapping int64 [rows] (slot -1 skips the insert); kv_cache [blocks, nkv, block_size, 2 * 128] (fp8, k then v); index_cache [slots, 128] (fp8); q_fp8 [rows, nq * 128]; index_q [rows, niq * 128]; q_out bf16 [rows, nq * 128] optional. single_round: residual_mid = bf16(sum of the partials + residual) with one rounding, as the stock deferred-MoE finalize + all-reduce + norm rounds it; otherwise bf16(bf16(sum) + residual), as FlashInfer's fused all-reduce + norm does.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/front.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
precompile()
¶
Compile every specialisation this stage launches (one per distinct
_spec_rows over its rows), outside CUDA-graph capture: the executor
first calls the front inside a FULL graph capture, where compiling is
refused. The kernel arguments are scalars (device addresses, sizes,
strides), so zeros of the same types compile the same code; nothing is
launched. Also runs the cluster co-residency check.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/front.py
StepMetaIO
dataclass
¶
Step metadata the front writes for the indexer of its layer (one extra
cluster). Inputs: query_start_loc int32 [reqs + 1], seq_lens int32
[reqs], block_table int32 [reqs, max_pages]. Outputs: n_valid int32
[rows] (pos // 128 + 1, 0 for an unresolved row), sparse_len int32
[heads, rows] (any strides) or None, pt_rows int32 [rows, pt_maxp] or
None (the first pages of each row's block table).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/front.py
_ext(fmt=_dtypes.CacheFormat.FP8_E4M3, world=4)
¶
The kernel module (CuTe DSL). Only the FP8 e4m3 cache format has device code;
world is a compile-time
parameter of each launch, accepted here for the registry's build phase.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/front.py
_max_active_clusters(fn, grid, smem)
¶
CuOccupancyMaxActiveClusters of the compiled kernel, or None when its CUfunction is not reachable.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/front.py
_spec_rows(rows, maxt)
¶
The rows a launch is specialised for (loop trip counts, MMA N and owner rows constant), 0 = runtime rows.