Skip to content

qwen4_exp: SparkQwen's MXFP8 decode tiers, W8A8 prefill and EP-split MXFP8 shared expert on FP4-Local (opt-in) - #265

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

AzeezIsh merged 4 commits into
Atlas-Inf:mainfrom
Enntity:sq-pr/parity

Conversation

@data-angel

@data-angel data-angel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Part of #220. This is the core of the SparkQwen-on-main series. With the whole series, SparkQwen 0.4.0 runs on Atlas main byte for byte and at the same speed (Benchmarks).

Series

Merge order: #265 → #266 (stacked on it) → #267 → #268 (stacked on #267; it requires #265 and #266) → #269, #270 and #271 in any order.

What

Three opt-in switches and two SP prefill fixes for nvidia/Qwen3.8-Flash-Next-FP4-Local, ported from SparkQwen's engine (Enntity/atlas spark-shared 9b25f57). With each switch unset, main runs exactly as before.

  • ATLAS_QWEN4EXP_MXFP8_DECODE=1
    • Every 1..=32-row mxfp8_proj launch (decode, verify, mxfp8_proj_exact_rows chunks) runs on the tensor-core tiers mxfp8_gemv_tc{8,16,32} (mxfp8_gemv.cu) instead of the CUDA-core GEMV tiers.
    • Both families are row-invariant; they sum in a different order.
  • ATLAS_QWEN4EXP_PREFILL_W8A8=1
    • GDN qkvz/out and attention q/k/v/o prefill run as MXFP8×MXFP8 GEMMs on cuBLASLt's block-scaled tensor cores, instead of expanding the weight to BF16 for every call.
    • The checkpoint's E4M3 bytes are the weight. Only the scales are relaid, once at load (3% of the weight).
    • Runtime support:
      • fp8_gemm_act_weight_t_mx;
      • mx_algo: a tuned in-order kernel per row bucket, row-invariant;
      • mx_sweep, mx_pinned;
      • kchain_pin::in_order, which also stops the BF16 k-chain pin from accepting a negative split-K kernel.
    • The prefill mHC collapse writes its rows' MXFP8 image in its epilogue (hc_up_mix_bf16_nt_mx), so those rows skip the activation quant.
  • ATLAS_QWEN4EXP_MXFP8_SHARED=1: the shared expert as SparkQwen serves it.
    • Decode and verify rows run on SwiGLU tensor-core tiers: gate, up and SiLU·up in one pass, rounded as vLLM's silu_and_mul rounds them.
    • Prefill runs W8A8.
    • Under EP each rank holds half the intermediate (column-parallel gate/up, row-parallel down: the reference's TP2 layout). Its partial joins the routed partial before the EP all-reduce or reduce-scatter.
    • MoeLayer::shared_joins_reduce keeps the partial in every EP blend (row, row pair, T rows, batched, MOE_FAST). The atomic-C4 arm steps aside.
    • On EP decode steps it runs on a side stream forked at the MoE entry, overlapping the router and routed experts.
  • Two SP prefill overlaps that were inert on FP4-Local:
    • _PREFILL_SP_ROUTE now routes a rank's own rows on the BF16 router's tile GEMM. That is the kernel the whole-batch FP4-Local router already runs, now one function, try_bf16_router_gemm. Before, the lane needed an NVFP4 router copy that FP4-Local never builds.
    • _PREFILL_SP_RS_PIPE now pipes a W8A8 out_proj by row ranges. Before, it needed out_proj_dense.

The three switches are in startup parity. A [job] issue is not opened for this series; the measurements are below.

Why

On Atlas main c998a49, SparkQwen 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). These arms are where that time went:

  • the decode GEMV family;
  • the per-call BF16 expansion in prefill;
  • replicated shared-expert bytes;
  • two SP overlaps that never engaged.

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.

This PR's own contribution is observed, not isolated: each arm was measured inside the stack.

  • Decode arms. Image 6f3b619ca2fe had this PR's first three arms plus the PLE, RDMA and MTP PRs, but not W4A4 or the SP fixes. Against 0.4.0 it measured:
    • C1 +8.5% (Strict) / +3.2% (Spark), C2 +10.2% / +5.5%, C4 −1.3% / +0.1%;
    • cold TTFT still +8..14% (Spark).
  • SP overlaps. One profiled 16K cold prefill each (ATLAS_PROFILE_FIRST=1), before vs after the fix:
    • MoE routing (gate_gemm + topk + sort): 87.4 → 26.7 ms; 0.4.0's fused route took 27.7 ms;
    • GDN out_proj: 179.9 → 147.5 ms;
    • TTFT: 3.99 → 3.84 s; 0.4.0 took 3.89 s.

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).

