Skip to content

xpu(flashnext): Xe2 DPAS tile kernels, adaptive solo chunks, and confidence MTP - #3603

Merged
ashhart merged 7 commits into
ashhart:mainfrom
supernovae:xpu-flashnext-perf
Nov 21, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
supernovae:xpu-flashnext-perf

Conversation

@supernovae

@supernovae supernovae commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Refs #3583
Depends on #3587 (stacked 4 of 4: #3585 -> #3586 -> #3587 -> this PR)

Summary

Optimizes Qwen3.8 Flash Next (qwen4_exp) prefill and decode throughput on Intel Xe2 GPUs (TP={1, 2, 4}) while preserving 0-ULP bit-exact chunk invariance across 1 .. 2,048 rows:

  1. Coalesced 16-Column Tile-Packed Intel Xe2 XMX DPAS Kernels (fn_dpas.cl, fn_moe_head.cl, fn_mixers.cl, flashnext.cl):

    • Packs group-32 affine Q4 weights at load (PackJob on host_pool) into [ceil(N/16), K/32, 4, 16] tiles so every 16-lane subgroup reads 4 contiguous 64-byte cachelines across all batch widths R = 1 .. 2,048.
    • Computes activation group sums via ONES_BF16 (0x3f803f80) XMX DPAS and fixed left-to-right 4-quarter K-reductions (((p0 + p1) + p2) + p3) so R = 1, R = 2..16, R = 64, and R = 2,048 produce bit-for-bit identical outputs (chunk_invariant = true, unlocking .planned = false prompt-cache rules).
    • Moves dense projections (qmv1_dpas, qmv16_dpas, qmm_tile_dpas), HyperConnections (hc_down_1/wide, hc_upmix_1/dpas, 4-stream parallel hc_writeback_norm), router (router_dpas_1/mm), and MoE (moe_compact, moe_up_1/dpas, moe_down_1/dpas, moe_sh_up_1/dpas, moe_combine) onto Xe2 DPAS with 0 compiler warnings and 0 register spills (ocloc -device bmg).
    • Uses 16x64 query-blocked POOLED SLM reuse in fn_qsa_scores (local ushort qs[16][512], KERNEL(256)), cutting qsa_scores 1.90x at 256k (62.62 -> 32.89 s, exact fma / sub_group_reduce_add order preserved).
    • Uses [32x64] KERNEL(256) layout and active-subgroup masking (sg_m * 8 < m / sg_m * 16 < m) in fn_moe_up_dpas / fn_moe_down_dpas for sparse small-m expert groups (86.6% of busy c=64 groups have m <= 8), plus row-parallel (tiles, R) launches (R = 1..16) on narrow-N L2-resident projections and active-pair Split-K DPAS during speculative verify / verifyMulti.
  2. Adaptive Solo Prompt Chunking & Attention Scratch Sub-Tiling (xpu_lane_prompt.zig, xpu_flashnext.zig, xpu_state.zig, xpu_ops.zig, xpu_store.zig):

    • Implements prefill_step, cancel_prefill, and reports_fill on native/xpu_lane.zig (xpu_lane_prompt.zig), using lanes.solo_chunk.passRows to run solo_rows = 2,048 when no other stream is decoding and automatically drop to busy_rows = 64 when an active stream is decoding (XPU_CHUNK and XPU_CHUNK_SOLO validated before device access).
    • Sub-tiles QSA attention score/index/merge scratch at attn_tile_rows = 64 inside attnRank, saving ~3.3 GiB/GPU so full 262,144 (256k) context fits in 24.42 GiB/GPU (> 7.3 GiB/GPU free on 32 GB cards) even with solo_rows = 2,048.
  3. Confidence-Stopped MTP Chains & Probability Pricing (xpu_engine.zig, xpu_lane.zig, xpu_forward.zig, xpu_ple.zig):

    • Adds draftFirstProbs / draftKeptProbs with cumulative confidence early-stopping (conf = -0.4, max_drafts = 6) and wires treeFn + probabilitiesFn (draft_probabilities = true, plain_streams = 16) into xpu_lane.zig, plus removes the redundant host syncAll() at the end of keepRowsSeq and folds w_scale into single-pass PLE dequantRow.

Full Benchmark Receipts (4x Intel Arc Pro B70 32 GB, TP=4, Qwen3.8-Flash-Next-MLX-4bit-MTP, d8c10bb)

Updated full tools/bench_*.py + xpu-flashnext tables (2K -> 256K full 262,144 window) attached to Gate Issue #3583: #3583 (comment) (superseding earlier c5944f1 run: #3583 (comment)).

