vllm.models.minimax_m3.nvidia.specialized_decode.kernels.allreduce_norm
¶
allreduce_norm stage: the post-attention boundary of a sparse layer (TP4).
One launch (CuTe DSL post/kernel.py post_route_kernel) after the o_proj stage:
- lands the four ranks' bf16 o_proj partials the o_proj GEMV pushed into this
rank's boundary exchange (
_exchange.push_workspace(transport, 8, "g3")), sums them in rank order, adds the residual, Gemma RMSNorm; - writes the routed experts' NVFP4 activation with the mode-Q per-token scale (the M3.1 QAT FC1 row quantizer) and, optionally, an MXFP8 copy;
- routes: a dedicated warp polls the o_proj router CTAs' tagged partial logits
(
RouterExchangeSlot), scales them by the row's 1/rms, runs the MiniMax2 top-4 (sigmoid + correction bias, scaled-sum normalize x 2) and publishes tagged route lines the fused MoE engine polls.
The hand-off to the MoE stage is MoeHandoff (exact layout below).
Buffers come from _comm.PeerTransport; every input is an explicit tensor.
Why not upstream finalize_allreduce_norm.FinalizeAllReduceGemmaRMSNormMxfp8:
its arithmetic (rank-order fp32 sum, bf16 residual, Gemma RMSNorm, UE8M0
MXFP8 in the 128x4 layout) is the same contract, but its device protocol is
different and cannot be swapped in without rewriting the producers: upstream's
consumer reads a three-generation multicast mailbox filled by its own publish
kernel (BF16 -0.0 sentinel), while here the producers (the o_proj GEMV and the
fused MoE engine) push unicast into a two-parity exchange whose parity flags the
consumer flips, and the same launch also performs routing and the NVFP4 tail.
What is reused: the test oracle uses the same UE8M0 / 128x4 math, and
_comm.SymmMemPeerTransport (the mechanism upstream uses) can provide the
peer pointers instead of CUDA IPC.
Classes:
-
MoeHandoff–What the post writes and the fused MoE engine reads (one per layer and
-
PostRouteStage–allreduce_norm stage (TP4 or TP8, mode Q). Build once per (layer, rows).
-
RouterExchangeSlot–One layer's router exchange between its o_proj router CTAs (writers,
Functions:
-
unpack_route–(tag, ids, weights fp32) of route words.
MoeHandoff
dataclass
¶
What the post writes and the fused MoE engine reads (one per layer and row count; rows = the engine's maxt, fixed at build).
============= ====================== =========================================
field dtype / shape content
============= ====================== =========================================
normed bf16 [rows, 6144] Gemma-RMSNorm output (shared-expert input)
residual_out bf16 [rows, 6144] bf16(bf16(sum partials) + residual_in)
x4_q uint8 [16, 3072] NVFP4 codes of normed rows, row-major,
low nibble = even column; rows >= rows
untouched
x4_sf_full uint8 [17, 384] rows 0..15: e4m3 block-16 scales,
row-major [row][col / 16]; row 16: fp32
s_t[0..95] (bytes 6144 + 4 t)
x4_sf uint8 [16, 384] view of x4_sf_full[:16]
x4_pts fp32 [96] view of x4_sf_full[16] (s_t per row)
x4_sfsc fp32 [1] 1.0 (unused by mode Q; struct field)
route int64 [16, rows, 16] [replica][row][word]; words 0..3 =
(tag << 32) | (id << 16) | bf16(w) of
the top-4 in rank order; engine CTA bx
polls replica bx % 16 for tag ==
rctr-epoch + 1
rctr int32 [rows, 32] word 0 of row t = tag of the last
publish (post-owned)
mx_q, mx_sf uint8 or None optional MXFP8 normed (codes [rows,
6144], 128x4-swizzled UE8M0); None in M1
============= ====================== =========================================
Mode Q dequant: value = e2m1(code) * e4m3(sf) * s_t (no global scale); FC1 is scaled by s_t per token after the GEMM; FC2 uses the fixed scale 16 folded into the weights (moe stage's weight prep).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/allreduce_norm.py
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 | |
PostRouteStage
¶
allreduce_norm stage (TP4 or TP8, mode Q). Build once per (layer, rows).
Parameters:
-
(transport¶PeerTransport) –the TP group's peer transport (world 4 or 8).
-
(rx¶RouterExchangeSlot) –the layer's
RouterExchangeSlot(shared withOProjRouterStage). -
(post_norm_weight¶Tensor) –bf16 [6144], Gemma weight (
1 + wapplied in-kernel). -
(router_bias¶Tensor) –fp32 [128] e_score_correction_bias.
-
(rows¶int) –decode rows per rank (1..8; the o_proj router path needs a power of 2).
-
(cl¶int, default:DEFAULT_CL) –CTAs per row (4, 8 or 16).
Methods:
-
__call__–Run the post on
residual_mid(bf16 [rows, 6144], final before -
build–Compile, check residency, load the module with an idle launch
-
grid_use–The post's footprint for
_arch.check_co_residentwith the MoE
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/allreduce_norm.py
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 | |
__call__(residual_mid, rows=None)
¶
Run the post on residual_mid (bf16 [rows, 6144], final before
the o_proj launch). Returns the hand-off buffers (owned by the stage).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/allreduce_norm.py
build()
¶
Compile, check residency, load the module with an idle launch (rows = 0). Must run outside graph capture and before the first live call: a live post whose module loads lazily can miss the 2 s rx deadline while peers wait.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/allreduce_norm.py
grid_use()
¶
The post's footprint for _arch.check_co_resident with the MoE
engine it launches early (exact after build).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/allreduce_norm.py
RouterExchangeSlot
¶
One layer's router exchange between its o_proj router CTAs (writers, every rank's) and its post routing warp (reader, this rank).
rx: u64 [2][maxt][world][NPART][E] per rank = (tag << 32) | fp32 bits,
zero = no call (tags start at 1); call tag lives in half tag & 1.
Peer-addressable (each rank's o_proj router CTAs store into every rank's
slot).
Why two halves: rank A's o_proj(k + 1) stores into rank B's slot as soon as A's own post(k) has finished, which needs B's o_proj(k) data but not B's post(k) read, so with one buffer it could overwrite B's unread tag-k words (B's post then never sees its tag and traps at the deadline). It cannot get two calls ahead: A's o_proj(k + 2) waits (grid dependency) for A's post(k + 1), which needs B's o_proj(k + 1) words, stored only after B's post(k) finished (B's own grid dependency).
rxc int32 [maxt][32]: word 0
of row t = tag of the last consumed rx call (post side). oep int32
[NR][32]: word 0 of router CTA r = its call counter (o_proj side). Every
o_proj call must be followed by the post call of the same layer, or the
counters drift and the post traps at its deadline; reset re-aligns.
Methods:
-
reset–Collective (every rank, same point, outside graph capture): zero the
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/allreduce_norm.py
reset()
¶
Collective (every rank, same point, outside graph capture): zero the rx words and both counters.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/allreduce_norm.py
unpack_route(words)
¶
(tag, ids, weights fp32) of route words.