Skip to content

spark-model: split a lone sequence's qwen4_exp draft head across the pair (C1 +4% on 2x DGX Spark, exact) - #375

Open
maplepaladin73 wants to merge 4 commits into
Atlas-Inf:mainfrom
maplepaladin73:perf/qwen4exp-single-seq-draft-tp
Open

maplepaladin73 wants to merge 4 commits into
Atlas-Inf:mainfrom
maplepaladin73:perf/qwen4exp-single-seq-draft-tp

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On the TP2 pair, ATLAS_QWEN4EXP_MTP_DRAFT_TP splits the qwen4_exp draft head across the two ranks, but only for a batched propose. A lone sequence drafts on the per-sequence propose, so the worker idles through every draft step at C=1.

This adds ATLAS_QWEN4EXP_MTP_DRAFT_TP_ONE=1 (default off; needs ATLAS_QWEN4EXP_MTP_DRAFT_TP=1). With it the model announces a lone sequence's propose as a one-row plan, and each draft position runs the existing TpRun::head at one row. No new protocol: the worker walks the same Plan::swaps it already walks, with n = 1.

What motivated it (nsys, both ranks, C=1, 1024 tokens, upstream a92bd068): rank 1 idle 24% of the request, in one ~8.4 ms gap per 49.5 ms verify step; rank 0 spends 87% of that gap in the drafter, the draft head w4a16_gemv being 611 us of each ~1.5 ms position.

Why output cannot change

  • The one-row scalar tier writes the per-sequence head's bytes: qwen4exp_mtp_tp_gpu_one_row_shards_assemble_to_the_per_sequence_head compares the assembled shards against DraftHead::project for the BF16 rows and the NVFP4 copy.
  • Drafts only decide what is proposed; every token is still verified by the target.
  • A grammar-masked propose reads the full head, is never announced and never swaps.
  • The switch rides bit 3 of the draft-TP parity word, so both ranks must agree at startup.

Test plan

  • cargo fmt --all -- --check
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy -p spark-model --tests (clean; the full --workspace run was not done)
  • bash scripts/check-license-headers.sh — not run (no docker on the dev host); both new files carry the SPDX line
  • typos — not run (not installed on the dev hosts)
  • cargo test --release -p spark-model --lib qwen4exp_mtp — 29 passed, including the three new lockstep tests in qwen4exp_mtp_tp_one_tests.rs
  • GB10: cargo test --release -p spark-model --lib qwen4exp_mtp_tp_gpu -- --ignored — 3 passed
  • Real model on hardware, below

Measurement (preliminary, single harness)

Fingerprint: 2x DGX Spark (GB10), TP=2/EP=2, nvidia/Qwen3.8-Flash-Next-FP4-Local, this branch on a92bd068, --speculative --num-drafts=7 --max-num-seqs=8 --kv-cache-dtype=bf16 --enable-prefix-caching --max-prefill-tokens=16384, the deployment's lever profile plus ATLAS_PLE_FAULT_THREADS=256. Harness: 8 distinct code/prose prompts, temperature 0, thinking off, max_tokens 1024, one warm-up pass, 3 runs, client-side aggregate tok/s. One variable between the two legs: the new switch.

Leg C=1 tok/s C=8 aggregate tok/s
switch off 94.4 / 95.3 / 95.6 205.3 / 206.0 / 204.6
switch on 98.6 / 99.5 / 99.1 205.7 / 205.9 / 206.0
  • Tokens per verify step at C=1: 4.92 in both legs.
  • Output text identical to upstream a92bd068 on all 27 decode requests and on 4 long prompts (3.6K–25K tokens), in both legs.
  • Also exercised with the switch on: widths 1, 2, 3, 4, 8 back to back; three staggered arrivals, whose outputs matched each prompt run alone; one json_schema request. No ERROR lines on either rank.

Not measured: a single node, other qwen4_exp checkpoints, ATLAS_QWEN4EXP_DRAFT_VOCAB id lists (refused by the existing batchable check), and anything beyond this one harness.

Second commit: MoE bench fixes (dev script only)

  • scripts/dev/qwen4exp_moe_c8_bench.sh time segfaulted: qwen4exp_moe_c8_tc3_plan takes six arguments (has_shared) and the bench passed five.
  • New POOLS=p option: launch i reads pool i % p, as a step's 48 layers do, instead of one 256-expert pool for every launch. With real C1/C8 routing on a GB10 the tc3 fused read rate is 219-232 GB/s on one pool and 208-211 GB/s on 48 pools (preliminary: one box, min of 11 passes). No engine code is touched.

Third commit: qwen4_exp may slab-pack its shards (ATLAS_QWEN4EXP_SLAB_PACK=1, default off)

