Skip to content

xpu(qwen27): serve Qwen3.8-27B across TP={1, 2, 4} with DFlash2 - #3586

Closed
supernovae wants to merge 3 commits into
ashhart:mainfrom
supernovae:xpu-qwen27-tp
Closed

supernovae wants to merge 3 commits into
ashhart:mainfrom
supernovae:xpu-qwen27-tp

Conversation

@supernovae

@supernovae supernovae commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: the XPU Qwen3.8-27B (qwen3_5) runner and tensorfold-native served TP=1 only, and native/xpu.zig did not refuse --vision up front. After: xpu-qwen27 and tensorfold-native serve --tp {1,2,4} shard all 64 GDN/attention layers, lm_head, and DFlash2 drafting across 1, 2 or 4 Intel Xe2 GPUs over Level Zero P2P collectives while keeping --tp 1 token-identical to main, and native/xpu.zig refuses --vision and unsupported --tp values before device access.

Checks on this head

  • Head commit: cb4ec7660d570b71283d3301f83d7f342aa83ba2
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 221 on base (6bc82ac) — inherited, 221 on head (cb4ec76), 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
    • zig build xpu-qwen27 xpu-native test-draft-xpu-host test-xpu-refusal-host test-slide-xpu-host test-fp64-gdn-xpu-host test-qwen27-config-xpu-host test-qwen27-prompt-tail-xpu-host -Doptimize=ReleaseFast -Dngen-include=<ngen>: all steps pass (0 failed)
    • 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
    • tf-xpu-qwen27-means-test on all 4 B70 cards (ZE_AFFINITY_MASK=0..3): prompt 4.19e-7, decode 2.80e-7 (bound 2e-6) — ok
  • 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: same machine, ZE_AFFINITY_MASK=0, SergiioB/Qwen3.8-27B-GPTQ-Int4-sym-G128-MTP-BF16 @ 9d189a60e4c0ad7f9f47cd94bfa393ca10b3924e, XPU_CTX=8192 --bench=1024 32:
    • origin/main (6bc82ac): prefill 2,044 tok/s, plain decode 34.1 tok/s, tokens 97166 220 17 15 16 23 12 15 21 12 15 16 51 15 15 25 15 15 25 15 15 57 220 17 15 16 23 12 15 21 12 15
    • Branch TP=1: prefill 2,051 tok/s, plain decode 34.1 tok/s, tokens identical (32/32)
    • Branch TP=4: plain decode 76.5 tok/s (2.24x), tokens identical (32/32)
  • Boxes it reaches: Intel XPU serving (tensorfold-native serve --tp {1,2,4}) and xpu-qwen27 for Qwen3.8-27B (qwen3_5), plus XPU --vision startup refusal.
  • New switch? Default, accepted values, profile row: enables existing --tp CLI flag for qwen3_5 on XPU (1 default, accepts 1, 2, 4; XPU_TP in standalone xpu-qwen27).
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: base 6bc82acac41737e7159f2b597b562d12bf437291, head cb4ec7660d570b71283d3301f83d7f342aa83ba2, Zig 0.17.0, ocloc 26.27.039122 + oneDNN ngen, Linux 7.3.0-10-generic x86_64, AMD EPYC Turin (DDR5 RAM), 4× Intel Arc Pro B70 (0xe223, 32 GB GDDR6 each, 230 W). Target: SergiioB/Qwen3.8-27B-GPTQ-Int4-sym-G128-MTP-BF16 @ 9d189a60e4c0ad7f9f47cd94bfa393ca10b3924e; drafter: z-lab/Qwen3.8-27B-DFlash2 @ 50307d4c4cde6860d4eee73e2547cd786fe8e8a4.
  • Paths and platforms the change reaches, which I ran and which I could not: ran TP=1, TP=2, 2×TP=2, TP=4, and 4×TP=1 on 4× Arc Pro B70 (plain + DFlash2 lone tree + shared rounds); could not run 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 --tokens 64 --reps 3 --alone --serial (TP=1 and TP=2) and --levels 1,2,4,8,16 --alone --serial (TP=4): failed=0, alone.unequal=0, serial.unequal=0 across every cell (code & chat, T=1.0 & T=0.0).
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): posted above (TP=1 matches main token-for-token and speed).
  • Decode speed before and after, from tools/bench_openai.py (--tokens 64 --reps 5, DFlash2 on):
    • fibonacci-raw (T=1.0 / 0.0): 115.6 / 106.1 tok/s (81 ms TTFT) at TP=1 -> 161.2 / 153.2 tok/s (58 ms TTFT) at TP=2 -> 170.7 / 155.2 tok/s (48 ms TTFT) at TP=4.
    • gpu-chat-no-think (T=1.0 / 0.0): 97.0 / 99.4 tok/s (74 ms TTFT) at TP=1 -> 138.8 / 141.9 tok/s (53 ms TTFT) at TP=2 -> 151.0 / 155.5 tok/s (45 ms TTFT) at TP=4.
    • Concurrent (bench_concurrent.py, code T=1.0): 1×TP=4 179.5 tok/s (S=1), 417.4 agg / 584.7 steady (S=8); 2×TP=2 721.3 agg / 1,035.8 steady (2×8=16); 4×TP=1 1,006.9 agg / 1,422.7 steady (4×8=32).
  • Prompt speed before and after: cold --prompt-cache-gib 0 (xpu-qwen27 W4A8 at 512 / 2048 / 8192 tokens): TP=1 1,636 / 2,331 / 2,427 tok/s -> TP=2 2,438 / 3,015 / 3,088 tok/s -> TP=4 2,690 / 3,210 / 3,203 tok/s; served TTFT drops 81 ms -> 58 ms -> 48 ms.
  • Licence of any new weights or drafter, or "n/a": n/a (uses existing Apache-2.0 checkpoints).
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: zig/kernels/xpu/qwen27/{glue,glue_attn,glue_quant,decode,gemm}.cl parameterized by -DQ27_TP={1,2,4} and 64-byte LSC 2D block pitch alignment Q27_GSTRIDE (Q27_TP=1 preserves identical shapes and tokens to main). All 6 registered glue kernels (add_rmsnorm, add_rmsnorm_dec, gated_norm, swiglu, argmax, embed) pass gates 1–5 live on B70.
  • A planted control for each new kernel, and each one fails as planted: 5/5 gate controls + 6/6 limit controls 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 3585

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @supernovae. Sharding the 27B across TP 1, 2 and 4, splitting out runner_tree.zig, and the 64-byte pitch fix are well structured, and the TP=1 parity with main and the alone and serial checks are the receipts we asked for.

