Repository navigation
RoPE: Qwen3.8-27B on XPU from core's exact helper (#1852 batch 8; 1-ulp value changes) - #2000
Conversation
|
Device check: |
|
The Qwen4 half of this is now #2223, which has passed its host gates. This PR keeps the Qwen3.8-27B on XPU half, which needs a token A/B on an Arc GPU that we don't have, so it stays open for anyone who can run that. |
|
@Mirrdhyn, since you have Qwen3.8-27B running on an Arc Pro B70: this PR moves the XPU target's and drafter's rotary tables onto core's exact helper (15 of 32 and 18 of 64 words move by 1 ulp). Could you run main against this head on the B70, greedy and seeded, with the prompts you used on #2460? Please post the token hashes, where any reply first differs (with its margin), and drafted against undrafted. No rush.
|
|
@ashhart main (merge-base
No margins yet: the XPU backend doesn't declare logprobs (neither |
|
Thanks @Mirrdhyn, that's exactly the run we needed. Greedy is identical on all four prompts, drafted equals undrafted on both binaries, and the only differences are in seeded draws, where a 1-ulp move in the rotary table can flip a sample by design. That's enough for this change without margins, so no harness is needed for it. Logprobs on the XPU host would still be welcome as their own PR, since they'd make every later XPU comparison easier. If you take it, the usual On our side, the Qwen4 half already landed separately, so we'll cut this down to the XPU commit, fix the description, and land it.
|
dceb04b to
5b5347b
Compare
…ords (value change) Both target loaders (load.zig: load and loadGptq) and the DFlash2 drafter (drafter.zig, Drafter.init) take their inverse frequencies from xpu/rope_table.zig: rope_freq.inverseFrequencies(1e7, 64) for the target's 32 words (attn_prep: 64 rotated dims of 256), (1e7, 128) for the drafter's 64 (dprep: full 128-dim heads). Every word that moves moves by exactly 1 ulp. Target, theta 1e7 over 64: 15 of 32 differ; largest |old - new| 2.980e-8 (word 2), largest relative 1.181e-7. word 2 0x3ebaf81a -> 0x3ebaf81b word 16 0x39a5cb5f -> 0x39a5cb60 word 22 0x37812dac -> 0x37812dab word 3 0x3e61f836 -> 0x3e61f835 word 18 0x38f22ce3 -> 0x38f22ce2 word 26 0x3609cf4b -> 0x3609cf4a word 5 0x3da50957 -> 0x3da50956 word 19 0x3892587f -> 0x3892587e word 28 0x35494c56 -> 0x35494c57 word 7 0x3cf11176 -> 0x3cf11177 word 20 0x3830df51 -> 0x3830df52 word 29 0x34f3499c -> 0x34f3499d word 10 0x3bd4ca14 -> 0x3bd4ca15 word 21 0x37d5c442 -> 0x37d5c441 word 13 0x3abbd3ec -> 0x3abbd3ed Drafter, theta 1e7 over 128: 18 of 64 differ; largest |old - new| 2.980e-8 (word 4), largest relative 1.181e-7. Even words 2j equal the target's word j, old and new, so 15 are the target's above at twice the index: 4 6 10 14 20 26 32 36 38 40 42 44 52 56 58. Three odd words also move: word 25 0x3af19f03 -> 0x3af19f02 word 35 0x391bc44d -> 0x391bc44e word 39 0x3863872d -> 0x3863872c Why the words differ: - Formula order: the loaders computed f32(1e7^(-i / 32)), a negative exponent with no reciprocal; transformers and rope_freq compute 1 / 1e7^(2i / d). - Precision: both old forms kept everything in f64 and rounded to fp32 once (the drafter's f32(1 / 1e7^(2i / 128)) took its reciprocal in f64). transformers rounds 1e7^e to fp32, then takes an fp32 reciprocal: two roundings. Every moved word is a case where those two roundings land 1 ulp from the single one. On all 18 moved words the old word is the nearer one to the exact 1e7^(-2i / d) (checked in 60-digit decimal). So this is a move to transformers' bits, not an accuracy fix. - Theta and exponent handling contribute nothing: 1e7 is exact in fp32 and f64, and 2i / 64 and 2i / 128 are exact in both, so old and new raise the same base to the same exponent. Test (zig build test, through the XPU host tests): rope_table.zig prints the old and new tables side by side with each table's largest absolute and relative difference. The replaced expressions live only in the tests, as references. The target's words are pinned to the transformers 5.22.1 literals that rope_freq's own test holds for 1e7/64. The drafter's are pinned to new 1e7/128 literals, each step correctly rounded in 60-digit decimal; their even words are the 1e7/64 transformers words, and their odd words are not yet checked against torch. The tests also assert exactly the moved indices and at most 1 ulp. Not run on an XPU. Before landing it needs a token A/B of old and new xpu-qwen27 builds on the same ids, and drafted == serial on the new build (XPU_VERIFY_TEST, XPU_DRAFTER with XPU_TREE=15, XPU_MULTI_TEST). Refs #1852.
xpu/rope_table.zig's two tests (the target's and the drafter's words against their old expressions) ran only under the aggregate test step. test-rope-xpu-host runs them alone, without devices or ocloc; the aggregate step still depends on them. Refs #1852.
5b5347b to
2826a46
Compare
Part of #1852, audit batch 8. Qwen3.8-27B's RoPE tables on XPU now come from core's
rope_freq, so they hold transformers' fp32 words. Values move by exactly 1 ulp.xpu/load.zig:loadandloadGptq) and the DFlash2 drafter (xpu/drafter.zig) take their tables from a newxpu/rope_table.zig:inverseFrequencies(1e7, 64)for the target's 32 words,(1e7, 128)for the drafter's 64.Why the words move: the old code was the more precise one. Both old forms did all the arithmetic in f64 and rounded to fp32 once: the loaders as
f32(1e7^(-i/32)), the drafter asf32(1 / 1e7^(2i/128)).rope_freqdoes what transformers does: it rounds1e7^(2i/d)to fp32, then takes the reciprocal in fp32, so it rounds twice. Each moved word is one where that second rounding lands 1 ulp away, and on every moved word the old value is the nearer one to the exact1e7^(-2i/d). So this change matches transformers' bits; it is not an accuracy fix. θ and the exponents are exact in both fp32 and f64, so nothing else differs.The new target words equal the transformers 5.22.1 words that
rope_freq's own test pins for 1e7/64. The drafter's even words are those same words; its three moved odd words are correctly rounded at each step but not yet checked against torch.Tests:
zig build test-rope-xpu-host(new step; also part ofzig build test) prints the old and new tables side by side and checks the exact moved indices, at most 1 ulp, and the pinned words. Withtest-slide-xpu-host test-draft-xpu-host test-xpu-refusal-host test-qwen27-config-xpu-host: 24/24 steps, 19/19 tests. A planted@compileErrorin each of the three changed call sites failstest-slide-xpu-host, so that step compiles all three.The Qwen4 rotary table and its reference oracle, which this PR used to carry, landed in #2223. This PR is now the XPU change alone and no longer touches
tensorfold.zig.Before landing, on an XPU (Arc): a 27B greedy token A/B of old and new builds on the same ids, and drafted equals undrafted (XPU_VERIFY_TEST, XPU_DRAFTER with XPU_TREE=15, XPU_MULTI_TEST).