Skip to content

feat(qwen4_moe): Qwen4-35B-A3B config, tokenizer-compat fallback, and DFlash2 mHC capture - #458

Merged
AzeezIsh merged 8 commits into
mainfrom
feat/qwen4-35b-a3b-core
Dec 4, 2026
Merged

AzeezIsh merged 8 commits into
mainfrom
feat/qwen4-35b-a3b-core

Conversation

@AzeezIsh

@AzeezIsh AzeezIsh commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Open for early testing & contributions — do not merge yet.
AMD Strix Halo validation against RadixArk/Qwen4-35B-A3B-NVFP4 (+ RadixArk/Qwen4-35B-A3B-Dflash2) is running on DevLab (47257869285); results and any follow-up fixes will land on this stack.

Summary

PR (1/2) in the Qwen/Qwen4-35B-A3B bring-up stack (model_type = "qwen4_moe", 40L 3:1 GDN/QSA, 256E/8A, H = 2048, 1M native context, PLE n-gram, 1 MTP layer, ViT, DFlash2). Stacked with #459 (feat/qwen4-35b-a3b-targets).

Adds the core config, tokenizer, and DFlash2 capture support needed to serve Qwen/Qwen4-35B-A3B and RadixArk/Qwen4-35B-A3B-NVFP4 (+ RadixArk/Qwen4-35B-A3B-Dflash2):

  1. Config dispatch & PLE alignment fix (atlas-core):
    • Routes "qwen4_moe" and "Qwen4MoeForConditionalGeneration" in dispatch.rs to parse_qwen4_exp (normalizing to "qwen4_exp").
    • Fixes parse_ngram_ple in qwen4_exp.rs: make_ngram_vocab_size_divisible_by pads the summed per-head prime table (Qwen4ExpNgram::padded_rows), not ngram_vocab_size_base itself (Qwen4-35B-A3B uses ngram_vocab_size_base = 10_000_000 with make_ngram_vocab_size_divisible_by = 512).
    • Adds the real Qwen/Qwen4-35B-A3B config.json test fixture + parser unit test (qwen4_35b_a3b_tests.rs).
  2. tokenizer-compat/ fallback & reasoning_effort = "off" (spark-server):
    • Qwen4 ships tiktoken.model at the repo root and places HF tokenizer.json, tokenizer_config.json, and chat_template.jinja under tokenizer-compat/.
    • Adds ChatTokenizer::resolve_tokenizer_dir fallback to tokenizer-compat/ in load.rs and serve_phases/config.rs, and includes tokenizer-compat/{tokenizer.json,tokenizer_config.json,chat_template.jinja} in model_download/plan.rs (+ unit test).
    • Translates disabled reasoning effort (enable_thinking = false / reasoning_effort = "none") to "off" when the loaded template accepts only ('xhigh', 'high', 'low', 'off') (Qwen4's chat_template.jinja raises on "none").
  3. DFlash2 mHC target-hidden capture (spark-model + strix-hip + gb10):
    • Adds hc_contract_strided (FP32 stream-mean highway contraction) to both kernels/strix-hip/qwen3.8-flash-next/nvfp4/hyper_connection.cu and kernels/gb10/qwen3.8-flash-next/nvfp4/hyper_connection.cu, and enables qwen4_exp alongside glm5_next in impl_b3_dflash.rs / capture_rows.rs.

Stack & How to Try / Contribute

  1. This PR (feat(qwen4_moe): Qwen4-35B-A3B config, tokenizer-compat fallback, and DFlash2 mHC capture #458) (feat/qwen4-35b-a3b-core → main)
  2. feat(targets): add strix-hip and gb10 qwen4-35b-a3b targets (+ DFlash2) #459 (feat/qwen4-35b-a3b-targets → feat/qwen4-35b-a3b-core) — check out feat/qwen4-35b-a3b-targets for the full runnable tree:
    git fetch origin feat/qwen4-35b-a3b-targets && git checkout feat/qwen4-35b-a3b-targets
    # AMD Strix Halo:
    ./build-amd.sh
    NUM_DRAFTS=0 ./serve-amd.sh RadixArk/Qwen4-35B-A3B-NVFP4
    # With DFlash2:
    DFLASH=1 DRAFT_MODEL=RadixArk/Qwen4-35B-A3B-Dflash2 DFLASH_GAMMA=8 ./serve-amd.sh RadixArk/Qwen4-35B-A3B-NVFP4

Open Areas for Contributors

  • NVIDIA (GB10 / SM121): Compile & test RadixArk/Qwen4-35B-A3B-NVFP4 (+ RadixArk/Qwen4-35B-A3B-Dflash2) on GB10, verify cargo test -p atlas-kernels -- --ignored, and audit any unresolved probes.
  • Fused GDN decode (nv / nk = 2): qwen4exp_decode_fuse currently assumes GDN_REPEAT = 3 (48V / 16K on Flash-Next) and cleanly skips on 32V / 16K; parameterizing a repeat = 2 arm benefits both Strix Halo and GB10.
  • Native tiktoken / encoding_qwen4.py parity: Current PR uses the checkpoint's shipped tokenizer-compat/ HF tokenizer + Jinja template; native anti-injection encoding_qwen4.py encoding is a clean follow-up.

AzeezIsh and others added 4 commits December 3, 2026 22:39
…ed mHC, wire verify_d piecewise graphs, and enable scalar NVFP4 DFlash head

Eliminates the dominant multi-row bottlenecks observed on gfx1151
(run 47268706905, where K=8 DFlash2 verify ran ~81 ms/step vs ~41 ms C1):
- Allow dense_gemv_batchm (chunked <=8) for gated BF16 QKV projections
  (tightening qkv_is_dense_bf16 to None | Dense only) with per-row
  deinterleave_qg, avoiding N-way sequential weight reads at n=2..32.
- Port gb10 vectorized multi-token mHC kernels (hc_pre_{stage,down,finish}_vec*
  and hc_post_vec) to strix-hip/hyper_connection.cu with plain vector loads
  and enable ATLAS_QWEN4EXP_HC_FAST on HIP (still default off).
- Switch PLE slot upload from copy_h2d_async to copy_h2d_async_retained
  so pinned staging no longer forces a per-step stream synchronize.
- Wire qwen4_exp piecewise graphs (decode_pieces, PieceStep::VerifyKgamma)
  into K=gamma verify_d.rs with full-row kgamma_dflash_capture.
- Add w4a16_gemv_batch{4,8,16} fallback in DFlash project_head so
  ATLAS_DFLASH_NVFP4_HEAD=1 works on strix-hip without tensor-core tiers.
- Batch BF16 MoE router GEMV in forward_rows_t when no router pre-norm.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…8_dyn_vl2_n2 in exact_rows, and retained DFlash markov H2D

Fixes three gfx1151 bottlenecks pinpointed by prof-k8 (run 47278407115):
- Lower strix-hip vectorized mHC ring depths (U=4, DN=2/1, FIN_UNROLL=4)
  and add __launch_bounds__(128) so T=5..8/rows stay in VGPRs without
  spilling (previously 321 us/site = 26.6 ms/step at K=8).
- Route qwen3_ssm exact_rows FP8 projections at 5..=8 rows (and 8-row
  chunks on HIP) through ops::fp8_verify_gemv_tier (w8a16_gemv_batch8_dyn_vl2_n2)
  instead of high-VGPR w8a16_gemv_batch16.
- Switch dflash_head/markov.rs seed_markov_prev from copy_h2d_async to
  copy_h2d_async_retained to remove the per-propose stream synchronize on
  the pinned staging buffer.

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

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

AzeezIsh commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

AMD Strix Halo (gfx1151) DevLab Progress Receipts (preliminary, single-shot per runner)

Fingerprint: RadixArk/Qwen4-35B-A3B-NVFP4@7d83fac3c8 + RadixArk/Qwen4-35B-A3B-Dflash2@cb9d9b2187, MAX_BATCH=8, MAX_SEQ_LEN=40960, GPU_UTIL=0.70, SSM_SLOTS=8, SSM_CKPT_INTERVAL=512, scripts/devlab/qwen4_35b_a3b_smoke.sh (decode_h2h.py thinking-off medians + thinking-on 512-tok panel + 21K-tok 3-needle check + ATLAS_QWEN4EXP_VERIFY_PROF=1). Tuned env: ATLAS_QWEN4EXP_FP8_GDN=1 ATLAS_QWEN4EXP_HC_FAST=1 ATLAS_PLE_FAULT_POOL=1 ATLAS_PLE_CACHE_GB=4 ATLAS_QWEN4EXP_DECODE_GRAPH=1 ATLAS_QWEN4EXP_DECODE_GRAPH_WIDE=1 (+ --dflash-window-size 2048 ATLAS_DFLASH_SPEC_THINK=1 ATLAS_DFLASH_CTX_ASYNC_POS=1 ATLAS_DFLASH_ASYNC_UPLOADS=1; BF16-target DFlash2 arms also set ATLAS_DFLASH_NVFP4_HEAD=1).

Arm Metric Run 47268706905 (bf59e87a9, r3 baseline) Run 47278407115 (be6dc85f1, r4) Run 47289055632 (12e8cfa40, r5)
base (BF16 head) C1 prose / code / json 21.6 / 24.1 / 24.2 31.8 / 31.8 / 31.7 29.1 / 30.1 / 30.0
base (BF16 head) C2 / C4 / C8 agg 44.3 / 66.3 / 80.4 51.2 / 68.7 / 69.9 50.4 / 70.6 / 80.2
base (BF16 head) prefill 7.4K / 29.4K 1529 / 1394 tok/s 1522 / 1389 (ctrl) · 1428 / 1310 (tuned) —
mtp1 (K=2, BF16 head) C1 prose / code / json 36.6 / 42.9 / 40.9 45.3 / 53.6 / 50.3 43.6 / 51.9 / 48.8
mtp1 (K=2, BF16 head) C2 / C4 / C8 agg 58.9 / 74.5 / 81.3 63.7 / 69.4 / 71.5 65.8 / 78.6 / 81.2
mtp3 (K=4, BF16 head) C1 prose / code / json — — 34.6 / 46.2 / 41.5 (C4 78.0, C8 80.9)
dflash2 (BF16 target + NVFP4 drafter head) think-on-512 67.9 (AL 5.28) 56.0 (AL 5.0) 65.7 (AL 5.0)
dflash2 (BF16 target + NVFP4 drafter head) C1 prose / code / json 22.7 / 36.0 / 27.4 25.9 / 35.0 / 28.6 26.6 / 43.2 / 29.9
dflash2 (BF16 target + NVFP4 drafter head) C2 / C4 / C8 agg 35.3 / 44.9 / 80.6 36.7 / 43.9 / 70.8 39.5 / 47.7 / 77.0
dflash2-fp4 (NVFP4 head) think-on-512 67.0 (AL 5.05) 59.8 (AL 5.1) 70.4 (AL 5.1)
dflash2-fp4 (NVFP4 head) think-math / think-code / think-prose — 47.0 / 34.3 / 21.5 54.6 / 39.1 / 25.1
dflash2-fp4 (NVFP4 head) C1 prose / code / json 25.1 / 39.2 / 29.3 29.0 / 33.9 / 31.2 29.8 / 38.4 / 31.8
dflash2-fp4 (NVFP4 head) C2 / C4 / C8 agg 37.8 / 46.9 / 81.5 39.5 / 46.7 / 71.9 41.4 / 48.2 / 77.5
dflash2-tuned 21,103-tok 3-needle retrieval — 3/3 exact 3/3 exact

K=8 stage profile (prof-k8, ATLAS_QWEN4EXP_VERIFY_PROF=1):

  • hc_pre_attn / hc_pre_ffn: 321 / 322 µs → 131 / 131 µs (-59% / 2.45× faster across 81 mHC sites after RDNA3.5 zero-spill ring tuning in 12e8cfa40, saving ~15.4 ms/step).
  • moe+hc_post_ffn (rows): 711 µs/L (28.4 ms across 40L vs 18.9 ms roofline).
  • QSA full-attn body: 336 µs/L (3.4 ms across 10L vs 2.5 ms roofline — BF16 gated QKV batching brought QSA to ~75% of ceiling).
  • PLE gather: 3.29 ms → 0.48 ms (-85% via ATLAS_PLE_FAULT_POOL=1 ATLAS_PLE_CACHE_GB=4 + copy_h2d_async_retained).
  • PAGE-LOCKED copy_h2d_async warnings: 0 across all 6 arms.
  • Note on host variance / open lever: 47278407115 (X2-LA03-S04-D07) and 47289055632 (X2-LA03-S03-D06) ran on different ephemeral runners; GDN body in prof-k8 measured 516 µs/L in r4 (w8a16_gemv_batch16) vs 605 µs/L in r5 (w8a16_gemv_batch8_dyn_vl2_n2), worth an interleaved same-runner A/B on exact_rows + checking FP8 mHC (radiance#801 idea) and FP8/NVFP4 dense trunk.

All workspace CI checks on 12e8cfa40 (cargo test --workspace, cargo llvm-cov, nvcc -> PTX (all gb10 targets), Linux x86_64/aarch64 CUDA builds, clippy, fmt, ≤500 LoC, SPDX) are green. Still draft / do not merge yet.

AzeezIsh and others added 2 commits December 4, 2026 12:58
…AT=2 fused decode, DFlash ctx/conv scalar NVFP4, and OOTB serve-amd.sh Qwen4-35B-A3B defaults

Makes RadixArk/Qwen4-35B-A3B-NVFP4 (+ DFlash2) serve cleanly out of the box
on AMD Strix Halo (gfx1151) with zero manual env flags:
- Change --dflash-window-size to Option<usize> and resolve CLI -> MODEL.toml
  [dflash].window_size -> drafter config.json sliding_window -> 4096 (so
  Qwen4-35B-A3B inherits window=2048 automatically).
- Parameterize strix-hip qwen4exp_decode_fuse.cu on REPEAT and add _r2
  fused GDN decode/rows kernels for Qwen4-35B-A3B's 16K/32V geometry.
- Generalize DFlash scalar w4a16_gemv_batch{4,8,16} NVFP4 fallback to
  ctx_projection (ATLAS_DFLASH_CTX_NVFP4) and conv_delta_gemm
  (ATLAS_DFLASH_CONV_TWIN=nvfp4) on targets without tensor-core tiers.
- Bump strix-hip HC_V_DOWN_DN8 / HC_V_WIDE_DOWN_DN from 1 to 2 for normed
  load overlap at T=5..8.
- Add Qwen4-35B-A3B out-of-the-box profile defaults in serve-amd.sh
  (fixing the MAX_BATCH>1 FP8_GDN override, avoiding the hardcoded 27B
  DRAFT_MODEL, and enabling validated Strix flags when unset).

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Same-runner interleaved A/B on Strix Halo (run 47392973648, X2-LA03-S04-D08)
showed plain w8a16_gemv_batch8 (VL2=0) beats w8a16_gemv_batch8_dyn_vl2_n2
at Qwen4-35B-A3B's K=2048 width by -2.62 ms/step on K=8 DFlash2
(76.78 / 76.66 ms controls vs 74.10 ms VL2=0) and +2.4 tok/s on C8
(92.7 / 92.6 vs 95.1 tok/s). Still overridable via ATLAS_GEMV_VL2=1.

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

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

AzeezIsh commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Strix Halo (gfx1151) Out-of-the-Box ./serve-amd.sh & Interleaved A/B Receipts — Run 47392973648

Fingerprint: devlab/qwen4-35b-a3b-test-r6@7ef316a78 (engine 300e726ff), host X2-LA03-S04-D08, RadixArk/Qwen4-35B-A3B-NVFP4@7d83fac3c8, RadixArk/Qwen4-35B-A3B-Dflash2@cb9d9b2187 (auto-resolved from MODEL.toml [dflash], γ=8, window=2048), MAX_BATCH=8, MAX_SEQ_LEN=40960, SSM_SLOTS=8. Zero manual ATLAS_*, --dflash-window-size, --dflash-gamma, or --draft-model flags on the OOTB arms.

Arm (all on X2-LA03-S04-D08) think-on-512 think-math/code/prose C1 prose / code / json C2 / C4 / C8 agg rows=8 med step 21K needle
ootb-mtp (./serve-amd.sh "$CK") 36.1 (serial) — 44.7 / 53.5 / 51.6 68.2 / 79.1 / 92.7 79.9 ms —
ootb-dflash2 (DFLASH=1, ctrl1) 68.7 (AL 5.0) 41.4 / 40.5 / 31.1 31.0 / 43.4 / 32.1 42.2 / 50.9 / 92.7 76.78 ms 3/3 exact (21,103 tok)
ootb-dflash2-vl2off (DFLASH=1 ATLAS_GEMV_VL2=0) — 40.4 / 41.2 / 23.4 31.2 / 37.9 / 32.9 41.9 / 51.0 / 95.1 74.10 ms —
ootb-dflash2-bf16head (DFLASH=1 LM_HEAD=bf16) — 53.5 / 29.0 / 24.2 27.7 / 41.2 / 30.1 39.7 / 49.5 / 91.7 77.71 ms —
ootb-dflash2-ctrl2 (DFLASH=1, interleaved ctrl2) — 41.5 / 37.5 / 24.7 30.0 / 38.9 / 33.6 42.6 / 51.3 / 92.6 76.66 ms —

Key verified outcomes:

  1. Zero-flag OOTB serving works end-to-end: MODEL.toml auto-resolved RadixArk/Qwen4-35B-A3B-Dflash2, γ=8, and window=2048; serve-amd.sh auto-armed qwen4exp_gdn_decode_fused_r2 / _rows_r2 (0x5), HC_FAST=1, FP8_GDN=1, DECODE_GRAPH=1+WIDE=1, PLE_CACHE_GB=4, DFLASH_SPEC_THINK=1, CTX_NVFP4=1, CONV_TWIN=nvfp4, and async DFlash uploads. PAGE-LOCKED warnings = 0 across all 6 arms.
  2. qwen4exp_gdn_decode_fused_r2 / _rows_r2 impact: Apples-to-apples BF16-head C8 jumped 77.0 → 91.7 tok/s (+19.1%) vs 47289055632; serial C1 (ootb-mtp) jumped 30.2 → 36.1 tok/s.
  3. Scalar NVFP4 ctx + conv DFlash twins: Step tail (L39 + head + DFlash2 5L propose) dropped 16.09 → 14.22 ms (-1.87 ms/step).
  4. Same-runner interleaved A/B (ctrl1 → candidate → ctrl2, 0.15% drift): ATLAS_GEMV_VL2=0 (w8a16_gemv_batch8) beat w8a16_gemv_batch8_dyn_vl2_n2 by -2.62 ms/step on K=8 (76.78 / 76.66 → 74.10 ms) and +2.4 tok/s on C8 (92.7 / 92.6 → 95.1 tok/s). Locked in via 10a14ba93 (ATLAS_GEMV_VL2="${ATLAS_GEMV_VL2:-0}" for Qwen4-35B-A3B in serve-amd.sh).

…0.061 NLL drift

Run 47402881193 KL gate showed quantizing Qwen4-35B-A3B's BF16 lm_head.weight
to NVFP4 adds +0.061 prompt NLL (max |dlp|=0.930) and 3x higher decode KL
for only ~0.9 ms/step (1.2%) on DFlash2. Keeping target LM_HEAD=bf16 (with
ATLAS_DFLASH_NVFP4_HEAD=1 still accelerating the drafter head) preserves
0.0000 prompt NLL delta vs golden and removes the padded-stride warning.
Still overridable via LM_HEAD=nvfp4.

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

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

AzeezIsh commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Strix Halo (gfx1151) KL Divergence & Golden BFCL ST-995 Accuracy Receipts

  • KL Divergence Gate (runs 47402881193 & 47406393872, RadixArk/Qwen4-35B-A3B-NVFP4@7d83fac3c8 + RadixArk/Qwen4-35B-A3B-Dflash2@cb9d9b2187):
    • exact-opt (HC_FAST=1, DECODE_GRAPH=1+WIDE=1, DECODE_FUSE=1 _r2, PLE_FAULT_POOL=1, PLE_CACHE_GB=4, LM_HEAD=bf16, FP8_GDN=0): KL = 0.000e+00, 642/642 exact token match, max |ΔNLL| = 0.0000 vs un-tuned golden BF16 reference.
    • Caught +0.061 prompt NLL drift (max |Δlp| = 0.930) from LM_HEAD=nvfp4; switched serve-amd.sh default to LM_HEAD=bf16 (487b72b0a, 0.0000 prompt NLL delta while ATLAS_DFLASH_NVFP4_HEAD=1 keeps the drafter head fast).
  • Golden bfcl-subset (62/10/10, n=995, seed=42, temp=0, NO param overrides) on exact pushed PR stack (487b72b0a / 4f1be0bcd):
    • ootb-dflash2 (DFLASH=1 ./serve-amd.sh, run 47409288279, X2-LA03-S01-D04, 0 errors, 0 PAGE-LOCKED warnings, 165,159 tok, med tok_step=2.292): overall_accuracy = 85.23, normalized_single_turn_score = 83.11 (non_live 83.40, live 78.24, hallucination 87.69; simple_python 94.35, live_simple 96.00, multiple 90.32, parallel 87.10, parallel_multiple 87.10).
    • ootb-mtp (./serve-amd.sh, run 47409294061, X2-LA03-S04-D02, 0 errors, 0 PAGE-LOCKED warnings, 0 unmatched, 163,160 tok, med 34.4 tok/s, p1=0.833): overall_accuracy = 84.12, normalized_single_turn_score = 82.53 (non_live 81.62, live 79.41, hallucination 86.55).
  • 21,103-token 3-needle gate: 3/3 exact hits across 3 consecutive runs (47278407115, 47289055632, 47392973648).
  • Workspace CI: All gating checks green on both PR feat(qwen4_moe): Qwen4-35B-A3B config, tokenizer-compat fallback, and DFlash2 mHC capture #458 (487b72b0a) and PR feat(targets): add strix-hip and gb10 qwen4-35b-a3b targets (+ DFlash2) #459 (4f1be0bcd), including cargo test --workspace, cargo llvm-cov, nvcc -> PTX (all gb10 targets), and both Linux CUDA release builds.

@AzeezIsh
AzeezIsh marked this pull request as ready for review December 4, 2026 22:07
@AzeezIsh
AzeezIsh merged commit 7cf5d6f into main Dec 4, 2026
23 of 26 checks passed
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