Repository navigation
XPU: gdn_out's scale bookkeeping in cheaper exact forms (Qwen3.8-27B on Arc Pro B70, -22.6% kernel time, bytes equal) - #2921
Conversation
|
Thanks @dinadur. This is careful work, and the "How far the equality argument goes" section saved us a lot of checking. We read all three edits against main and agree they're exact:
The A-B-B-A kernel times settle the speed. Two runs and it's ready:
Answers to your questions:
CI is waiting on our approval, which we'll give. Main is frozen for today's release. Once the two comparisons are posted, mark the PR ready and we'll queue it to land after the release.
|
|
Thanks for the read-through. Results for the two comparisons, from two windows today on the same B70 (head The 1.
2. The same comparison with the fallback forced: identical. Build: this head with line 371 changed to
Timing in the first window ( Planted control. A deliberately wrong kernel (high planes only) through the same comparison on the 8,192-token prompt: Also run, though you said they are not needed. Upstream's own
CI on this head: 8 jobs passed; Still not run: Measurements are from my B70; this comment was prepared with an AI coding agent working under my direction. |
|
Thanks @dinadur, that settles both. CI is green and it merges cleanly with main, so we've marked the PR ready for you and queued it to land.
|
…e, reads row exponents from the bits, and takes e^la once a row The prompt GDN's output kernel keeps every product and its order. The two rescales after the products multiply by 2^n when every lane's n is in [-124, 127], where ldexp is that one product, and run ldexp otherwise. The row exponent is the float's exponent field, equal to 14 - ilogb(m) under the same clamp for every float. e^la is computed once a row in the first half. Refs ashhart#2859
bf0cc2e to
fdd6994
Compare
|
Thank you @dinadur. 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. |
Figures and scope corrected to the PRs (#2948, #2863, #2934, #2933, #2921, #2906, #2878, #2892, #2851, #2728, #3072, #2915, #2864, #2854 and others), promises of later work removed (#2903, #2875, #1630, #1720), #3074 and #3047/#3046 said as their PRs scope them, the duplicate #2861, #2585, #2321 and #2719 entries and two copies of released 1.2.5 lines removed, #1953's line named for its PR, and a line for #3255. Released sections unchanged.
|
Thanks @dinadur! This is in TensorFold 1.2.8, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.8
|
|
Thanks @dinadur! This is in TensorFold 1.2.10, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.10
|
What this changes
gdn_out(the prompt GDN's output kernel on XPU) computes the same bytes with less work around its products. Before: 736 ms of GPU time on a 32,768-token prompt on an Arc Pro B70. After: 570 ms. No product, operand or summation order changes, andgdn_prepandgdn_statecompile to the same instructions as on main.Three edits, all inside
gdn_out:ldexpis one multiply.ldexp(x, n)with a per-lanencompiles (IGC 2.40.13) tox * 2^n * m0 * m1behind three range selects, about 11 SIMD16 instructions an element, 128 elements a subgroup. Fornin [-124, 127] bothm0andm1are 1.0, so the result is the single productx * 2^n. The kernel now tests once a subgroup that every lane'snis in that range and, if so, multiplies by the power of two built from the exponent bits; otherwise it runs the originalldexploops unchanged.ilogb.clamp(141 - ((bits >> 23) & 255), -100, 100)equalsclamp(14 - ilogb(m), -100, 100)for every positive float: normals by definition, subnormals clamp to 100 either way, infinity to -100 either way.exp(la[t])is computed once a row in the first half and read back from local memory in the second, instead of in every subgroup.gdn_outpart of it;gdn_prepandgdn_stateare untouched, see "What remains").atc overlap --json: not run yet; see "Not run, and why".Checks on this head
bf0cc2e273f145219a32b0ca0b45e70f1d632bd4, on main93a2e93ecebff8aa52b88e58c5dd222516e69c5f. Every number below was measured on that base with this file's exact bytes (kernel source sha256b21179948be2888350994aab6cc27263ce0694ae6e90f1914c0e86b540f4842f), built before the commit existed.python3 tools/zig/lean_check.py, on the base and on this head: 386 and 386, 0 new (lean_new.py)../zig-out/bin/tf-xpu-contract-run --device 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, exit 0, the same line on main../zig-out/bin/tf-xpu-qwen27-means-test:prompt 4.19e-7, decode 2.80e-7 (bound 2e-6), exit 0, the same on main../zig-out/bin/tf-xpu-qwen27-seam-test MODEL: cut at 64 and cut at 1024 each give 0 of 248,320 differing logits, exit 0, the same on main.XPU_FP64_REF=1 xpu-qwen27 MODEL IDS 8on 2,048 real tokens: all 197 table lines equal main's.git diff --check: clean.fmt,pytest,zig,zig-windows,zig-macos-dev-tools,release-paths, bothbenchmark-clients);host-nightly-linuxandhost-nightly-macoswere skipped.zig build test test-golden: not run. The only machine here is a shared inference host, and an XPU unit test in the tree opens a card with no device mask; I did not run host suites outside a quiesced window.atc: not installed and no claim made through it; the review said none is needed, XPU (B70): the 1.1.0 prompt GDN costs about 5% of 32K prefill on Qwen3.8-27B, and the README table predates it #2859 being the invitation.Receipt
Main against branch: cells and numbers, or why they can't be run: raw runner,
XPU_CTX=33024 XPU_PROFILE=1 xpu-qwen27 MODEL --bench=32768 32, a fresh process each run, two A-B-B-A rounds after warm-up runs brought the card to 80 °C.gdn_outmsgdn_prepmsgdn_statemsgdn_out: 736.3 to 570.2 ms, 166 ms (22.6%) lower in every pair. Whole prompt: 20.844 to 20.705 s, 0.67%; in the second round, with the card fully hot, 0.47%. The card is power-limited during a prompt (PL2 at 230 W), and the other kernels read slightly higher whengdn_outgets lighter, so the wall-clock gain is smaller than the kernel's.Boxes it reaches: Intel XPU only, the Qwen3.8-27B prompt path (
gdn_chunk.cl).New switch? Default, accepted values, profile row: none.
Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: main
93a2e93e(1.2.7); Zig 0.17.0;oclocand compute runtime 26.31.39395.13 (IGC 2.40.13), Level Zero 1.32.0, nGEN headers from oneDNN55e24fbf; Arc Pro B70 (8086:e223) capped at 230 W, Core Ultra 7 270K Plus, 61 GiB RAM, Ubuntu 26.04, kernel 7.0.0-42,xe;SergiioB/Qwen3.8-27B-GPTQ-Int4-sym-G128-MTP-BF16at9d189a60. A second B70 in the host kept serving another model; everything else on the test card was stopped. The test card had taken one engine reset earlier the same day and was not rebooted before these runs: a diagnostic variant of this kernel, from this same work, fed fp16 bits to a bf16 product to time it, produced garbage values, and the run ended in an xe engine memory CAT error. Clock state: every prompt sample in all eight runs is PL2-throttled at 2,083 to 2,250 MHz (per-run means 2,162 to 2,208 for both builds); the sampling is one reading every 5 s, too sparse to bound the gap between arms below 1%.Paths and platforms the change reaches, which I ran and which I could not: the XPU prompt GDN for Qwen3.8-27B, run on one B70 through the raw runner and, in the follow-up, through
servewithout a drafter at 1 and 2 streams. Not run: drafted decode, any other Intel GPU.Exactness, from
tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: in the follow-up,bench_concurrent.py --tokens 64 --levels 1,2 --alone --serialon main and on the branch: every cell equal to its alone and serial outputs, 0 unequal, 0 failed."draft": falsecomparison: not run (no drafter was loaded). Bytes:XPU_DUMP_H(every row's final normed hidden state, the prompt's rows and the 7 decoded ones) on main and on the branch.CHANGELOG.mdat93a2e93e(checkpoint tokenizer, no special tokens)a80d58299b1e2f2536c427cfb561af56de9c6958270de09bf3ec12858b3a7fee--bench=32768bc29a385e8573e0de0121d113e972a200b43a244ddee2264116718b2ff1da07bd430ed6a9d83e98dc6492bcad653f399b8134fd71afdd2fd344560e2eff32d12The comparison XPU (B70): the 1.1.0 prompt GDN costs about 5% of 32K prefill on Qwen3.8-27B, and the README table predates it #2859 named, run in the follow-up (comment):
Yafter everygdn_outlaunch (48 GDN layers × 32 chunks) on the 32KCHANGELOG.mdprompt, from a local host hook that is not in this pull request. Main and the branch give identical files: 19,327,352,832 bytes, sha2561c1d63886151939587485057b92bec16b640e39d61baaf98c28b691aece48018. With the fallback forced (one = 0at line 371, local build only)Yand the final hidden states on the same prompt are identical to main's too. A deliberately wrong kernel through the same comparison on the 8,192-token prompt differs in both.The 8 greedy tokens after each prompt are equal too.
gdn_prepandgdn_state: IGC's assembly for both is the same as main's apart from the two program-hash marker moves.Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): above.
Decode speed before and after, from
tools/bench_openai.py:--tokens 256 --reps 3 --temperatures 0throughserve, two fresh servers a build: 33.4 tok/s median for main and for the branch.gdn_outruns only on prompt chunks, and decode GPU time is 1,246.2 to 1,246.6 ms for 31 tokens in all eight runs above.Prompt speed before and after: raw runner above (32K). Cold
ttft_sfromtools/bench_cache.py --require-coldthroughserve --parallel 4 --context 66560 --prompt-cache-gib 0, no drafter, two fresh servers a build (the server reported 3 streams of 66,560 tokens for both builds), at 2,048 / 8,192 / 32,768 / 65,536 tokens: main 1.174, 1.178 / 4.520, 4.525 / 20.911, 20.940 / 49.283, 49.278 s; branch 1.159, 1.162 / 4.492, 4.492 / 20.806, 20.806 / 49.057, 49.032 s. Every row cold with 0 cached tokens and qualified;token_sha256equal between builds at every size.Licence of any new weights or drafter, or "n/a": n/a.
Kernel contract, only when a GPU kernel is new or changed
gdn_outis changed in place; on main none of the three prompt-GDN kernels is registered (the nine XPU registrations are glue kernels). The review said registration is not needed for this pull request.SUMMARYline and exit status: XPU, 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.How far the equality argument goes
ldexpby its own expansion (the dumped LLVM IR showsx * 2^n * m0 * m1, and multiplying by 1.0 twice changes nothing). Against any correctldexpit is exact wheneverx * 2^nis a normal float or zero, because that product is then exactly representable. For a subnormal result the two could differ on a compiler or device that treats subnormals differently inldexpand in a multiply; that was not probed here. Outside [-124, 127] the original code runs.one = 0givesYand final hidden states identical to main's on the 32K prompt. I did not measure how often a subgroup takes the one-multiply path on these prompts.expof the same scalar giving the same bits in the first half as in the second. The byte comparisons test that; I have no proof of it.What remains for #2859
gdn_statehas the same per-laneldexppattern (32 an 8-row block a chunk) and its row split is computed twice a chunk;gdn_prepis untouched. Neither is in this pull request.gdn_outto 474 ms. This branch is 96 ms above that, not all of it rescale work. Removing the row-maximum analysis took 40 ms; the low-plane products and reads are 116 ms.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Concurrent equals alone and serial at 1 and 2 streams, see Receipt. Drafted and resumed: not run.)--drafter, no slower than without it, greedy and sampled. (Raw runner: prompt 0.5 to 0.7% faster. Throughservewithout a drafter: coldttft_s0.5 to 1.3% lower at 2k to 64k, decode within 0.2% at 1 and 2 streams. The server admitted 3 streams; 3 streams,--drafterand sampled: not run.)The
Ycomparisons, the forced fallback and theservenumbers above were measured after review and are reported in full in this comment; they were made after a reboot of the host, in a boot with no xe fault lines. This description and the change were prepared with an AI coding agent working on my machine under my direction; the measurements are from my B70.🤖 Generated with Claude Code