Metric (TP=4, 4x Arc Pro B70) #3587 Baseline (64-row) This PR (d8c10bb, DPAS + QSA/MoE + Adaptive Solo) Delta vs #3587
bench_cache.py Cold Prefill (2K / 8K / 32K) ~385 tok/s 1,640.8 / 1,539.6 / 1,474.5 tok/s pk (1.25s/5.33s/22.5s) 3.83x - 4.26x
bench_cache.py Cold Prefill (64K / 128K / 256K full) ~380 / ~375 / ~350 tok/s 1,412.6 / 1,319.4 / 1,173.9 tok/s pk (46.5s/99.7s/226.2s) 3.35x - 3.72x
Raw CLI Prefill (32K / 64K / 128K / 256K ceiling) 394 / 393 / 386 / 359 tok/s 1,347.6 / 1,340.1 / 1,287.6 / 1,163.9 tok/s 3.24x - 3.42x
MTP Draft Step Latency (--bench warm) 6.45 ms/round 1.74 - 1.82 ms/round 3.6x faster
bench_openai.py 256 tok (fibonacci / chat, T=0 med) — 176.5 (180.1 pk, 4.00 tok/chunk) / 146.6 tok/s —
bench_openai.py 256 tok (fibonacci / chat, T=1 med) — 143.9 (163.5 pk) / 115.6 tok/s —
bench_openai.py 64 tok (fibonacci / chat, T=0 med) 112.6 / 106.9 tok/s 159.3 / 159.5 tok/s +41.5% / +49.2%
bench_concurrent.py 16 Distinct Prompts (T=0, S=1/2/4/8) — 202.0 / 246.1 / 266.2 / 252.1 tok/s steady 0 unequal
bench_concurrent.py Standard (S=2 / 4 / 8 / 32, T=0) 133.6 / 150.7 / 172.6 / 145.0 tok/s 195.7 / 223.2 / 237.2 / 215.0 tok/s steady +37.4% - +48.3%
bench_fill.py 16K & 32K Prefill + 512-tok Active Chat — gap_p95 = 197.0 - 199.8 ms (exact: true) Unstalled decode

Verification

  • 0-ULP Chunk & Speculative Exactness:
    • tools/bench_cache.py --require-cold across 2,048, 8,192, 32,768, 65,536, 131,072, and 262,079 (+ 64 = 262,143 / 262,144 full window): all 6 cells exited 0 with "qualified": true, cached_tokens == 0, and equal_first_tokens: true.
    • tools/bench_fill.py at 16,384 and 32,768 long prompt tokens (--reply 512): both exited 0 with exact: true and cold: true in both reply_first and long_first orders.
    • tools/bench_concurrent.py --alone --serial: all 8 cells on --prompts tools/bench_prompts.json (16 distinct prompts) and all 24 cells on code/chat (1 .. 32 streams) passed with failed = 0, alone_unequal = 0, and serial_unequal = 0.
    • xpu-flashnext raw CLI across 512 .. 262,080 + 64 = 262,144: all 11 depths verified MTP == serial: true.
    • 3-rep interleaved unprofiled A/B (c5944f1 vs d8c10bb on identical token IDs): matched all output SHAs (2K: d94f99a2702e, 32K: 6becd29ac6f1, 128K: bd8cd97f415c, 256K: 85c3b0c0a73c), speeding 262,079 prefill 275.956 s -> 222.261 s (+24.2%).
    • tools/bench_warm_turns.py (--prompt-cache-gib 1): restored 4,123 / 4,157 continuation tokens with exact first/continuation ID and output equality.
    • Cross-model regression (xpu-qwen27, Qwen3.8-27B 2,048 tokens): 1,970 tok/s prefill, 32.8 tok/s decode, exact output tokens.
  • XPU Kernel Contract & Host Contributor Checks:
    • zig build -Dxpu-contract=true xpu-kernel-contract-limits xpu-contract-run -Docloc=ocloc -Dxpu-device=bmg:
      SUMMARY bmg-g31 0xe223 9 kernels: 9 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems; gates 5689 ms, limits 1 ms
      
    • zig build test-flashnext-xpu-host test-qwen27-prompt-tail-xpu-host test-qwen27-config-xpu-host test-fp64-gdn-xpu-host test-draft-xpu-host test-slide-xpu-host test-xpu-refusal-host: 89/89 build steps succeeded; 12/12 tests passed.
    • zig fmt --check, git diff --check, ocloc -device bmg (0 spills), and python3 tools/pr_check.py --base origin/main --pr 3603 (0 errors, 1 advisory Unreleased CHANGELOG warning; lean 221 vs 221, 0 new).

@supernovae

Copy link
Copy Markdown
Contributor Author

/atc depends 3587

@supernovae

supernovae commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Attached the full TP=4 deep benchmark run up to the full 256k (262,144) context window using tools/bench_cache.py, tools/bench_openai.py, tools/bench_fill.py, tools/bench_concurrent.py (including --prompts tools/bench_prompts.json), tools/bench_warm_turns.py, and xpu-flashnext (c5944f1) to Gate Issue #3583: #3583 (comment)

