Skip to content

[None][feat] Muse Spark Open modeling_v2 TEP target: Vera Rubin decode megakernel, 2..4-request TEP4 decode paths and sm107 context-step paths - #21646

Closed
xwang233 wants to merge 15 commits into
NVIDIA:feat/musespark-open-agentxfrom
xwang233:mso-vrmerge2/agentx-tep
Closed

xwang233 wants to merge 15 commits into
NVIDIA:feat/musespark-open-agentxfrom
xwang233:mso-vrmerge2/agentx-tep

Conversation

@xwang233

@xwang233 xwang233 commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR follows #21377. It adds the next round of Vera Rubin (sm107) fast paths to the Muse Spark Open modeling_v2 TEP target and registers each one as a lever in the per-deployment resolver. The changes are 15 commits:

  • 11 inside the Staircase target (_experimental/modeling_v2/models/musespark_open/...__tep): eight groups of paths (context steps, decode steps, 2..4-request decode steps, the lossy MXFP8 QKV opt-in, and four parts of the single-request decode), the whole-layer decode megakernel, the step-commit hooks, and the lever registration;
  • 3 opt-in shared-path changes, off by default (below);
  • 1 setup.py change that ships the target's new JIT CUDA sources.

Aggregated TEP4 servers (sm107), max_batch_size ≥ 4, on under auto.

  • Context and mixed steps:
    • a CuTe DSL multi-instance paged context FMHA (fmk_context_fmha);
    • vectorized context prep rows;
    • replicated embedding and the router input join for context ids;
    • a deeper split-KV page ring;
    • in-place compaction of a windowed drafter arena.
  • Decode steps:
    • a row-gated split of the wide post-attention hop;
    • a BF16x3 router GEMM with a staged epilogue;
    • a late join of the context-K/V side chain;
    • a wider drafter fc inbox gather above 128 rows;
    • a tile-32 pin of the layer 0 and 61 expert calls.
  • Lossy opt-in: decode_qkv_mxfp8 runs the decode QKV projection on the context FP8 copy of the weight. It is never on under auto; it needs MUSESPARK_OPEN_LEVER_DECODE_QKV_MXFP8=on.

TEP4 decode steps of 2–4 requests (bitwise).

  • Scope: generation servers of max_batch_size 2–4 and aggregated servers of 2–8. Off on TEP8, at max_batch_size 1, on context servers and on the high-concurrency selection.
  • The paths:
    • sliding-window blocks per program;
    • the full-attention prep fold on the wide path;
    • the next-QKV L2 prefetch moved after the experts;
    • the DFlash capture stored from the wide boundary.

Single-request TEP8 (aggregated, max_batch_size 1, dense drafter arena).

  • The decode megakernel (kernels/megakernel) runs target layers 1–60 as whole-layer persistent launches, one per layer.
    • It is not bitwise the stock layers. The MoE boundaries and the router inputs use FP32 composites instead of BF16-rounded intermediates, so near-tied top-8 expert choices can differ.
    • These are the gated numerics levers megakernel_one_exchange_boundaries, megakernel_two_term_pool and megakernel_router_by_linearity. Opting out of any of them runs the stock layers.
    • Every other forward runs the stock layers: another device, mapping or row count, context rows, or a step first seen inside a capture.
  • The edges around it:
    • a one-launch pre-layer chain with layer 0's QKV served from a per-token table;
    • the BF16 expert layers 0 and 61 on the routed decode front;
    • the last-layer unpool, residual and final norm in one launch.
  • The distributed head sampler: each rank samples a vocabulary shard, and the ranks exchange sampler states instead of logits.
  • The DFlash drafter:
    • elementwise folds into the split-K GEMV epilogues;
    • the QK norm + RoPE and window attention as programmatic dependents;
    • the preamble's late join;
    • a draft-head tail chain, excluded when the drafter declares a logit transform.
  • Step commits carried in the kernel parameter block, and the overlap scheduler's two offset adds as one launch.
  • head_multimem_gather stays off under auto here; the single-request recipe turns it on with its knob.

MUSESPARK_OPEN_LEVER_<NAME>=auto|on|off is the only switch. The paths' former environment switches are retired and raise at start-up, naming the lever knob. Under MUSESPARK_OPEN_LEVER__DEFAULT=baseline every new lever is off. The sm103 (GB300) compositions serve the same paths as before.