Default. These stay opt-in because they change FP4-Local's bytes against main's current paths, which #198 chose. The measurement that would flip them on: the FP4-Local ST-995 and agentic-webserver gates with the series on vs off.

Tests

  • Host tests (written first):
    • tc tier dispatch per row count (32-row launches, tail tiers) and its kernel ABI;
    • the switch parse;
    • W8A8 per-layer operand lookup and the collapse producer slots;
    • activation quant against a host ModelOpt reference, and the cuBLASLt tile offsets;
    • mx_algo bucket tables and the sweep;
    • SwiGLU row launches and ABI;
    • shared-expert decode launch order and twin-shape refusals;
    • the BF16 router tile GEMM serving only a flagged layer;
    • the out_proj pipe predicate;
    • startup parity names.
  • GPU tests (#[ignore]):
    • tc rows equal the 1-row launch for m = 1..=65 at the four FP4-Local TP2 shapes, on realistic and hostile bytes;
    • the quant and relayout kernels write the host reference's bytes;
    • W8A8 rows don't depend on pass height and stay within 5e-2 rel-L2 of the BF16 expansion.
  • cargo fmt --check, cargo clippy --workspace --tests and cargo doc --workspace --no-deps pass. cargo test passes for spark-model and spark-runtime.
  • The image build's full cargo test --workspace --release passed.
  • Not yet run: the spark benchmark run --pull-request-gate records at this tip.

Authorship

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

🤖 Generated with Claude Code

data-angel and others added 4 commits October 29, 2026 21:23
…ensor-core tiers

SparkQwen 0.4.0 decodes FP4-Local's MXFP8 projections (GDN qkvz/out,
attention, indexer, shared expert) on `mxfp8_gemv_tc{8,16,32}`; main serves
them on the CUDA-core `mxfp8_proj` GEMV tiers. With the switch at 1, every
1..=32-row `mxfp8_proj` launch (decode, verify, `mxfp8_proj_exact_rows`
chunks) takes the tensor-core tier for its width instead. Both families are
row-invariant; they sum in different orders, so the switch is in startup
parity. Unset keeps today's tiers byte for byte.

Kernels: SparkQwen's `glm-5.3-flash/nvfp4/mxfp8_gemv.cu` (a superset of
main's: tiled, multi, SwiGLU and B128 forms over the same tc core), its PDL
touch helpers, `common/mxfp8_act_quant.cuh`, and the qwen3.8-flash-next
`mxfp8_gemv.cu` that includes them plus the SwiGLU twins.

Tests: dispatch per row count (32-row launches, tail tiers), the launch ABI,
the switch parse, the GEMV fallback, and an ignored GPU test that every row
of an m-row tc launch (m = 1..=65) equals its 1-row launch at the four
FP4-Local TP2 shapes on realistic and hostile bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Lt W8A8 GEMMs

SparkQwen 0.4.0 prefills FP4-Local's MXFP8 projections (GDN qkvz/out,
attention q/k/v/o) as MXFP8 x MXFP8 GEMMs on cuBLASLt's block-scaled tensor
cores; main expands each weight to BF16 per call and runs a BF16 GEMM. With
the switch at 1 each layer carries an `MxPrefill` (the checkpoint's E4M3
bytes, scales relaid once at load into cuBLASLt's 128x4 tiles, 3% of the
weight) and every prefill pass takes it; decode and verify are unchanged.
The prefill mHC collapse writes the qkvz / q-k-v input's MXFP8 image in its
epilogue (`hc_up_mix_bf16_nt_mx`) so those rows skip the quant pass.

Ported from SparkQwen's engine (Enntity/atlas spark-shared 9b25f57):
- spark-runtime: `fp8_gemm_act_weight_t_mx` and its tuned per-row-bucket
  in-order kernel choice (`mx_algo`, the invariance sweep `mx_sweep`, the
  pinned kernel split into `mx_pinned` for the file cap), `fixed_algo`'s
  MXFP8 / block-FP8 operands, and `kchain_pin::in_order`, which also stops
  the BF16 k-chain pin from taking a negative split-K kernel