The fast loader's pack_slab (one allocation a shard instead of one cuMemAlloc a tensor) was refused at TP/EP > 1 for every loader, in serve_phases/weights.rs. This moves that decision to the loader, which the trait doc already calls the owner of the policy. This touches a shared gate: Nemotron's policy already returns false at TP/EP > 1, and no other loader opts in, so their behaviour is unchanged.

Why it is safe for qwen4_exp, one rank or the TP=EP=2 pair: slab_layout reserves offset 0, so every packed tensor is strictly interior to its slab, and the CUDA backend's free of an interior pointer is a no-op. The loader's frees are of its own buffers (gpu_concat_rows, the per-rank copies tp_shard makes at tp > 1) or go through WeightStore::reclaim / free_loader_source. Under a slab a reclaim returns no memory; the footprint below is net of that.

Same fingerprint and harness as above, same binary, switch off -> on (preliminary, single harness, 3 runs):

off on
Pre-KV footprint a rank 61.0 GB 55.8 GB
KV budget 29.7 GB 34.8 GB
C=1 tok/s 98.4 / 99.5 / 99.5 99.9 / 101.1 / 101.0
C=8 aggregate tok/s 205.7 / 206.5 / 206.2 209.4 / 209.9 / 209.5
  • Output identical on 27 decode requests, 4 long prompts (3.6K-25K tokens) and a 1/2/3/4/8-wide transition run. Cold 16K prefill unchanged.
  • Graceful stop exits 0 on both ranks, with no new teardown errors (the existing "teardown swept N allocations" warning reads 1,843 packed against 2,052 unpacked).
  • Not exercised: a single node, the non-fast loader, the other qwen4_exp checkpoints, non-CUDA backends (the trait's register_slab defaults to a no-op there).

A fourth commit adds SLAB=1 to the MoE bench (dev script only), which is where the read-rate effect was first seen.

Notes for reviewers

  • Default off, so nothing changes for existing deployments. I would like an opinion on whether it should simply follow ATLAS_QWEN4EXP_MTP_DRAFT_TP instead of being its own switch.
  • qwen4exp_mtp_tp.rs would have crossed 500 lines, so the lone-sequence pieces live in qwen4exp_mtp_tp_one.rs.
  • Pair, config() and head() in the existing test modules became pub(super) / pub(crate) so the new tests reuse them.

CLA

Generated with Devin

…pair

ATLAS_QWEN4EXP_MTP_DRAFT_TP splits the draft head of a batched propose
only. A lone sequence drafts on the per-sequence propose, so on the TP2
pair the worker idled through it: 8.4 ms of a 49.5 ms verify step at C1,
the draft head 611 us of each ~1.5 ms position (nsys, both ranks).

ATLAS_QWEN4EXP_MTP_DRAFT_TP_ONE=1 (default off, needs the switch above,
agreed by both ranks through the parity word) announces that propose as
a one-row plan and runs each position's draft head through the existing
TpRun::head. The one-row scalar tier writes the per-sequence head's
bytes, so drafts, acceptance and output are unchanged. A grammar-masked
propose reads the full head and is never announced.

Preliminary, single harness: 2x DGX Spark, Qwen3.8-Flash-Next FP4-Local,
3 runs each of 1024 tokens. C1 94.4/95.3/95.6 -> 98.6/99.5/99.1 tok/s,
C8 unchanged; 27 decode and 4 long-prompt outputs identical.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
maplepaladin73 and others added 3 commits November 15, 2026 20:31
qwen4exp_moe_c8_tc3_plan gained a sixth argument (has_shared) and the
bench still passed five, so `time` segfaulted inside cuLaunchKernel.

POOLS=p (with LAYER_PASSES) reads launch i from pool i % p instead of
one 256-expert pool for every launch, as a step's 48 layers do. On a
GB10 with real C1/C8 routing, one pool reads at 219-232 GB/s and 48
pools (34 GB) at 208-211 GB/s; preliminary, one box, min of 11 passes.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ATLAS_QWEN4EXP_SLAB_PACK=1 (default off) opts the qwen4_exp loader into
the fast loader's pack_slab: one allocation a shard instead of one
cuMemAlloc a tensor, each rounded to 2 MB pages.

The server refused packing at TP/EP > 1 for every loader. The loader is
now the single source for its topology: Nemotron's policy already
returns false there, so its behaviour is unchanged. qwen4_exp's frees
are of its own buffers or go through WeightStore::reclaim, and a packed
tensor is strictly interior to its slab, where the backend's free is a
no-op.

Preliminary, single harness: 2x DGX Spark, Qwen3.8-Flash-Next
FP4-Local, 3 runs of 1024 tokens, same binary, switch off -> on.
Pre-KV footprint 61.0 -> 55.8 GB a rank, KV budget 29.7 -> 34.8 GB;
C1 98.4/99.5/99.5 -> 99.9/101.1/101.0 tok/s, C8 205.7/206.5/206.2 ->
209.4/209.9/209.5. 27 decode and 4 long-prompt outputs identical.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…cations

With POOLS=48 and real routing on a GB10, tc3 fused reads at 208-211
GB/s with one cudaMalloc a projection and 218-221 GB/s carved from
slabs; no difference with one pool. Preliminary, one box.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@AzeezIsh

Copy link
Copy Markdown
Contributor

@maplepaladin73 Thanks. The nsys breakdown makes the case for the lone-sequence split clearly. Before we gate this on the pair, could you split it? This repo merges one change per PR, and each PR is measured as its own binary against its parent's, on what it touches. This branch has three independent changes:

  1. defa80195: the lone-sequence draft-head split. This PR, on main.
  2. 68e45f471: qwen4_exp slab-packs its shards at TP/EP > 1. It moves a shared gate in serve_phases/weights.rs, so it should get its own PR with the footprint/KV table you already have. It doesn't depend on (1), so it can be based on main too.
  3. 671558df1 + 117e0d1bd: the MoE bench fixes. Dev scripts only, so a small PR of their own.

On your question: I'd fold (1) into ATLAS_QWEN4EXP_MTP_DRAFT_TP rather than add ATLAS_QWEN4EXP_MTP_DRAFT_TP_ONE. The env-budget ratchet is already over (main fails it), the switch rides the parity word so both ranks agree anyway, and the output can't change. A lone sequence would then split whenever the batched propose does. If you'd rather keep it opt-in for one release, that's fine too. Say so in the PR body and we'll gate both settings.

I've approved the CI workflows for this branch, so the workspace jobs will report here. Your measurements are on a92bd068; we'll re-measure each split PR on our pair (reiner + spark2) against current main.

Generated with Devin

@AzeezIsh

AzeezIsh commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@maplepaladin73 Code review of defa80195 (the lone-sequence draft-head split). I can't run it: our 2× DGX Spark pair was decommissioned on 11-19, so this is review only, plus CI.

Correctness: looks right.

  • Lockstep: the head only takes the TP path when the model announced it. impl_b3 sets ctx.comm to the announce's communicator, and only tp_one_word announces at n == 1. TpRun's Drop drains the swaps on every other exit: the confidence stop, any ? inside forward_one, and a finish. So the worker can't be left waiting in a swap.
  • Rank agreement: bit 3 of parity_word, so a mismatched pair refuses at startup. one_requested() refuses _TP_ONE=1 without _TP=1.
  • Grammar-masked proposes are never announced, and the head side returns None for them.
  • Bytes: the one-row tier writing w4a16_gemv / dense_gemv_bf16's bytes is pinned by the new #[ignore] GPU test. Please paste its output from a GB10 (ok nvfp4=false/true: 6 one-row heads byte-identical).
  • Other callers: I checked both propose() call sites. impl_b2's self-spec path passes comm: None, and rank_split_ready is only overridden by dflash_head, so split_comm is always None for a qwen4_exp proposer.

Nit (robustness): draft_tp_one_run keys the TP run off ctx.comm.is_some() alone, not off self.tp_one. That's correct today, because the only caller that passes a communicator is the announce. But a future caller that hands a qwen4_exp propose the model's comm with ATLAS_QWEN4EXP_MTP_DRAFT_TP=1 set would issue unannounced swaps and hang the pair. A self.tp_one && guard there (or passing the announced Plan explicitly) would close that off.

Before merge:

  1. Split, as in my 11-18 comment: this PR = defa80195 only. 68e45f471 (qwen4_exp slab packing at TP/EP > 1, a shared gate in serve_phases/weights.rs) goes in its own PR, and 671558df1 + 117e0d1bd (bench scripts) in a third.
  2. Fold the switch into ATLAS_QWEN4EXP_MTP_DRAFT_TP (e.g. =2 also splits a lone sequence) instead of adding ATLAS_QWEN4EXP_MTP_DRAFT_TP_ONE. The env-budget ratchet is already over on main (1,171 vs 1,091 names).
  3. Build mdBook + rustdoc is red: "public documentation for draft_tp links to private item TpRun::head". Make it plain code text.
  4. Measurement: your C1 +4% (94.4–95.6 → 98.6–99.5 tok/s, 3 runs) and "27 decode + 4 long-prompt outputs identical" are the receipts this will merge on, since I can't reproduce them. Please attach the run records (fingerprint: binary SHA, both ranks' env, prompt set) to the PR.

The branch still merges cleanly into main cb4dcf9a7, and default-off means nothing changes for anyone who doesn't set the switch. Once 1–3 are pushed, I'll merge it on CI plus your pair receipts.

🤖 Generated with Claude Code

This branch has not been deployed

No deployments
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.

2 participants