Repository navigation
Conversation
|
The two extra off-vs-main rounds are in. I pooled them with the first round, all on head
The loss holds. With the mode off, decode on this branch is 0.1–0.3 % slower than main, in 14 of 17 pairs. 8K TTFT is about 1.9 % slower, in 5 of 5. 32K and 63K TTFT are even, at 3 of 6 each. So this stays don't land yet. What I think causes it. I don't know yet, and I haven't profiled it. What I can rule out:
My best guess is the host work per token that sits outside the graph: sampling, the stop checks and the stream write. If that moved in code layout, a constant cost of about 0.1 ms per token would fit the absolute deltas (0.08 / 0.05 / 0.19 ms). The 8K TTFT gap would then come from the same kind of host-side shift on the first long prompt after warm-up. This is a guess, not a measurement. How I'll settle it. I'll build this branch with only the Gemma 4 host hooks reverted, keeping the new image, the contract and the tests, and run it A-B-B-A against main the same way:
I'll post both here. |
|
The first check from my last comment is done. I built this head with only the Gemma 4 host hooks reverted:
Decode without the hooks is even with main: slower in 8 of 17 pairs, against 15 of 17 for the off arm. (I said 14 of 17 last time. One 63K pair is +0.004 %, and I had rounded it to zero.) So the binary carrying the new image doesn't explain the off loss. Under the plan from my last comment, that skips the padding A/A and points at the hooks. That surprises me, and I can't yet say why. With the mode off, every hook computes main's values:
What the off binary still changes at decode time: 8K TTFT doesn't separate the two the same way. nohooks is +1.5 % (3 of 5) against off's +1.9 % (5 of 5), so I don't read the 8K TTFT gap as coming from the hooks yet. Next, I want all three arms measured in one session instead of at different hours:
Don't land yet still holds until I can show the off arm is even with main. |
|
The interleaved run is in. I measured off, nohooks, and main with an unrelated padding change (the A/A) in one session. Each arm got its own A-B-B-A block against main, rotated over 2 rounds. Everything was on head Decode, paired, vs main, all in the same session:
When all three arms run interleaved, the off arm is even with main. Pooled over all of its rounds, though, it still leans slower: 21 of 28 pairs, medians +0.10 / +0.12 / +0.17 % at 8K / 32K / 63K. The other two arms put that in context:
My read: the off delta is at the size that moving the binary's layout produces on this box. It is not a mechanism in the hooks. With the mode off, every hook computes main's values, and decode replays a graph of identical kernels. I'm not going to bisect the hooks, because fields-only and logic-only builds would land inside this same noise. I can't prove the off arm is exactly even, though. If "no served cell slower" has to hold at 0.1 %, I'd need many more pairs per arm, and the A/A shows that would also flag unrelated changes. Your call on how to treat it. Until then I'm leaving "don't land yet" up. 8K TTFT is the noisiest cell, with pairs spanning −3.2 … +3.4 %. Pooled it reads off +1.7 % (7 of 8) and nohooks +0.7 % (5 of 8). With the mode off, the prompt path runs main's kernels with main's host code apart from one bool test per layer per pass. That test can't cost 140 ms, so I don't attribute that cell to the change either. |
8751128 to
975ed0a
Compare
|
Rebased onto main #3135 landed first, so this PR now carries the disk side, as the body promised. I took the refusal, not the kept-image key. With
On this head:
Speed on this head (A-B-B-A, 3 rounds, paired):
|
|
Thanks @jschmied for the current-head receipts and the disk-keep controls. The opt-in/default-off wiring, 29 exact-token cells, and named I accept the disclosed 0.03–0.13% off-mode decode delta for landing: the existing kernels have identical SASS, the off memory plan is unchanged, and the unrelated-change A/A demonstrates the same layout-noise scale. No further performance run is needed for that cell. What remains is ours: the diff conflicts with current main in
|
…s made from values (own image) window_vonly.cu is a new image, so window_pages.cu and every other image are unchanged. Its kernels: tf_vonly_keys makes keys from cached values in qk_round's op order (bf16(w * V), then RoPE with cosf/sinf); tf_wrows_part_512_pg_vo and tf_wrows_merge_512_pg_vo are tf_wrows_part_512_pg/merge_512_pg's arithmetic over V-only pages, a block a key head, each key tile made once; tf_wrows_put_v is tf_wrows_put's v half. Kernel contract: each registers as a replacement bit-equal to the K+V path (contract_window_vonly.zig): keys against qk_rows' K placed by tf_wrows_put (positions to 262,163, edge values), V-only decode against the K+V paged decode (float64 replay included), put_v against put's V. Three controls: a flipped key bit, keys without the bf16 rounding of w * V (tf_ctl_vonly_keys_unrounded), keys from another k norm. Gate-5 records measured with nvcc 13.0 per SM (the same method reproduces window_pages' records). `window-bench vonly` times both paths.
…in), refused by name before anything loads The 31B's global layers have no v_proj, so K is a function of the cached V. With TF_GEMMA4_V_ONLY=1 the global layers' page regions hold V alone (plus one region, a prompt layer's keys made from values for the K+V prompt kernel), and attention makes each key from its value through window_vonly.cu. Unset, empty or 0 is off and the path is main's: the wiring is cuda_vonly.zig, behind `global and m.v_only` in cuda_forward. The switch is a .flag row in environment.zig. Its refusals fire in open from the config alone, before a kernel, weight, stream or copy: an assistant or DFlash drafter, disk keep (--learn-conversations, --prompt-cache-disk, --spill-gib: the disk image's key has no page layout, so no V-only state reaches it), TF_KV_SHARE, linear caches, a checkpoint whose global layers have v_proj, and the 12B (one key head). cuda_vonly_test.zig counts driver calls and allocations to show it. Kept states in RAM copy V alone under the mode.
975ed0a to
e407950
Compare
Closes the plan in #3312 (comment 6880132767). Head
975ed0a054, rebased onto main7b2717a20d(fromd6c4cce602). Every receipt below is on this head against that main. The PR binary is4dfd2cb1and main's is1500150e. The capacity loads, the kernel bench and the window tests ran on the binary off285664210, which differs from this head only by one deleted comment line: SASS 1190/1190 the same, host bytes shifted by the line.Don't land yet, unless you accept the off cell below. With the mode off, decode on this binary is 0.03–0.13 % slower than main, in 14 of 18 pairs (27 of 36 over two sessions). The off arm runs main's SASS (1186/1186 kernels the same) on main's host path, apart from one bool test per layer. In round 1, an A/A with only a never-taken branch changed measured the same size against main (+0.10 % at 8K, 4 of 4,
followup-3389-rot). So I read this as binary layout, not a mechanism in the hooks. Under your rule it is still a slower served cell, so I am saying so. Your call.What it does
Gemma 4 31B's global layers have no
v_proj(attention_k_eq_v). V = bf16(x * rstd), and K = rope(bf16(w_k * V)), so K is a function of the cached V. WithTF_GEMMA4_V_ONLY=1, the global pages hold V alone, and attention makes each key from its value, bit for bit:[0, p0 + rows)into one scratch region in the page layout. Main's K+V prompt kernel then reads that scratch unchanged. This is where the TTFT cost comes from.The mode is off by default, and it stays opt-in. A V-only page is 11.00 MiB (10 V regions plus the prompt's key scratch), against 20.00 MiB.
What changed in this rebase
--learn-conversations,--prompt-cache-disk,--spill-gib). Its image key (cuda_disk.zigfacts) hashes each layer's row bytes and whether it is global, but not whether a global layer holds K and V or V alone, andpartslays out K then V for every layer. I took the refusal, not the key:partsto drop K for V-only layers, and a served disk round trip (restart, reload, resumed == fresh) under the mode. That is a follow-up worth doing when someone wants V-only and disk keep together. The key would befwd.pages.copies(m)per global layer infacts.GemmaVOnlyKeptDisk:cuda_vonly.zig:30. Gemma'sOptionsgainslearn_conversations(cuda_native.zig:58), filled bycuda_options.zig's existing@hasFieldline, the same way GLM's is. All three flags set it (cli.zig:462,471).openbeforegpa.create(Owned)(cuda_native.zig:141-142). The disk store attaches only afteropenreturns (native/cuda.zig:291vs:411), so a refused open never reaches it.cuda_refusal.zigis now main's file.cuda_disk.zig's test model setsv_only = false. Before, it wasundefinedundersnap.each, which now reads it.contract_controls_set.cu(next tonemo_audio's controls),contract_limits.zig's image list, and one help line intests/cuda/main.zig. Nothing in the kernels or the Gemma 4 forward path conflicted.cuda_vonly_test.zignow counts allocations over a page-aligned fixed buffer, not an arena. On the new main the arena counts drifted by ±1 between cases (read 8, open 7) with the same code path. The fixed buffer gives one count per path.The nine points
1. Off == main
tensorfold-nativebuilt withzig build native -Dsm=121: main1500150e, PR4dfd2cb1.window_vonly:tf_vonly_keys,tf_wrows_part_512_pg_vo,tf_wrows_merge_512_pg_vo,tf_wrows_put_v. No existing.cufile changes.contract_controls_set.cu:8only includes the control.cuda_forward.zig:436(const vo = global and m.v_only) falls through to main's lines.cuda_pages.zig:38-44keeps 2 copies a layer and no extra region when off.2. On == off, token for token (the same cell list as round 1, fixed before the runs)
Greedy and seeded (temp 1.0, seed 4242) at 8K and 32K with drafts off; default drafting (greedy 8K, seeded 8K, and a repeat prompt that accepts prompt drafts); c=4 and c=8 (half greedy, half seeded, ~7K each); resumed vs fresh 2-turn chats at 6K and 20K, greedy and seeded, with a prompt cache.
a3b23d5a0751dd7b9f977f9cbe24b98c93646c2f1fc1caf8a3b23d5a0751be24b98c9364f921026a62c713b2684850d18ed9249d6f6cdd5132bf9627f917c3f27f550730025b2ee7535fa28ba71f55ed2ff07a1e8a050a03b8942597d95a4d27/2597d95a4d271ee556a88dcc/1ee556a88dcc7b58cabfbde9/7b58cabfbde9ea5bd497c79e/ea5bd497c79efree N + store 0 == total Non all 24 servers (8 per arm).cuda_snap.zig:47, test atcuda_snap.zig:253.3. The switch and its refusals
environment.zig:62is a.flagrow next toTF_GEMMA4_CHUNK_SOLO(:61). Valid cases are atenvironment_test.zig:87-88, and the docs row is atdocs/environment.md:40.cuda_vonly.zig:11,16reads the flag throughenvironment.value/read. The test atcuda_vonly.zig:124refusesoff false no on 2 " 0" "1 " yes trueby name (BadGemmaVOnly).cuda_vonly.zig:21, each named and explained:GemmaVOnlyDrafter: assistant or DFlash drafter.GemmaVOnlyKeptDisk(new):--learn-conversations,--prompt-cache-diskor--spill-gib.GemmaVOnlyKvShare:TF_KV_SHARE.GemmaVOnlyUnpaged:TENSORFOLD_GEMMA4_KV_PAGES=0.GemmaVOnlyKeysNotValues: E-series, which havev_proj.GemmaVOnlyOneKeyHead: the 12B.cuda_vonly_test.zig:126: a fake driver counts module loads, streams, allocations and copies, and a counting allocator runs over a fixed buffer. For each refusal, the disk one included (:98), it expects the named error, 0 driver calls, and exactly the config read's allocations (0 for a bad value). So nothing is loaded, allocated on the device, copied or queued before the refusal fires.:141-155): the 31B with the mode on goes past the gate, toOwnedand the kernels. Disk keep with the mode off goes past it too, so the refusal is V-only's and not the flag's.if (disk)made a no-op, both tests fail (expected error.GemmaVOnlyKeptDisk, found error.BuiltWithoutKernels, andfound null), 67/69. With the line in place they pass 69/69 (test-gemma4-cuda-host).TF_GEMMA4_V_ONLY=1--learn-conversations --learn-dir DTF_GEMMA4_V_ONLY=1: --learn-conversations, --prompt-cache-disk and --spill-gib keep states on disk as K+V page images, which V-only pages do not hold: serve without them, or unset TF_GEMMA4_V_ONLY--prompt-cache-disk D--spill-gib 2 --prompt-cache-disk D--learn-conversations --learn-dir D, one 2-turn chatNone of the refused servers reached the weights; the log has no
KV page groupsline.4. Kernel contract (
zig/tests/cuda/contract_window_vonly.zig, runtf-cuda-test kernel-contract window_vonly V-only tf_vonly_keys 'keys without the bf16'on the GB10 at this head)tf_qk_rows_roundK as placed bytf_wrows_put. They run at pages of 256 and 37, at positions 0, 65400, 69900 and 262100, where 262100 takes cosf's slow path.plantEdges,:396).tf_wrows_part_512_pg+tf_wrows_merge_512_pgover K+V pages, at 32/4 heads on pages of 256 and 37, and at 10/2 heads (GQA 5).tf_wrows_put_v's placed V is compared byte for byte withtf_wrows_put's V in every prepare.:65); keys without the bf16 rounding of w*V (:72, kernelcontract_vonly_controls.cuh:6); decode with another k norm's weight (:89).zig/src/core/contract/window_vonly_records.zig(sm 80/86/89/120/121), joined atregistry_joins.zig:13. Docs atdocs/kernel-contract.md:317.5. Speed, on this head vs main
7b2717a20dServed A-B-B-A, with main against off and on in one session. Each arm got its own block, rotated over 3 rounds (24 servers), and pairs are taken within a block. Each request is cold, with 160 tokens. Decode ms/tok comes from the token stamps, and TTFT from the done line. The page cache is dropped before every start, and the GPU clock is capped (2281–2288 MHz under load in every arm). Two main 8K streams reached the client as 2 events, though the server made all 160 tokens. Their decode pairs are dropped, and their TTFT pairs use the server's done line.
On vs main:
Off vs main:
f285664210, the same SASS, gave +0.06 / +0.05 / +0.11 % (13 of 18). Pooled, that is +0.05 / +0.13 / +0.11 %, 27 of 36. It matches round 1's +0.10..0.17 %, and the A/A's +0.10 %.runs/speed-off,on-r3.jsonl(and-r2for thef285664210run), with the per-server logs and nvidia-smi samples next to them.tf-cuda-test window-bench vonly, cold L2, median of 25):6. Capacity and pool
Pool page sizes at load (
--parallel 1 --context 67584):265 pages at that window: 5.18 GiB vs 2.85 GiB.
With
TENSORFOLD_CUDA_MEMORY_LIMIT_GB=60 --parallel 16 --context 67584, the same 23.87 GiB pool in all three arms gives main and off 1222 pages, enough for 4 streams at a 67,584-token window, and on 2222 pages, enough for 8.7. Files and lines
zig/src/families/gemma4/cuda_vonly.zig(164 lines), with its testcuda_vonly_test.zig(156). The kernels are inzig/kernels/cuda/window_vonly{.cu,.cuh,_part.cuh}, with host code inzig/src/cuda/window_vonly.zig.cuda_forward.zigat 513 lines.zig/tests/cuda/main.zigstays at 600.Options(one field longer), the existing image list incontract_limits.zigand the existingpub fn pagedline inwindow_pages512_tests.zig.8. Code sharing and clean-room
window_vonly.cu/.cuh/_part.cuh, which reusewindow_rows.cuh/window_rows512.cuh(NT,Pg, the merge's sums and order);zig/src/cuda/window_vonly.zig; the contract file and records.WindowAttention.promptRows),tf_wrows_put's layout,qk_rows' rounding points, and cuda: Gemma 4, Dory and Spark2.5 keep prompt states on disk, on one shared kept image (#840) #3135's disk path (native/cuda_kept.zig,gemma4/cuda_disk.zig), which this PR refuses rather than forks. The newOptionsfield followscuda_options.zig's existing forwarding, as GLM's does.cuda_vonly.zig, plus the hooks incuda_forward.zig,cuda_native.zig,cuda_pages.zig,cuda_snap.zigandcuda_kernels.zig.kv.Layouttakes one more layer).9. CI
zig build -Dfixed-cpu test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-pathsgives 768/771 steps and 10615/10695 tests, with 1 failure.zig build -Dfixed-cpu test-hosthas 2 failing steps, and they are the same test.cli_config_test"serve --config: expand reads the file…", which is the only failure in both. It fails the same way on that box at main7b2717a20dwithout this branch (test-cuda-host, 1 failed, the same test).zig build check-native-cuda-host compile-cuda-tests: 16/16.python3 tools/pr_check.py --base 7b2717a20d: 0 errors, lean 221 vs 221, 0 new. One WARN, the Unreleased line, which is proposed below.zig fmt --check build.zig zig: clean.test-gemma4-cuda-host69/69.tf-cuda-test window-pages-512andwindow-rowspass (main's kernels, unchanged).f5765b5125(checked withgit merge-tree).Proposed CHANGELOG line (yours to place):
- CUDA: TF_GEMMA4_V_ONLY=1 keeps V alone in Gemma 4 31B's global pages and makes each key from its value, bit for bit (page 20 → 11 MiB, twice the streams at a 67K window; prompts slower, opt-in; refused with disk keep).I keep the raw receipts (per-request jsonl, every server log, the full contract, bench and SASS outputs). Say which you want attached.