- the arena's FP8 scale scratch holds a tiled MXFP8 image of any row count
- `ops::mxfp8_act` (activation quant, scale relayout), `ops::MxW8a8`,
  `ops::qwen4exp_w8a8` (the switch, the collapse producer slots) and
  `common/mxfp8_act_quant.cu`
- the PDL list check reads `atlas_pdl_enter_touch_tri`, and the GLM list
  names the tiled, block-FP8 and multi MXFP8 tiers the shared kernel file
  now defines (inert unless ATLAS_PDL=1)

Unset keeps main's prefill byte for byte. Opt-in (`1`), where SparkQwen's
engine reads it as default-on; SparkQwen sets it. In startup parity.

Tests: switch parse, the per-layer operand lookup, the producer slots,
activation quant against a host reference (ModelOpt rounding), cuBLASLt
tile offsets, bucket/sweep tables, and ignored GPU tests that the quant and
relayout kernels write the host reference's bytes and that W8A8 rows do not
depend on the pass height and stay within 5e-2 (rel L2) of the BF16
expansion at the FP4-Local TP2 shapes.

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

SparkQwen 0.4.0 serves FP4-Local's MXFP8 shared expert three ways main
does not: decode and verify rows on the tensor-core SwiGLU tiers
(`mxfp8_gemv_tc{8,16,32}_swiglu`, gate/up and SiLU * up in one pass, then
down on the plain tiers), prefill as W8A8 GEMMs under
ATLAS_QWEN4EXP_PREFILL_W8A8=1, and under EP each rank holding half the
intermediate (column-parallel gate/up, row-parallel down: the reference's
TP2 layout) with its partial joining the routed partial before the EP
all-reduce or reduce-scatter. On EP decode steps it runs on a side stream
forked at the MoE's entry, overlapping the router and routed experts.

With the switch at 1 the layer carries `SeparateSharedExpert::Mxfp8Native`
(`layers/moe/shared_mxfp8.rs`, loaded by `weight_loader/qwen4_exp/
shared_mx8.rs`). `MoeLayer::shared_joins_reduce` keeps the partial in every
EP blend (single row, row pair, T rows, batched, MOE_FAST) and stops
`forward_ep_reduce` adding a shared expert after the reduce; prefill blends
it before the reduce, or per row range inside the q38 reduce-scatter pipe.
The atomic C4 arm, whose finalize adds a whole shared expert, steps aside.
A call that finds the lane forked joins it and checks it writes the lane's
rows. Unset keeps main's shared expert byte for byte. In startup parity.

Ported from SparkQwen's engine (Enntity/atlas spark-shared 9b25f57:
f7ee11e, 789285e, 802eddd, 9507c06, 89ffeed), with
`ops::mxfp8_swiglu_rows` for main's MXFP8 weight type.

Tests: SwiGLU row launches (tiers, 32-row chunks, ABI, k refusal), the
decode and W8A8-less prefill launch order, and twin shape refusals.

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

Two SP prefill overlaps that SparkQwen 0.4.0 runs and main skipped on
FP4-Local (one profiled 16K cold prefill on 03/04: +60 ms routing, +21 ms
GDN out_proj against 0.4.0):