Shared paths: opt-in, off by default. With the variables unset, behaviour is unchanged.

  • MUSESPARK_OPEN_PREFILL_SP_MIN_TOKENS sets the smallest step the built-in prefill sequence parallelism shards. With the split on, each MNNVL all-reduce workspace is reserved before the first capture. Both exist only under MUSESPARK_OPEN_PREFILL_SEQUENCE_PARALLEL=1.
  • RuntimeHooks.overlap_offsets_applier (None by default): a model can run the overlap scheduler's position-id and KV-length corrections of a generation-only speculative step as one launch.
  • TLLM_WORKER_AFFINITY_BEFORE_CUDA_CONTEXT=1 applies the GPU's CPU affinity before torch.cuda.set_device creates the CUDA context, so the driver's host-side memory for it is on the GPU's socket.

Measured gains.

Point Δx / Δy vs #21377
TEP8 c1 +14.9 % / +1.9 %
TEP4 c24, max_batch_size 4 +10.5 % / +4.5 %
TEP4 c32, max_batch_size 4 +11.2 % / +6.4 %
TEP4 c32, max_batch_size 6 +9.8 % / +2.1 %
TEP4 c32, max_batch_size 8 +11.7 % / +2.8 %
TEP4 c40, max_batch_size 8 +12.0 % / +6.2 %
TEP4 c96, high-concurrency recipe +12.5 % / +4.9 %
  • ⚠️ TEP4 c32 at max_batch_size 4 still has TTFT p90 above the 10-second bound, 22 % lower than before.
  • The disaggregated points were not re-measured for this PR.
  • Every run installed its expected lever table.

Accuracy.

  • Setup. Spec decoding on with natural acceptance; long-preamble GSM8K, GPQA-Diamond and a prefix-reuse probe, greedy; pooled paired McNemar.
  • Results.
    • High-concurrency precision set, aggregated TEP4 at max_batch_size 4 and 32, two pairs each against the same recipe without it: passes, p ≥ 0.052, acceptance-length ratio within ±1 %.
    • 2–4-request generation levers on a 1 ‖ 1 TEP4 B2 generation server, against the previous selection: passes, GSM8K p 1.0, AL ratio 0.9997.
    • Single-request TEP8, the megakernel set against MUSESPARK_OPEN_LEVER__DEFAULT=baseline, one pair: McNemar passes on every probe (GSM8K +0.15 pp, p 0.77; reuse −0.08 pp, p 1.0; GPQA −2.5 pp, p 0.062).
  • ⚠️ The single-request acceptance length is higher on GPQA (+3.7 %) and unchanged on GSM8K (−0.2 % / −0.1 %). The shift is spread across questions, with 118 / 198 higher. This is an acceptance gain, not a regression, but GPQA is the weakest probe of this round.

Validation.

Test Coverage

  • tests/unittest/_torch/modeling_v2/models/musespark_open/.../test_modeling_v2_levers.py: the region tables, the new parameters (including the row-range mode), gates, structural exclusions and retired switch names.
  • accuracy/modeling_v2/test_musespark_open.py (on this branch): GSM8K and mean acceptance length under modeling_v2="require".

PR Checklist

  • Please check this after reviewing the above items as appropriate for this PR.

🤖 Generated with Claude Code

… each MNNVL all-reduce workspace before the first capture

MUSESPARK_OPEN_PREFILL_SP_MIN_TOKENS (default 4096, floor 1024) sets the
smallest step the built-in prefill sequence parallelism shards. With the
split on, every MNNVL all-reduce workspace the layers use is sized for a
full replicated step at the first forward that is not captured, keyed by
the reducer's own mapping and dtype, so no CUDA graph keeps the address of
a workspace a later replicated message would grow.

Both exist only under MUSESPARK_OPEN_PREFILL_SEQUENCE_PARALLEL=1. With it
unset the constructor reads no new variable and sets no reservation; the
forward runs as before.

Signed-off-by: Xiao Wang <[email protected]>
RuntimeHooks gains overlap_offsets_applier (None by default). When a model
declares one, the decoder runner may issue the overlap scheduler's
position-id and KV-length corrections of a generation-only speculative step
as one launch. Without it, or when it declines the step, the two original
adds run unchanged.

Signed-off-by: Xiao Wang <[email protected]>
…e its CUDA context

With TLLM_WORKER_AFFINITY_BEFORE_CUDA_CONTEXT=1, BaseWorker applies the
CPU affinity of its GPU before torch.cuda.set_device creates the CUDA
context. The context is then created from a CPU of the GPU's NUMA node,
so the driver's host-side memory for it, such as the words the GPU
writes and polls for event completion, is on the GPU's own socket.