@supernovae

Copy link
Copy Markdown
Contributor Author

Amended xpu-flashnext-perf to d8c10bb with 16x64 query-blocked SLM reuse in fn_qsa_scores (1.90x at 256k) and zero-spill [32x64] KERNEL(256) + active-subgroup masked MoE (fn_moe_up_dpas / fn_moe_down_dpas), and updated PR description + tools/pr_check.py / xpu-contract-run receipts.

Full updated tools/bench_*.py + xpu-flashnext report up to 256k (262,144) context posted on Gate Issue #3583: #3583 (comment)

@supernovae

supernovae commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Restacked onto updated #3587 (cdc1c7799, head now a168cb043) and routed XPU_CHUNK and XPU_CHUNK_SOLO (alongside the other XPU_* knobs) through platform/environment.zig (sys.environment) with host validation tests in environment_test.zig and xpu_tp_refusal_test.zig.

Re-verified on the rebased head:

  • python3 tools/pr_check.py --base origin/main --pr 3603: 0 error(s) (lean 221 vs 221, 0 new)
  • zig build test-environment-host test-xpu-refusal-host test-flashnext-xpu-host test-qwen27-config-xpu-host test-qwen27-prompt-tail-xpu-host test-fp64-gdn-xpu-host test-draft-xpu-host test-slide-xpu-host test-kernel-contract -Dxpu-contract=true xpu-kernel-contract-limits xpu-contract-run xpu-native xpu-flashnext xpu-qwen27 xpu-tp-bench -Doptimize=ReleaseFast: 145/145 steps succeeded, 255/255 tests passed (SUMMARY bmg-g31 0xe223 18 kernels: 18 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems)
  • Live refusal & TP4 checks (xpu-flashnext & xpu-qwen27, mixed_2048.ids): invalid XPU_CHUNK=0 / XPU_CHUNK_SOLO=4096 fail before device init (InvalidEnvironment), xpu-flashnext matches serial tokens (equal to serial: true, 80.2 tok/s MTP), and xpu-qwen27 shows zero regression (1494 tok/s prompt, 69.8 tok/s decode).

@supernovae
supernovae marked this pull request as ready for review November 18, 2026 02:06
@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thank you @supernovae. XPU_CHUNK and XPU_CHUNK_SOLO now go through the startup parser with bounds and invalid-input tests, and an explicit --tp 1 still stands after the restack. Your 18-kernel contract summary and the exactness cells up to the full 256k window cover the device side. The restack and the CHANGELOG line are ours. This is ready to land after #3587.

One thing on our side: zig-windows is red at this head, in the CUDA host test step. We're checking whether that comes from this change or from the Windows runner, and will say here if anything is needed from you.

  • Synthena

@ashhart

ashhart commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Thanks @supernovae. To get this moving, we rebased this onto the finished #3587 ourselves, keeping your commits as they were. It carries the Windows test guard from #3586, and with it the Windows build compiles; nothing else changed. It is in the landing queue now; nothing is needed from you.

  • Synthena

@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

I traced the red Windows benchmark client check at b04951bc to test_a_healthy_server_proves_both. It returned two equal replies but failed because the fake server observed no overlap between their decode windows. Windows job log

I trial-merged Ash's fake-stream fixture fix #4260 (fc392f46) into 46c6ee22. The sole conflict was in the changelog and I kept both entries. On macOS, cd tools/tests && python3 -m unittest -v test_bench_fake_stream_pair test_bench_served_evidence then passed 10/10. This covers the targeted fixture; the Windows check needs the resolved train to run again.

A trial merge of the #3603 public head against main reported 16 conflicts. The same 16 paths conflicted when paired with #4260, with no additional path from the fixture change.

I reran checks after the rebase to a2320fea3. It merges cleanly into dc71af9d2. On M5 Max, zig build test-flashnext-xpu-host test-qwen27-config-xpu-host test-qwen27-prompt-tail-xpu-host test-xpu-refusal-host -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3 --summary all passed 14/14 on the published head. The #4260 test module is absent on that head and present in the merged tree. In the merged tree, cd tools/tests && python3 -m unittest -v test_bench_fake_stream_pair test_bench_served_evidence passed 10/10. The new Windows benchmark client and Zig Windows jobs both completed successfully on that head.

The full No GPU workflow has now completed successfully on a2320fea3. This is the source PR head; the separate combined #4279 train has its own checks.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart merged commit ecc80b9 into ashhart:main Nov 21, 2026
1 of 11 checks passed
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thank you @supernovae. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@supernovae
supernovae deleted the xpu-flashnext-perf branch November 22, 2026 21:43
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.

3 participants