- ATLAS_QWEN4EXP_PREFILL_SP_ROUTE routed a rank's own rows only through the
  NVFP4 router copy, which FP4-Local does not build (its router stays the
  checkpoint's BF16), so every rank routed all rows after the gather. It now
  routes them on the BF16 router's tile GEMM, the kernel the whole-batch
  prefill router already runs (`MoeLayer::try_bf16_router_gemm`, one
  function for both), as SparkQwen does (Enntity/atlas 28611c0).
- ATLAS_QWEN4EXP_PREFILL_SP_RS_PIPE piped out_proj by row ranges only on the
  dense BF16 arm; an MXFP8 layer has no `out_proj_dense`, so its out_proj
  and reduce-scatter ran back to back. Native MXFP8 on W8A8 pipes too: its
  rows are independent (per-row quant, in-order kernels), so every byte is
  the unsplit pass's (`out_proj_rows_independent`). The ranges compute on
  one stream, so they share the activation scratch in order.

Tests: the BF16 router GEMM launches only on a flagged layer, one 128x128
tile grid; out_proj pipes on dense BF16 and W8A8 MXFP8, not on MXFP8's GEMV
tiers.

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

Copy link
Copy Markdown
Contributor

@data-angel Picking up the series now, in your order (#265 → #266 → #267 → #268 → #269/#270/#271), one pair-gated step at a time on our two GB10s (reiner + spark2, single-rail RoCE, tp2-profile-rc16 + 8x32k geometry).

  1. qwen4_exp: SparkQwen's MXFP8 decode tiers, W8A8 prefill and EP-split MXFP8 shared expert on FP4-Local (opt-in) #265 + qwen4_exp: W4A4 routed-expert prefill at FP4-Local's input scales (ATLAS_QWEN4EXP_PREFILL_W4A4, opt-in) #266, merged onto main (df1dbcc3), checked first.
  2. qwen4_exp MTP: drafter BF16 attention and router, RNE draft quantizer, BF16 KV-only prompt rows #267 conflicts with qwen4_exp: SparkQwen's MXFP8 decode tiers, W8A8 prefill and EP-split MXFP8 shared expert on FP4-Local (opt-in) #265/qwen4_exp: W4A4 routed-expert prefill at FP4-Local's input scales (ATLAS_QWEN4EXP_PREFILL_W4A4, opt-in) #266 in weight_loader/qwen4_exp/mode.rs when they're merged in your order. Once qwen4_exp: SparkQwen's MXFP8 decode tiers, W8A8 prefill and EP-split MXFP8 shared expert on FP4-Local (opt-in) #265/qwen4_exp: W4A4 routed-expert prefill at FP4-Local's input scales (ATLAS_QWEN4EXP_PREFILL_W4A4, opt-in) #266 are on main, I'll resolve it with a normal merge of main into sq-pr/mtp, with no force-push, unless you'd rather restack it yourself. Say which you prefer.
  3. comm: pin the RDMA pair proxy to the fastest core; post the chained flag WRITE inline #270's proxy pin is on by default, so its check is the default config: decode-floor plus C1 references.

I'll post results here and on each PR.

@AzeezIsh
AzeezIsh merged commit 27dfb25 into Atlas-Inf:main Oct 30, 2026
1 check passed
AzeezIsh added a commit that referenced this pull request Oct 30, 2026
…t scales (ATLAS_QWEN4EXP_PREFILL_W4A4, opt-in)

Pair-gated on main + #265 + #266 (wave1a, #220): switches unset -> C1/C8 == #198 refs 8/8, tools 21/21; all four switches on -> decode-floor 89.3 vs 84.1 tok/s (n=3), cold TTFT -13..-15%, tools 21/21. CI green except the PR benchmark gate.
@AzeezIsh

Copy link
Copy Markdown
Contributor

Merged #265 and #266 (main f1c8e556f). Pair check on main + #265 + #266 (df1dbcc3), on reiner + spark2 with the rc16-resident profile. Receipts are in reiner's ~/code/night1027/out/wave1a/.

switches unset MXFP8_DECODE + PREFILL_W8A8 + MXFP8_SHARED + PREFILL_W4A4
C1 / C8 greedy vs #198 references 8/8, 8/8 identical 0/8 (expected: these switches change the numerics)
tools 21/21 21/21
decode-floor, n=3 84.09 / 84.17 / 84.19 tok/s 89.36 / 89.29 / 89.25 tok/s (+6.2%)
cold TTFT 2K / 8K / 16K / 28K 922.5 / 2644.7 / 5626.9 / 9412.5 ms 801.9 / 2280.3 / 4817.8 / 8008.1 ms (−13..−15%)

Each column is a single boot of the same binary; only the switches differ. With the switches unset, main's outputs are unchanged.

Next is #267. It conflicts with main in weight_loader/qwen4_exp/mode.rs now that #265 and #266 are in. I'll resolve that with a normal merge of main into sq-pr/mtp, unless you'd rather restack it yourself, @data-angel.

data-angel added a commit to Enntity/atlas that referenced this pull request Oct 30, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	crates/spark-model/src/weight_loader/qwen4_exp/mode.rs
data-angel added a commit to Enntity/atlas that referenced this pull request Oct 30, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	crates/spark-model/src/weight_loader/qwen4_exp/mode.rs
AzeezIsh added a commit that referenced this pull request Oct 30, 2026
…ft quantizer, BF16 KV-only prompt rows

Pair-gated (#220, wave1b/1c): switches unset -> no change to C1/C8 vs refs; with MTP_BF16_ATTN/ROUTER on top of the #265/#266 set, decode-floor 89.97-90.00 vs 89.25-89.36 without (observed, one boot each); Spark mode (NVFP4 draft attn) gives C1 identical to the BF16-draft run. CI green except the PR benchmark gate.
@data-angel
data-angel deleted the sq-pr/parity 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