Unset (the default), the affinity is applied after the context is
created, as before.

Signed-off-by: Xiao Wang <[email protected]>
…CUDA sources

Package data for the CUDA sources that the musespark_open TEP target
compiles at run time: the .cu files of its kernel packages dr_draft_tail,
drafter_attn_pdl/_qk_norm_rope_pdl, pf_pre, pv_logits, s2_sampler and
megakernel, and the megakernel's stages/*.cuh headers. The packages are
added by the following commits. The codespell ignore list gains the
kernels' identifiers.

Signed-off-by: Xiao Wang <[email protected]>
…ed context FMHA for mixed steps

A CuTe DSL paged context FMHA for sm107 that runs several attention
instances per CTA over a planned list of work units, and the installer
that serves the context rows of mixed steps with it.

- ops/attention/context_fmha_fmk_kernel.py: the kernel. Double-buffered S,
  diagonal causal mask, Q prefetch, direct O stores and an optional
  diagnostic timestamp build.
- ops/attention/context_fmha_fmk.py: the host planner. It splits each
  context request into units and merges short ones, from fitted per-unit
  costs, and builds the plan tensors.
- kernels/fmk_context_fmha: the installer over the mixed-step context
  library. It reserves its workspace and warms up outside meta init,
  checks for a stream capture before reading the call's parameters, and
  refuses head splits other than the planned one.

The path is installed by the fmk_context_fmha lever (a later commit).

Signed-off-by: Xiao Wang <[email protected]>
… for aggregated TEP4 servers

Paths for context and mixed steps, each installed by its own lever (a
later commit):

- ops/attention/preattn_prep.py: a vectorized context prep rows kernel
  with one 16-byte load and store per norm lane and the reference
  summation order.
- kernels/replicated_embedding: the replicated table also serves
  context-step ids up to a per-architecture row limit.
- kernels/context_sequence_parallel: on sm107 the sequence-parallel
  context step also joins the router input.
- ops/attention/multi_request_split_kv.py: a deeper page ring for the
  E4M3-query split-KV build; the ring depth is part of the compiled-kernel
  key.
- kernels/drafter_window_compact: in-place compaction of the windowed
  drafter arena on mixed steps.
- kernels/context_fp8_dense: refined MXFP8 tactic buckets for the lossy
  context FP8 projections.

Signed-off-by: Xiao Wang <[email protected]>
…gregated TEP4 servers

Decode-step paths, each installed by its own lever (a later commit):

- ops/allreduce/post_attn_hop_wide.py: a row-gated split of the wide
  post-attention hop into fewer CTAs per rank on given row ranges.
- spec_worker.py: a wider drafter fc inbox gather (more rows and
  programs).
- ops/moe/decode_expert_tactics.py, kernels/replicated_experts: a tile-32
  pin of the layer 0 and 61 decode expert calls.
- ops/moe/router_gemm_staged.py, ops/moe/router_gemm.py,
  kernels/router_gemm: a BF16x3 router GEMM whose epilogue stages the
  partial tile in bulk.
- kernels/context_kv_fork: a late join of the context-K/V side chain,
  deferred until its first reader (the readers follow with the drafter
  commit). With no join pending the readers keep their previous launch
  order.

Signed-off-by: Xiao Wang <[email protected]>
… published decode steps (lossy)

On a decode step that projection_publish serves, the QKV projection runs
on the MXFP8 copy of the weight that context_fp8_dense keeps, with the
activation quantized per 1x32 block. This lowers precision, so the
decode_qkv_mxfp8 lever (a later commit) is never on under auto and needs
its knob, MUSESPARK_OPEN_LEVER_DECODE_QKV_MXFP8=on.

- kernels/decode_qkv_mxfp8: the installer.
- ops/comm/projection_publish.py, kernels/projection_publish,
  kernels/batch_dense_gemms: the hooks it uses.
- weights.py: install after the context FP8 copies.

Signed-off-by: Xiao Wang <[email protected]>
…paths for the 2..4-request decode steps of sm107 TEP4

Bitwise paths for decode steps of two to four requests, each installed by
its own lever (a later commit):

- kernels/swa_block, ops/attention/swa_block.py: the sliding-window split
  grid gives each program as many 32-key blocks as the step has
  sequences; one partial per block and the combine are unchanged.
