Skip to content

qwen4_exp MTP: drafter BF16 attention and router, RNE draft quantizer, BF16 KV-only prompt rows - #267

Merged
AzeezIsh merged 6 commits into
Atlas-Inf:mainfrom
Enntity:sq-pr/mtp
Oct 30, 2026
Merged

AzeezIsh merged 6 commits into
Atlas-Inf:mainfrom
Enntity:sq-pr/mtp

Conversation

@data-angel

Copy link
Copy Markdown
Contributor

Part of #220. The qwen4_exp MTP drafter, as SparkQwen 0.4.0 runs it. weight_loader/qwen4_exp/mode.rs listed what was missing for this.

What

  • ATLAS_QWEN4EXP_MTP_BF16_ATTN=1: the drafter's own TP1 config gets attn_proj_bf16.
  • ATLAS_QWEN4EXP_MTP_BF16_ROUTER=1, or either serving mode: the drafter MoE uses the checkpoint's BF16 router (no NVFP4 copy), and its shared expert becomes an NVFP4 copy fused into the expert kernels. This matches production's _ROUTER=1.
  • The corrected-RNE NVFP4 weight converter (quantize_bf16_to_nvfp4_weight_rne, qwen3.8-flash-next target):
    • weight_quantizer() returns it under a mode;
    • the draft head's NVFP4 copy (Spark) uses it;
    • it is on the Qwen PDL list, because it enters PDL first.
  • Mode contract: Strict requires MTP_BF16_ATTN=1 with DRAFT_HEAD_NVFP4=0; Spark requires =0 with =1.
  • BF16 KV-only drafter rows: the MTP absorb and the prompt pass (ATLAS_QWEN4EXP_MTP_PREFILL) project K and V through dense_gemv_batchm in 8-row groups.
    • Before, BF16 drafter attention fell back to the full Q/K/V phase on every prompt row.
    • Ported from 9263250. Production's dense_mx check is main's QuantWeight::Mxfp8, already excluded.
  • With no switch and no mode, main's drafter runs byte for byte as before.
  • Ported from SparkQwen's engine: 15ecb5e, 030ec26, the drafter parts of 28611c0 and 7e056d6, and 9263250.

Why

Strict on main drafted on NVFP4 attention. That flattered its speed, and it is not what SparkQwen serves. With BF16 drafter attention but without the KV-only rows, Strict's prompt pass projected Q for every row: cold TTFT was 1.34 s at 2K and 7.17 s at 16K, against 0.70 / 3.94 s on 0.4.0 (image 6f3b619ca2fe).

Benchmarks

Fingerprint (every number below). ennspark03/04, two GB10s at TP=EP=2 over RoCE, 2026-10-29. Checkpoint nvidia/Qwen3.8-Flash-Next-FP4-Local. Served by the SparkQwen launcher, profile 8x32k (--speculative --num-drafts=7 --max-num-seqs=8 --max-seq-len=32768 --max-prefill-tokens=16384 --kv-cache-dtype=bf16 --gpu-memory-utilization=0.88 --enable-prefix-caching), Strict and Spark modes.

  • Baseline: SparkQwen 0.4.0, engine Enntity/atlas 9b25f57, image atlas-sparkqwen:3e0d9e7e4b29.

  • Candidate: Enntity/atlas enntity-stack/sq-integ cf4200e = Atlas-Inf main a12bffa plus this PR series, image atlas-sparkqwen:cc103bd6cc92.

  • Harness: SparkQwen bench/sq_bench.py: streamed, temperature 0, reasoning_effort low; decode = 384-token prose/code/JSON, 3 reps; cold TTFT at 2K/8K/16K/28K, 2 reps; aggregate decode at C1–C8, 256 tokens per stream, 2 reps; warm 8K/20K conversations. Medians per cell. Plus greedy_eq.py (8 prompts, 320 tokens, temp 0) and lp_dump.py (echo prompt logprobs at 1K/6K/20K tokens).

  • Baseline and candidate arms interleaved on the same pair in one session.

  • One box and one harness, so these are observations under this fingerprint, not cross-validated claims.

  • With the KV-only rows, Strict cold TTFT came back to 0.677 / 3.95 s at 2K / 16K. That image also carried W4A4, worth about 0.3 s at 16K, so the two are not separated.

  • Under the whole series, the drafts that 0.4.0 makes give byte-identical outputs and the same decode speed in both modes (table below).

Whole series vs SparkQwen 0.4.0 (arms q-040-* / q-fix-*):

