Skip to content

xpu(flashnext): serve Qwen3.8 Flash Next (qwen4_exp) at TP={1, 2, 4} with host-RAM PLE and MTP - #3587

Merged
ashhart merged 7 commits into
ashhart:mainfrom
supernovae:xpu-flashnext-tp
Nov 20, 2026
Merged

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

Conversation

@supernovae

Copy link
Copy Markdown
Contributor

What this changes

Before: the XPU backend refused Qwen3.8 Flash Next (qwen4_exp). After: xpu-flashnext and tensorfold-native serve run Qwen3.8 Flash Next (mlx-q4g32) across TP={1, 2, 4} on Intel Xe2 GPUs over Level Zero P2P collectives (19.79 GiB VRAM/GPU at 16k context, 23.81 GiB/GPU at the full 262,144 native window on 4× Arc Pro B70) with host-RAM mmap PLE 4-gram tables (29.80 GiB), Layer-48 MTP speculation, shared-round verifyMulti up to 32 streams, and prompt snapshot caching.

Checks on this head

  • Head commit: 9d930a92a01827423647c3049a39c11f3001dfc9
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 221 on base (6bc82ac) — inherited, 221 on head (9d930a9), 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check build.zig zig & git diff --check: pass
    • python3 tools/pr_check.py --base origin/main: 0 errors
    • python3 -m unittest discover -s tools/zig -p build_options_test.py (5/5) & host_tests_test.py (13/13): pass
    • zig build xpu-flashnext xpu-native test-flashnext-xpu-host test-draft-xpu-host test-xpu-refusal-host test-slide-xpu-host -Doptimize=ReleaseFast -Dngen-include=<ngen>: all steps pass (0 failed; ocloc compiles all 36 flashnext Xe2 kernels at 128 GRF/thread with 0 spills)
    • zig build -Dxpu-contract=true xpu-kernel-contract-limits xpu-contract-run: 9/9 pass, 5/5 controls red, 0 limit problems
    • umask 0022 && zig build -Dfixed-cpu test --test-timeout 20m: 696/696 steps succeeded (0 failed)
    • zig build -Dfixed-cpu test-kernel-contract test-golden test-gradient-serving test-qwen-serving-host test-server-security test-pull-security fuzz-cortheon: 62/62 steps succeeded; 317/317 tests passed
  • CI: pending on this push.
  • Not run, and why: Metal (M1–M5), CUDA (sm_*), HIP (gfx*), and Windows GPU checks (Linux 4× Intel Arc Pro B70 host only).

Receipt

  • Main against branch: main refuses qwen4_exp on XPU; existing XPU Qwen3.8-27B (TP=1) verified unchanged against main in parent slice 2 (token_sha / greedy tokens 32/32 identical, 34.1 vs 34.1 tok/s decode, 2,051 vs 2,044 tok/s prefill).
  • Boxes it reaches: Intel XPU serving (tensorfold-native serve) and standalone xpu-flashnext for qwen4_exp (mlx-q4g32), plus xpu_lane.zig sub-batch verifyShared for drafting engines implementing verifyMulti.
  • New switch? Default, accepted values, profile row: serves qwen4_exp via existing --tp {1,2,4} (defaults to 4 on 32 GB cards when --tp is unset/default so the ~79.2 GiB device weights fit across 4 cards); --vision is explicitly refused until an XPU vision tower is added.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: base 6bc82acac41737e7159f2b597b562d12bf437291, head 9d930a92a01827423647c3049a39c11f3001dfc9, Zig 0.17.0, ocloc 26.27.039122 (-device bmg), Linux 7.3.0-10-generic x86_64, AMD EPYC Turin (91 GiB DDR5 RAM), 4× Intel Arc Pro B70 (0xe223, 32 GB GDDR6 each, 230 W). Checkpoint: TensorFold/Qwen3.8-Flash-Next-MLX-4bit-MTP @ 2b170fa6309d5d1ee380b35636075fac7945f286 (105.43 GiB: 19.79 GiB VRAM/GPU at 16k ctx, 21.77 GiB/GPU at 135k ctx, 23.81 GiB/GPU at full 262,144 native ctx + 29.80 GiB PLE in host DDR5 RAM).
  • Paths and platforms the change reaches, which I ran and which I could not: ran TP=4 across 4× Arc Pro B70 from 512 through the full 262,144 (256k) native context window and 1..32 concurrent streams; could not run single-card TP=1/TP=2 full-model load (requires >80 GiB / >40 GiB VRAM per card), Metal, CUDA, HIP, or Windows GPU.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false:
    • bench_concurrent.py --levels 1,2,4,8,16,32 --tokens 64 --reps 3 --alone --serial: all 24 cells (1, 2, 4, 8, 16, 32 streams × code/chat × T=1.0/0.0) pass with failed=0, alone.unequal=0, serial.unequal=0.
    • xpu-flashnext raw context sweep across 512, 1k, 2k, 4k, 8k, 16k, 32k, 64k, 128k, 192k, and 256k (262,080 + 64 = 262,144): MTP == serial: true (0 diff) at every depth, plus XPU_VERIFY_TEST=1 (perfect & wrong drafts equal to serial: true) and 9/9 exact passkey retrieval across 132,380 served tokens.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): main does not support qwen4_exp on XPU; Qwen3.8-27B TP=1 parity is posted above.
  • Decode speed before and after, from tools/bench_openai.py (--tp 4):
    • bench_openai.py (--tokens 64 --reps 5): fibonacci-raw 110.8 tok/s (T=1.0) / 112.6 tok/s median (121.2 peak, 61 ms TTFT) (T=0.0); gpu-chat-no-think 96.5 tok/s (T=1.0) / 106.9 tok/s (95 ms TTFT) (T=0.0).
    • Served long-context novel-code pure MTP decode (LRUCache, T=0.0, no copy-draft overlap): 136.3 tok/s (<1k), 125.1 tok/s (4k), 125.7 tok/s (16k), 124.2 tok/s (64k), 113.3 tok/s (132k, passkey=True); multi-turn (MTP + context copy) reaches 214.1–253.5 tok/s from 1k to 132k.
    • Concurrent (bench_concurrent.py, T=0.0): steady decode scales 114.6 (S=1) -> 133.6 (S=2) -> 150.7 (S=4) -> 172.6–174.7 tok/s (S=8), and 143.3–145.0 tok/s (S=32) vs 69.4–71.5 tok/s plain single-stream decode.
  • Prompt speed before and after: cold prefill (TP=4, 64-row Xe2 BF16 DPAS + expert-grouped MoE, --prompt-cache-gib 0):
    • 512: 248.8 tok/s · 1k: 313.4 tok/s · 2k: 356.2 tok/s · 4k: 378.8 tok/s · 8k: 389.4 tok/s · 16k: 392.8 tok/s · 32k: 394.3 tok/s · 64k: 392.7 tok/s (166.9 s TTFT) · 128k: 385.7 tok/s (339.8 s TTFT) · 192k: 369.2 tok/s · 256k (262,080 native window): 359.3 tok/s (with prompt cache on, exact snapshot restore TTFT is 160 ms at 66k and 139 ms at 132k).
  • Licence of any new weights or drafter, or "n/a": tested against TensorFold/Qwen3.8-Flash-Next-MLX-4bit-MTP (Qwen Community License 1.0); no weights are committed to this repository.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: New family image zig/kernels/xpu/flashnext/{flashnext,fn_mixers,fn_moe_head}.cl (36 kernels for qwen4_exp, compiled at -cl-intel-128-GRF-per-thread, subgroup 16, <= 16 KiB SLM, 0 register spills; replaces none). Agreeing XPU family-kernel contract coverage is part of XPU (Arc Pro B70): Level Zero P2P tensor parallelism (TP=2, 4) for Qwen3.8-27B and Qwen3.8 Flash Next (qwen4_exp) #3583.
  • A planted control for each new kernel, and each one fails as planted: Existing XPU contract controls (5/5 gate controls + 6/6 limit controls) run and fail red as planted.
  • Each backend's SUMMARY line and exit status:
    • xpu-contract-run (exit 0): 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 5558 ms, limits 1 ms
  • Chips I could not run: Apple M1–M5, NVIDIA sm_80/86/89/120/121, AMD gfx1030/1100/1151/1201.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled

@supernovae

Copy link
Copy Markdown
Contributor Author

/atc depends 3586

@supernovae

Copy link
Copy Markdown
Contributor Author

Stacked follow-up performance PR opened at #3603 (xpu-flashnext-perf, atc depends 3603 3587): adds coalesced 16-col Intel Xe2 XMX DPAS tile kernels, adaptive 2,048 -> 64 solo prompt chunking, and confidence-stopped MTP chains (1,279 tok/s cold HTTP prefill, 159.1 tok/s single-stream decode, 236.5 tok/s concurrent steady decode).

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @supernovae. Flash Next on XPU is well split, with every file under 600 lines, and the PLE warm-up overlap and the 24/24 alone and serial checks up to 262,144 tokens are thorough.

Two things only you can do. Move the new direct std.c.getenv reads (in native/xpu_flashnext.zig, xpu_ple.zig, xpu_store.zig and the runner) to the startup parser. And resolveTp turns o.tp == 1 into 4, so an explicit --tp 1 can't be chosen; please let an explicit 1 stand. The rebase after #3585 and #3586 and the changelog line are ours.

  • Synthena

@supernovae

Copy link
Copy Markdown
Contributor Author

@ashhart Updated xpu-flashnext-tp to commit cdc1c7799 (rebased cleanly onto updated #3586 480167c):

  1. Moved all new direct std.c.getenv reads to the startup parser (zig/src/platform/environment.zig):
    • Registered XPU_CTX, XPU_MTP, XPU_MTP_DEPTH, XPU_MTP_CONF, XPU_VERIFY_TEST, XPU_FLASHNEXT_WARM, and XPU_DEVICE_ID (.base = 0 for 0x hex or decimal) under .scope = .xpu with full valid/invalid coverage in zig/src/platform/environment_test.zig.
    • Switched zig/src/native/xpu_flashnext.zig, zig/src/families/flashnext/xpu_ple.zig, zig/src/families/flashnext/xpu_store.zig, and zig/src/families/flashnext/xpu_main.zig to read/validate through @import("sys").environment.
  2. Preserved explicit --tp 1 in resolveTp (zig/src/native/xpu_flashnext.zig):
    • Removed the if (o.tp == 1) return 4; override so o.tp stands unless XPU_TP is explicitly set, and added unit coverage in zig/src/native/xpu_tp_refusal_test.zig (resolveTp(.{ .tp = 1 }) == 1, --tp 3 refusal on qwen4_exp).

Verified with zig build test-environment-host test-xpu-refusal-host test-flashnext-xpu-host test-slide-xpu-host test-draft-xpu-host xpu-flashnext xpu-native (80/80 steps, 41/41 tests), invalid env refusal (XPU_MTP=maybe), and python3 tools/pr_check.py --base origin/main --pr 3587 (0 error(s), lean 221 vs 221, 0 new).

@supernovae
supernovae force-pushed the xpu-flashnext-tp branch 2 times, most recently from cdc1c77 to de88692 Compare November 18, 2026 02:05
@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. Both asks are resolved: the new XPU_* reads now go through the startup parser with valid and invalid coverage, and resolveTp lets an explicit --tp 1 stand while still refusing 3 before device access. Your 24/24 alone and serial cells and the Qwen3.8-27B TP=1 parity cover the device side. The rebase and the CHANGELOG line are ours. This is ready to land.

One thing on our side: zig-windows is red at this head, in the 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 #3586 ourselves, keeping your commits as they were, and fixed its Windows test build the same way (one commit keeping the Linux-only XPU startup calls in the test off Windows; production code unchanged). It is in the landing queue now; nothing is needed from you.

  • Synthena

@supernovae

Copy link
Copy Markdown
Contributor Author

Sounds good! look forward to seeing this land - looking forward to benching/tuning Nemotron / LFM3 / Gemma 4 or Qwen3.8-27B long-context attention tuning on the B70.

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @supernovae. The startup-parser and explicit TP1 asks remain resolved, and this head's files match the series we already prepared with the Windows host-test guard. Nothing new is needed from you. Current main has moved again, leaving five integration conflicts for us to reconcile while preserving both sides; the accepted device receipts and their limits remain credited.

  • Synthena

ashhart and others added 7 commits November 20, 2026 15:06
Keep actual XPU startup calls behind the Windows compile-time guard: they instantiate Linux Level Zero loading, mmap and signal code. Preserve the existing environment assertions on every host and every Linux assertion unchanged.
Follow main 3c29352 and its candidate-row handoff when verify and verifyTree move to runner_tree.zig. Keep candidate harvesting on step and every verify before its existing sync. Normalize the merged environment-test table and shorten two inherited header comments to the required limit.
@ashhart
ashhart merged commit d26d5b0 into ashhart:main Nov 20, 2026
10 of 11 checks passed
@ashhart

ashhart commented Nov 20, 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.

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.

XPU (Arc Pro B70): Level Zero P2P tensor parallelism (TP=2, 4) for Qwen3.8-27B and Qwen3.8 Flash Next (qwen4_exp)

2 participants