- kernels/full_attention_prep_fold, ops/attention/full_attention_prep_fold.py,
  ops/attention/full_attention_split_kv*.py: the prep fold also takes the
  steps the wide full-attention path folds, in a multi-sequence build of
  the fold kernel on the multi-sequence split-KV partition.
- kernels/next_qkv_prefetch, kernels/boundary_early_release: on the wide
  QKV rows whose kernel stages its weight before its wait, the next QKV
  weight's L2 prefetch is forked after the experts and the unpooler's
  prefetch of it is dropped.
- kernels/capture_fold: a capture layer armed on the wide direct
  transport stores the DFlash capture from its boundary.

Signed-off-by: Xiao Wang <[email protected]>
…el parameter block and a fused overlap-offsets applier

The target's runtime hooks gain two parts of the single-request step
loop. Each writes the same words as the launches it replaces:

- a step commit whose descriptors fit a kernel parameter block carries
  its table there (ops/runtime/step_commit_inline.py) instead of reading
  it from pinned host memory;
- in captured decode graphs the overlap scheduler's two offset adds run
  as one launch that releases its programmatic dependent at entry
  (ops/runtime/overlap_offsets.py, the overlap_offsets_applier hook).

Both are installed by the step_loop_inline_commits lever (a later
commit).

Signed-off-by: Xiao Wang <[email protected]>
…front and last-layer boundary of the single-request decode

The decoder's edges around the middle layers, each installed by its own
lever (a later commit):

- layer0_qkv_table: on a decode step the pre-layer chain is one launch
  (kernels/pf_pre): the replicated token-embedding gather, the embedding
  RMSNorm, the exact FP32 widening of its BF16 output as the residual
  stream, and layer 0's pre-QKV norm. Layer 0's QKV(G) projection
  depends only on the token id, so it is served from a per-token table
  built at load (kernels/tt_table/target_l0.py) and returned by layer 0's
  dense GEMM dispatcher in place of the GEMM.
- edge_bf16_moe_front: the two layers the checkpoint leaves with BF16
  experts (0 and 61) take the routed decode front of the NVFP4 layers;
  the MoE prologue runs their router shard and pool on one chain, and the
  pool and router logits are published into the routed pool kernel's
  transport (kernels/pool_into_route).
- last_layer_boundary: the last layer's unpool gather, post-FFN gated
  residual and the model's final norm run as one launch
  (ops/comm/unpool_final_boundary.py), reproducing the bits of the
  built-in join and RMSNorm it replaces; the glue to the LM head writes
  the head's BF16 input directly (kernels/pv_glue). The routed pool
  kernels gain a BF16 norm variant for the BF16 expert layers. When the
  armed join cannot run, projection_gathers falls back to the built-in
  chain and logs the reason once.
- kernels/ox_entry: the layer-0 input RMSNorm releases its dependent at
  entry.

Signed-off-by: Xiao Wang <[email protected]>
distributed_head_sampler (installed by its lever, a later commit): the
target head's verify sampler runs on an interleaved vocabulary shard on
every rank and the ranks exchange sampler states instead of logits
(kernels/s2_sampler). Logits are gathered in one shot straight into the
final row layout (kernels/pv_logits), and calls neither takes are
gathered with one MULTIMEM all-gather (split_sampler.target_head). The
head sampler's first kernel runs a cooperative fold whose states are the
plain fold's bit for bit, its second kernel releases its dependent right
after its wait, and the verify fold launches as that programmatic
dependent.

Signed-off-by: Xiao Wang <[email protected]>
…eamble late join and draft-head tail

Drafter paths of the single-request decode, each installed by its own
lever (a later commit), computing the same values as the launches they
replace unless noted:

- drafter_folds: elementwise kernels folded into the epilogue of the
  split-K GEMV before them (kernels/dr3_folds,
  ops/gemm/dr3_fold_splitk_gemm.py); the drafter's QK norm + RoPE and
  window attention as programmatic dependents (kernels/drafter_attn_pdl,
  ops/spec/dr3_qk_norm_rope.py); the drafter's layer-0 front served from
  a per-token table built at load (kernels/tt_table/drafter_l0.py).
- draft_head_tail: the draft head's tail after the vocab-sharded LM-head
  GEMV as a short chain of CUDA launches (kernels/dr_draft_tail). It
  does not apply a drafter logit transform, so it is excluded when the
  drafter declares one.