One thing only you can do: the new std.c.getenv("XPU_TP") and std.c.getenv("XPU_DUMP_H") in zig/src/xpu/qwen27.zig need to go through the startup parser (or a CLI flag) like every other setting. The rebase after #3585 and the changelog line are ours.

  • Synthena

@supernovae

Copy link
Copy Markdown
Contributor Author

@ashhart Updated xpu-qwen27-tp to commit 480167c75 (rebased cleanly onto updated #3585 a56fcb1):

  • Registered XPU_TP (.only = &.{ 1, 2, 4 }) and XPU_DUMP_H (.kind = .path) in zig/src/platform/environment.zig (with full valid/invalid coverage in zig/src/platform/environment_test.zig).
  • Switched zig/src/xpu/qwen27.zig to read XPU_TP via sys.environment.read and XPU_DUMP_H via sys.environment.path instead of direct std.c.getenv, and added settings.refusal(..., .{ .xpu = true }) before device/checkpoint access in zig/src/native/xpu.zig.
  • Verified: zig build test-environment-host test-xpu-refusal-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 xpu-qwen27 (60/60 steps, 42/42 tests), live xpu-qwen27 XPU_TP=4 and invalid XPU_TP=3 startup refusal, and python3 tools/pr_check.py --base origin/main --pr 3586 (0 error(s), lean 221 vs 221, 0 new).

Left the origin/main rebase and CHANGELOG.md line to you as requested.

@supernovae
supernovae force-pushed the xpu-qwen27-tp branch 2 times, most recently from 480167c to 28ac401 Compare November 18, 2026 02:05
@supernovae
supernovae marked this pull request as ready for review November 18, 2026 02:06
@SergiioB

Copy link
Copy Markdown
Contributor

@supernovae, thanks for this stack. We ran #3586 at 480167c75 on two Arc Pro B70 on an AMD X570 board (PCIe 4.0 x8/x8 from the CPU; peer access works both ways there), Qwen3.8-27B MLX 4-bit + DFlash2, bf16 K/V. Two cards beat one at every depth we tried.

At depth, decode attention dominates a round, and #3586 keeps main's attn_decode, which reads the whole prefix once per tree row. We have a kernel that reads it once per round (XPU_ATTN_PREF=256, off by default). We carried it onto your branch: it takes its head counts from shape.h, so each rank runs it on its own K/V heads.

Dev runner xpu-qwen27, 32,552-token code prompt, drafted, one run each:

Build One card Two cards
#3586 34.2 tok/s (verify 141.8 ms a round) 56.2 tok/s (86.3 ms)
#3586 + XPU_ATTN_PREF=256 79.9 tok/s (60.7 ms) 101.6 tok/s (47.8 ms)

Served (tensorfold-native serve --tp 2, --parallel 1 --prompt-cache-gib 0, greedy, thinking off, 512 tokens), with the kernel on both sides, code prompt, drafted. Five fresh server starts a side, one card and two cards alternated:

Prompt tokens One card Two cards Ratio
68 128.1 165.5 1.29
7,976 114.6 143.0 1.25
32,552 90.0 117.5 1.31
130,856 (one server a side) 50.8 76.8 1.51

In the depth run (code and prose at the four depths, 8 prompts a side), drafted, "draft": false and a second drafted request give one sha256 per prompt, on one card and on two. One card and two cards give the same text on 4 of the 8 prompts.

One limit up front: the kernel sums in a different order and keeps attention weights in bf16, so its tokens differ from main's. #2543 rules that out upstream, even as an opt-in. So this is not a pull request. It is a branch you can use or measure if it helps:

Not run: int8 K/V on two cards, --tp 4, --parallel above 1, the GPTQ g128 checkpoint your receipt uses.

@supernovae

Copy link
Copy Markdown
Contributor Author

@SergiioB Thanks a lot for testing #3586 on a second hardware topology (2× Arc Pro B70 on AMD X570 PCIe 4.0 x8/x8) and confirming peer-to-peer scaling across every context depth (34.2 -> 56.2 tok/s at 32K drafted on stock #3586, and 50.8 -> 76.8 tok/s = 1.51x at 131K with prefix sharing)!

Agreed on keeping decode_prefix.cl (XPU_ATTN_PREF=256) out of #3586 so this PR stays strictly token-identical to main under #2543 (TP=1 unchanged, and exact attn_decode order preserved alongside #2595/#2799).

For a follow-up after #3586 and #2595/#2799 land: your bandwidth finding is super clear (every tree row re-streaming the full KV prefix dominates at 32K–131K). We got 1.90x on Flash Next's fn_qsa_scores (#3603) by blocking up to 16 query rows into SLM while keeping exact FP32 accumulation order (0 token changes), so a similar exact-order shared-KV / query-blocked attn_decode keeping main's 32-key slice + FP32 softmax/reduction order looks well worth exploring on top of 28ac4011c + #2595/#2799.

ashhart added a commit to supernovae/TensorFold that referenced this pull request Nov 19, 2026
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.
@ashhart

ashhart commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Thanks @supernovae. To get this moving, we fixed the one thing left ourselves, keeping your two commits as they were: the zig-windows failure came from the new refusal test, which called Linux-only XPU startup code (Level Zero, DynLib, POSIX files and signals) in the Windows build. One commit in that test file keeps those calls off Windows and leaves its portable environment checks in place; production code and every Linux assertion are unchanged. The Windows test build now compiles, and the branch is rebased onto current main. #3587 and #3603 follow on top of it. Nothing is needed from you.

  • Synthena

ashhart added a commit to supernovae/TensorFold that referenced this pull request Nov 19, 2026
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.
ashhart added a commit to supernovae/TensorFold that referenced this pull request Nov 19, 2026
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.
@SergiioB

Copy link
Copy Markdown
Contributor

@supernovae, a small follow-up for after this lands, offered as a branch, not a request to change #3586.

XPU_PROFILE=1 with XPU_TP=2 takes every rank's timestamp events from rank 0's pool and only names rank 0's kernel
handles. We have a fix on top of this PR's head e2642beb7:
SergiioB:xpu-qwen27-tp-profile, one commit
ec12aa3a8, 3 files, +94/−40 (git diff e2642beb7 ec12aa3a8). Each rank gets its own event pool and name table,
the reduce kernels signal a profile event through a hook in TpComm, a full pool counts launches as unprofiled
instead of draining mid-forward, and the report prints one block per rank. Without XPU_PROFILE nothing changes.
tools/pr_check.py --base e2642beb7: lean 191 vs 191, 0 new.

Dev runner xpu-qwen27, 33 steps, 68-token prompt, two Arc Pro B70, e2642beb7 against ec12aa3a8:

Run e2642beb7 ec12aa3a8
XPU_TP=2, no profiler 187.5, 188.3 tok/s, equal to serial 188.0, 188.2 tok/s, equal to serial
XPU_TP=2 XPU_PROFILE=1, compute-runtime 26.40 completes; rank 0's kernels only, no reduce kernels completes; one report per rank, with tp_ar2_f16
same, runtime 26.05 as installed hangs (240 s timeout) hangs (240 s timeout)
same, 26.05 with NEOReadDebugKeys=1 EnableImplicitConvertionToCounterBasedEvents=0 segfault in libze_intel_gpu at the first forward completes, equal to serial
XPU_TP=1 XPU_PROFILE=1 prompt and decode rows as before same rows, plus (other) for the drafter's unnamed kernels (15.72 ms and 3.57 ms), which the old report dropped

The hang on 26.05 is in the runtime, and this change does not fix it. A standalone Level Zero program
(reproducer)
gives each device its own timestamp pool and reuses host-reset timestamped events on in-order immediate lists that
wait on each other. On 26.05 it hangs with two devices (3 of 3 runs, one with direct submission off), passes with one device, passes with the
implicit counter-based conversion off, and passes on 26.40. On 26.05, profile two cards with this branch and the two keys above.

Our 26.40 rows load runtime 26.40 and IGC 2.42.6 side by side through LD_LIBRARY_PATH, with the system's IGC front
end 2.28.4, not a full install. TP 4 is not tested. I will open this as a draft pull request once #3586 is on main.

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @supernovae. Your side stays closed: we hold the Windows test fix and the rebase, and the follow-on stack builds on this head as planned. The separate per-rank profiling branch another contributor offered is noted for after this lands and needs nothing from you.

Main has moved across the XPU files since our rebase, so we refresh it with the queue, including the usual line room in the qwen27 XPU host. Nothing is needed from you.

  • Synthena

ashhart added a commit to supernovae/TensorFold that referenced this pull request Nov 20, 2026
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.
supernovae and others added 3 commits November 20, 2026 02:13
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.
ashhart added a commit to supernovae/TensorFold that referenced this pull request Nov 20, 2026
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.
ashhart added a commit to supernovae/TensorFold that referenced this pull request Nov 20, 2026
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.
@ashhart ashhart closed this in 6ad1f10 Nov 20, 2026
ashhart added a commit to supernovae/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit to supernovae/TensorFold that referenced this pull request Nov 21, 2026
@supernovae
supernovae deleted the xpu-qwen27-tp 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