Strict 0.4.0 Strict main+series Spark 0.4.0 Spark main+series
greedy text, 8 prompts 8/8 identical 8/8 identical
prompt logprobs (1K/6K/20K) max |Δ| 0.0000 max |Δ| 0.0000
decode prose / code tok/s 54.1 / 77.7 54.2 / 77.8 61.0 / 86.8 61.6 / 92.9
cold TTFT 2K / 16K / 28K s 0.681 / 3.94 / 6.92 0.677 / 3.95 / 6.99 0.673 / 3.90 / 6.88 0.673 / 3.94 / 6.94
C1 / C2 / C4 / C8 tok/s 51.3 / 83.5 / 131 / 192 51.3 / 83.4 / 130 / 189 58.1 / 88.5 / 139 / 192 58.8 / 89.2 / 139 / 202

For reference, Atlas-Inf main c998a49 with the same launcher measured −9..−12% at C1, −15% at C2, −21..−25% at C4 and +21% cold TTFT against 0.4.0 (2026-10-29, same pair and harness).

Tests

  • Host tests (written first):
    • MtpPrecision switch parsing, 4 tests;
    • the mode drafter-flag contract;
    • the RNE converter under a mode;
    • the kernel shadow detector declaring the RNE kernel;
    • BF16 KV-only batching (row groups, tails, skips Q) and its eligibility.
  • fmt, clippy, doc and the atlas-kernels, spark-model and spark-runtime tests pass.
  • Not carried: production's GPU test for the KV-only rows, which reads production-only checkpoint helpers; the PDL list check covers the kernel.
  • Not ported: production's 15a5b78, which skips building NVFP4 Q/K/V/O copies under attn_proj_bf16. It saves memory only (~13 MB a layer) and touches the shared attention builder.

Authorship

AI-authored (Claude Code), ported from SparkQwen's AI-authored engine. No human-written code.

🤖 Generated with Claude Code

data-angel and others added 5 commits October 29, 2026 21:23
…under a mode

Enntity's quantize_bf16_to_nvfp4_weight_rne (CUDA's nearest-even E4M3
scale and E2M1 conversion) had no kernel in this stack, so under
ATLAS_QWEN4EXP_SERVING_MODE mode::weight_quantizer() named the standard
converter and the draft copies did not carry Enntity's rounding.

The kernel lands as a qwen3.8-flash-next shadow of common/'s
quantize_bf16_to_nvfp4.cu (the common file included unchanged, one entry
point added; body byte-identical to Enntity's glm-5.3-flash file, which
Enntity shares into this target by symlink -- here the GLM target is left
untouched). weight_quantizer() names it whenever a mode is selected, as
Enntity's does, and the draft head's NVFP4 copy (ATLAS_QWEN4EXP_DRAFT_HEAD_NVFP4,
Spark) now takes it like the MTP drafter already did. Unset: the standard
converter everywhere, as before. Under draft TP both ranks build the head
copy from the mode, which startup parity already pins. PDL lists unchanged.

check_qwen4exp_kernel_names.py follows a shadow's .cu include (Enntity
7e056d6's translation_unit) so the included entry points still resolve.

Ported from Enntity/atlas 9b25f57 (mode.rs weight_quantizer,
qwen4exp_draft_head.rs, glm-5.3-flash/nvfp4/quantize_bf16_to_nvfp4.cu via
f4d95a1/70c35846, scripts/dev/check_qwen4exp_kernel_names.py), AGPL-3.0-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_MTP_BF16_ATTN / _ROUTER)

The MTP loader requantized the drafter layer's BF16 Q/K/V/O and router to
NVFP4. ATLAS_QWEN4EXP_MTP_BF16_ATTN=1 builds the drafter body with
attn_proj_bf16 (the --attn-proj-dtype bf16 arms) on its own TP=1 config
only. ATLAS_QWEN4EXP_MTP_BF16_ROUTER=1 gives the drafter Enntity's MoE:
the checkpoint's BF16 router (gate_nvfp4 None, on the scalar BF16 arms as
Enntity runs it, not the target's row-invariant tiers) and the shared
expert as an NVFP4 copy (mode::weight_quantizer) fused into the expert
kernels, in place of this stack's NVFP4 router copy and BF16-native
shared-expert chain. Enntity removed its _ROUTER switch when the BF16
router became its only drafter MoE (28611c0), so either serving mode
selects it here too. Each switch is on only at 1; both default off, and
unset (no mode) keeps today's drafter byte for byte. The target is
untouched. Drafts only, on the drafting rank, so as in Enntity neither is
a startup-parity setting.

The switches are read in one place, helpers::MtpPrecision (Enntity's
helpers.rs mtp_drafter_config / mtp_router_nvfp4 after 030ec26), with
the lookup injectable for the unit tests.

Ported from Enntity/atlas 15ecb5e, 030ec26, the drafter hunk of
28611c0 and the mtp.rs/helpers.rs hunks of 7e056d6 (AGPL-3.0-only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…contract)

With ATLAS_QWEN4EXP_MTP_BF16_ATTN implemented, the serving-mode drafter
flags take Enntity's contract: Strict requires MTP_BF16_ATTN=1 beside
DRAFT_HEAD_NVFP4=0, Spark MTP_BF16_ATTN=0 beside DRAFT_HEAD_NVFP4=1. The
file header no longer lists the switch among the ones this stack lacks
(and, since the previous commits, no longer says the RNE converter is
missing). REQUIRED_FLAGS are unchanged.

Ported from Enntity/atlas 9b25f57 mode.rs drafter_flags (7e056d6),
AGPL-3.0-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…PDL list

It enters PDL before reading its inputs, as production lists it; the PDL
list check fails without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tches

Under ATLAS_QWEN4EXP_MTP_BF16_ATTN=1 (Strict) the drafter's attention is
BF16, and the KV-only rows of the MTP absorb and the prompt pass
(ATLAS_QWEN4EXP_MTP_PREFILL) fell back to the full Q/K/V phase: every
prompt row projected Q too, about 0.2 ms a token of Strict TTFT (2K 0.70 ->
1.34 s, 16K 3.9 -> 7.2 s on 03/04 against 0.4.0). K and V now go through
dense_gemv_batchm in groups of up to eight rows (the scalar GEMV's K order
and reduction tree), as in SparkQwen 0.4.0; Q is never read.

Ported from Enntity/atlas 9263250 (production's dense_mx check is main's
QuantWeight::Mxfp8, already excluded by the k/v weight checks); its GPU
test reads production-only checkpoint helpers and is not carried.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor

Conflict with main resolved: normal git merge origin/main — kept both flag contracts (the #265/#266 switches and MTP_BF16_ATTN / MTP_BF16_ROUTER / MTP_PREFILL); resolution was doc-comment-only in weight_loader/qwen4_exp/mode.rs. clippy+fmt clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	crates/spark-model/src/weight_loader/qwen4_exp/mode.rs
@data-angel

Copy link
Copy Markdown
Contributor Author

Thanks. Your merge hadn't reached the branch (the head was still dad0c33 and showed as conflicting), so I pushed the same thing: a normal git merge of main (f1c8e55) into sq-pr/mtp, now at 8cc82e9, with no force-push. As you found, the conflict was doc-comment-only in weight_loader/qwen4_exp/mode.rs. fmt and clippy are clean, and spark-model passes 1967 tests and spark-runtime 455. I carried the same merge into #268 (sq-pr/modes 9542c96), whose mode.rs paragraph now names the four switches it requires. If you'd already resolved it locally, please take this head rather than pushing yours.

Separately, I'm running the two FP4-Local gates its BENCH.toml declares (bfcl-subset ST-995 and agentic-webserver) on one GB10 each, at main + #267–#271, with the four switches on and off. I'll post the records here.

🤖 Generated with Claude Code

@data-angel

Copy link
Copy Markdown
Contributor Author

Correction to my last comment: I'm not running the FP4-Local gates after all, so no gate records are coming from us. The pair checks you're running per PR are the verification. The sq-pr/mtp and sq-pr/modes merges above stand.

🤖 Generated with Claude Code

@AzeezIsh
AzeezIsh merged commit 3bacfa8 into Atlas-Inf:main Oct 30, 2026
1 check passed
@AzeezIsh

Copy link
Copy Markdown
Contributor

@data-angel, a correction to my earlier note on this PR: the "conflict resolution" merge I mentioned went to a branch of the same name in Atlas-Inf (Atlas-Inf:sq-pr/mtp / sq-pr/modes), not to your PR head on Enntity:sq-pr/*. Your own merges (8cc82e95d, 9542c96f4) differ from mine only in mode.rs's doc comment, so the code is identical.

Merged after the pair checks on main + #267…#271 (713fea77):

#268's strict boot is being checked now. Our rc16 profile exports DRAFT_HEAD_NVFP4=1 after the env overrides, so it needed a profile copy.

@data-angel
data-angel deleted the sq-pr/mtp branch November 3, 2026 05:07
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