- drafter_preamble_late_join: the verify fold stages the drafter's
  layer-0 input, and the main stream's join of the context-K/V side
  chain moves into the drafter forward, right before layer 0's QK norm
  and RoPE (drafter.py, kernels/drafter_block_decode,
  kernels/verify_fold, ops/spec/dflash_*). The drafter's window attention
  can apply the QK norm and RoPE itself and issues its loads before the
  dependency wait.

With no join pending, the readers of the side chain keep their previous
launch order.

Signed-off-by: Xiao Wang <[email protected]>
…ernel on sm107 TEP8

The megakernel lever runs target layers 1 to 60 (every NVFP4 routed
layer of the 62-layer model) of a decode forward as whole-layer
launches: one persistent launch per sliding-window layer and one per
full-attention layer. Only the forward it is built for takes it: sm107,
TP8 with EP8 over two nodes of four, one sequence with its drafts, no
context rows. Every other forward, and a step whose metadata is first
seen inside a capture, runs the stock layers.

kernels/megakernel holds the CUDA kernel (msoMegakernel.cu and
stages/*.cuh, compiled at install), its per-CTA unit schedules, the
layer plans, and the serving code: install compiles the library, builds
the workspaces and packs each replaced layer's GEMV weights once; begin
binds a forward's parameter blocks; run launches every replaced layer
and returns what the stock layer 60 would.

The served build is not bitwise the stock layers: the MoE boundaries
and the router inputs use FP32 composites instead of BF16-rounded
intermediates (no stored value loses precision), so near-tied top-8
expert choices can differ. These are the gated numerics levers
megakernel_one_exchange_boundaries, megakernel_two_term_pool and
megakernel_router_by_linearity, which the megakernel requires (a later
commit). The install refuses, with the reason logged, on another device
or mapping, or without pinned host memory for the kernel's watchdog
record.

Signed-off-by: Xiao Wang <[email protected]>
…d sm107 TEP4, 2..4-request and single-request TEP8 paths

Registers the paths of the previous commits as levers in the resolver
(levers.RULES, dispatch.FAST_PATHS) and composes them in modeling.py,
layers.py and the decode target. MUSESPARK_OPEN_LEVER_<NAME>
(auto|on|off) is the only switch; the paths' former environment
switches are retired and raise at start-up, naming the lever knob.
Under MUSESPARK_OPEN_LEVER__DEFAULT=baseline every new lever is off.

Aggregated sm107 TEP4 servers of max_batch_size 4 or more, on under auto:
- bitwise: context_kv_late_join, hop_cluster_split (CLUSTER, ROWS),
  router_staged_epilogue, step_window_compact (windowed arena only),
  split_kv_deep_ring, context_prep_rows_vec, context_embedding_replicated,
  context_sp_router_input; drafter_fc_inbox_wide (MAX_ROWS, PROGRAMS) also
  needs a decode step of more than 128 rows;
- lossless-numeric, with an accuracy gate on the same servers:
  fmk_context_fmha, l061_tile32_pin;
- lossy, on only by its knob: decode_qkv_mxfp8, excluded when
  context_fp8_dense__PROJECTIONS leaves out qkv.

sm107 TEP4 decode steps of two to four requests (bitwise): on for
generation servers of max_batch_size 2..4 and aggregated servers of
max_batch_size 2..8, off on TEP8, at max_batch_size 1, on context
servers, for an unknown role and on the high-concurrency selection:
swa_blocks_per_program, wide_full_attention_fold, wide_qkv_prefetch,
wide_capture_fold.

Aggregated sm107 TEP8 servers of max_batch_size 1 over a dense drafter
arena (dispatch.SM107_TEP8_ONLY), on under auto there and off everywhere
else: megakernel with its numerics levers
megakernel_one_exchange_boundaries, megakernel_two_term_pool and
megakernel_router_by_linearity (gated, switchable; opting out of one
runs the stock layers); megakernel_zero_exchange_boundary, declared and
structurally excluded; layer0_qkv_table, edge_bf16_moe_front,
last_layer_boundary, context_kv_fork_last_layer,
distributed_head_sampler, drafter_preamble_late_join, drafter_folds,
draft_head_tail (excluded when the drafter declares a logit transform)
and step_loop_inline_commits.

Param gains a ranges mode for comma-separated lo-hi row ranges. The
sm103 compositions serve the same paths as before. The host tests pin
the region tables, the new parameters, gates and retired names.

Signed-off-by: Xiao Wang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant