Skip to content

gemma4 cuda: TF_GEMMA4_V_ONLY keeps V alone in the 31B's global pages, keys made from values (opt-in, exact) - #3389

Draft
jschmied wants to merge 3 commits into
ashhart:mainfrom
jschmied:gemma4-vonly-pr
Draft

jschmied wants to merge 3 commits into
ashhart:mainfrom
jschmied:gemma4-vonly-pr

Conversation

@jschmied

@jschmied jschmied commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes the plan in #3312 (comment 6880132767). Head 975ed0a054, rebased onto main 7b2717a20d (from d6c4cce602). Every receipt below is on this head against that main. The PR binary is 4dfd2cb1 and main's is 1500150e. The capacity loads, the kernel bench and the window tests ran on the binary of f285664210, 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. With TF_GEMMA4_V_ONLY=1, the global pages hold V alone, and attention makes each key from its value, bit for bit:

  • Decode: a block per key head makes each 32-key tile once from V, then runs main's partial/merge sums in main's order.
  • Prompt: each pass makes the keys [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

  • cuda: Gemma 4, Dory and Spark2.5 keep prompt states on disk, on one shared kept image (#840) #3135 landed first, so this PR carries the disk side. Main now keeps Gemma 4's states on disk (--learn-conversations, --prompt-cache-disk, --spill-gib). Its image key (cuda_disk.zig facts) hashes each layer's row bytes and whether it is global, but not whether a global layer holds K and V or V alone, and parts lays out K then V for every layer. I took the refusal, not the key:
    • The refusal is a few lines in the existing gate, and its proof runs on the host.
    • A key would also need parts to 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 be fwd.pages.copies(m) per global layer in facts.
  • GemmaVOnlyKeptDisk: cuda_vonly.zig:30. Gemma's Options gains learn_conversations (cuda_native.zig:58), filled by cuda_options.zig's existing @hasField line, the same way GLM's is. All three flags set it (cli.zig:462,471).
  • The gate runs in open before gpa.create(Owned) (cuda_native.zig:141-142). The disk store attaches only after open returns (native/cuda.zig:291 vs :411), so a refused open never reaches it.
  • The stale test from the first round, which pinned "Gemma 4 has no disk image", is gone: cuda_refusal.zig is now main's file.
  • cuda_disk.zig's test model sets v_only = false. Before, it was undefined under snap.each, which now reads it.
  • Conflicts were only in lists: contract_controls_set.cu (next to nemo_audio's controls), contract_limits.zig's image list, and one help line in tests/cuda/main.zig. Nothing in the kernels or the Gemma 4 forward path conflicted.
  • cuda_vonly_test.zig now 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-native built with zig build native -Dsm=121: main 1500150e, PR 4dfd2cb1.
  • Per-kernel SASS across every embedded fatbin: 1186 kernels have the same name and the same SASS, 0 differ. Four are new, all in their own image window_vonly: tf_vonly_keys, tf_wrows_part_512_pg_vo, tf_wrows_merge_512_pg_vo, tf_wrows_put_v. No existing .cu file changes. contract_controls_set.cu:8 only includes the control.
  • The off arm's host path: cuda_forward.zig:436 (const vo = global and m.v_only) falls through to main's lines. cuda_pages.zig:38-44 keeps 2 copies a layer and no extra region when off.
  • token_sha: off == main in all cells of point 2.

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.

cell main off on
greedy 8K a3b23d5a0751 same same
greedy 32K dd7b9f977f9c same same
seeded 8K be24b98c9364 same same
seeded 32K 6c2f1fc1caf8 same same
drafting greedy 8K a3b23d5a0751 same same
drafting seeded 8K be24b98c9364 same same
drafting repeat f921026a62c7 same same
c=4, 4 streams 13b2684850d1 8ed9249d6f6c dd5132bf9627 f917c3f27f55 same same
c=8, 8 streams the 4 above + 0730025b2ee7 535fa28ba71f 55ed2ff07a1e 8a050a03b894 same same
6K resumed / fresh, greedy 2597d95a4d27 / 2597d95a4d27 same same
6K resumed / fresh, seeded 1ee556a88dcc / 1ee556a88dcc same same
20K resumed / fresh, greedy 7b58cabfbde9 / 7b58cabfbde9 same same
20K resumed / fresh, seeded ea5bd497c79e / ea5bd497c79e same same
  • 29 reply cells, 0 differ. The reply texts are equal too, per stream at c=4 and c=8. Every sha is the same as on the first head.
  • The resumed turns hit the cache, with cached = 6005/6087 and 19775/19847. The fresh greedy turns start at cached 0.
  • The after-drain census reads free N + store 0 == total N on all 24 servers (8 per arm).
  • The RAM snapshot of a V-only stream copies a global layer's V pages alone: cuda_snap.zig:47, test at cuda_snap.zig:253.

3. The switch and its refusals

  • environment.zig:62 is a .flag row next to TF_GEMMA4_CHUNK_SOLO (:61). Valid cases are at environment_test.zig:87-88, and the docs row is at docs/environment.md:40.
  • cuda_vonly.zig:11,16 reads the flag through environment.value/read. The test at cuda_vonly.zig:124 refuses off false no on 2 " 0" "1 " yes true by name (BadGemmaVOnly).
  • Refusals, in cuda_vonly.zig:21, each named and explained:
    • GemmaVOnlyDrafter: assistant or DFlash drafter.
    • GemmaVOnlyKeptDisk (new): --learn-conversations, --prompt-cache-disk or --spill-gib.
    • GemmaVOnlyKvShare: TF_KV_SHARE.
    • GemmaVOnlyUnpaged: TENSORFOLD_GEMMA4_KV_PAGES=0.
    • GemmaVOnlyKeysNotValues: E-series, which have v_proj.
    • GemmaVOnlyOneKeyHead: the 12B.
  • Host test 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.
    • Red controls in the same test (:141-155): the 31B with the mode on goes past the gate, to Owned and the kernels. Disk keep with the mode off goes past it too, so the refusal is V-only's and not the flag's.
    • Planted, red before green: with if (disk) made a no-op, both tests fail (expected error.GemmaVOnlyKeptDisk, found error.BuiltWithoutKernels, and found null), 67/69. With the line in place they pass 69/69 (test-gemma4-cuda-host).
  • Served, on the GB10 with the PR binary:
flags, TF_GEMMA4_V_ONLY=1 exit message files in the disk dir
--learn-conversations --learn-dir D 1 TF_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 0
--prompt-cache-disk D 1 same 0
--spill-gib 2 --prompt-cache-disk D 1 same 0
control, mode off, --learn-conversations --learn-dir D, one 2-turn chat serves none 29 (1.83 GB)

None of the refused servers reached the weights; the log has no KV page groups line.

4. Kernel contract (zig/tests/cuda/contract_window_vonly.zig, run tf-cuda-test kernel-contract window_vonly V-only tf_vonly_keys 'keys without the bf16' on the GB10 at this head)

  • The keys entries replace qk_rows' tf_qk_rows_round K as placed by tf_wrows_put. They run at pages of 256 and 37, at positions 0, 65400, 69900 and 262100, where 262100 takes cosf's slow path.
  • The nonfinite fill plants signed zero, NaN, inf, subnormal and min-normal edges (plantEdges, :396).
  • The decode entries replace tf_wrows_part_512_pg + tf_wrows_merge_512_pg over 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 with tf_wrows_put's V in every prepare.
  • Planted controls, each red as planted: one bit of one made key flipped (:65); keys without the bf16 rounding of w*V (:72, kernel contract_vonly_controls.cuh:6); decode with another k norm's weight (:89).
  • Records in zig/src/core/contract/window_vonly_records.zig (sm 80/86/89/120/121), joined at registry_joins.zig:13. Docs at docs/kernel-contract.md:317.
FAIL shapes control: tf_vonly_keys with one bit of one made key flipped: at 512x4x0 its bytes differ from qk_rows' tf_qk_rows_round K (Gemma 4's global layers), placed by tf_wrows_put's from byte 3145734
CONTROL control: tf_vonly_keys with one bit of one made key flipped: red at shapes, as planted
CONTROL control: keys without the bf16 rounding of w * V: red at shapes, as planted
CONTROL control: V-only decode whose keys take another k norm's weight: red at shapes, as planted
PASS limits live window_vonly tf_wrows_part_512_pg_vo: 256 threads launched, the driver allows 256; 157 registers, 17536 + 65536 shared bytes (recorded 157, 17536)
(filtered) SUMMARY 5 kernels: 5 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems; gates 3742 ms, limits 2 ms

5. Speed, on this head vs main 7b2717a20d

Served 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:

ctx decode main → on paired slower TTFT main → on paired slower
8K 84.99 → 85.01 ms −0.01 % 1 of 4 8.85 → 8.80 s −0.54 % 3 of 6
32K 93.56 → 91.74 ms −1.87 % 0 of 6 44.30 → 44.48 s +0.66 % 5 of 6
63K 104.31 → 100.15 ms −3.98 % 0 of 6 107.60 → 108.91 s +1.43 % 6 of 6

Off vs main:

ctx decode main → off paired slower TTFT paired slower
8K 84.99 → 85.02 ms +0.03 % 6 of 6 +0.53 % 3 of 6
32K 93.56 → 93.60 ms +0.13 % 4 of 6 +0.24 % 4 of 6
63K 104.31 → 104.38 ms +0.10 % 4 of 6 −0.10 % 2 of 6
  • With the mode on, cold prompts at 32K and 63K are slower (+0.7 / +1.4 %, 5 of 6 and 6 of 6), because every prompt pass makes the keys again. That is why the mode is opt-in, and the docs row says so. Decode gains 1.9 % at 32K and 4.0 % at 63K, and at 8K it is flat.
  • With the mode off, decode is +0.03..0.13 % (14 of 18 pairs slower). This is the cell behind "don't land yet". A second run of the same 3 rounds on 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 %.
  • The 8K TTFT pairs span −2.9 … +3.4 % in every arm, so that cell is noise.
  • Raw rows: runs/speed-off,on-r3.jsonl (and -r2 for the f285664210 run), with the per-server logs and nvidia-smi samples next to them.
  • Kernel bench on this head (tf-cuda-test window-bench vonly, cold L2, median of 25):
    • 31B decode: 365 → 336 / 1238 → 1024 / 2423 → 1939 us at 8K / 32K / 64K.
    • 31B prompt (512 rows): +2.5 / +1.5 / +1.6 %.
    • 12B decode: +7 / +12 / +14 %, which is why it is refused.

6. Capacity and pool

Pool page sizes at load (--parallel 1 --context 67584):

main/off: KV page groups: one page 20.00 MiB, 256 rows of the full group; full: 10 layers x 8.00 KiB a row
on:       KV page groups: one page 11.00 MiB, 256 rows of the full group; full: 11 layers x 4.00 KiB a row

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

  • The V-only wiring is in its own file, zig/src/families/gemma4/cuda_vonly.zig (164 lines), with its test cuda_vonly_test.zig (156). The kernels are in zig/kernels/cuda/window_vonly{.cu,.cuh,_part.cuh}, with host code in zig/src/cuda/window_vonly.zig.
  • The largest touched source is cuda_forward.zig at 513 lines. zig/tests/cuda/main.zig stays at 600.
  • Comments are one line, at most 120 columns. Over 120 columns are only the docs table row, Gemma's existing one-line Options (one field longer), the existing image list in contract_limits.zig and the existing pub fn paged line in window_pages512_tests.zig.

8. Code sharing and clean-room

  • Shared CUDA, for any family whose keys are a function of the values at head dim 512 over pool pages: window_vonly.cu/.cuh/_part.cuh, which reuse window_rows.cuh/window_rows512.cuh (NT, Pg, the merge's sums and order); zig/src/cuda/window_vonly.zig; the contract file and records.
  • Reused unchanged: main's K+V prompt kernel (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 new Options field follows cuda_options.zig's existing forwarding, as GLM's does.
  • Gemma 4 only: cuda_vonly.zig, plus the hooks in cuda_forward.zig, cuda_native.zig, cuda_pages.zig, cuda_snap.zig and cuda_kernels.zig.
  • Not touched: Metal, HIP, other families, and core KV accounting (kv.Layout takes one more layer).
  • Clean-room: no other engine's code was read or ported.

9. CI

  • The full x86 set via the dispatcher at this head: zig build -Dfixed-cpu test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths gives 768/771 steps and 10615/10695 tests, with 1 failure. zig build -Dfixed-cpu test-host has 2 failing steps, and they are the same test.
  • That test is 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 main 7b2717a20d without 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.
  • On the GB10: test-gemma4-cuda-host 69/69. tf-cuda-test window-pages-512 and window-rows pass (main's kernels, unchanged).
  • The branch also merges cleanly with today's main f5765b5125 (checked with git 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.

@jschmied

Copy link
Copy Markdown
Contributor Author

The two extra off-vs-main rounds are in. I pooled them with the first round, all on head 8751128d89, A-B-B-A, paired within each block. That gives 6 pairs per cell; one main 8K stream reached the client as 2 events, so 8K has 5.

ctx decode, off vs main slower TTFT, off vs main slower
8K +0.13 % (83.45 → 83.53 ms/tok) 5 of 5 +1.89 % 5 of 5
32K +0.19 % (92.00 → 92.05 ms/tok) 4 of 6 −0.15 % 3 of 6
63K +0.29 % (102.63 → 102.82 ms/tok) 5 of 6 +0.01 % 3 of 6

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:

  • Not GPU code. Every kernel the off arm runs has the same SASS as main: 1170 of 1170 identical. Decode runs as CUDA graphs captured from those same kernels.
  • Not the memory plan. With the mode off, cuda_pages.zig keeps 2 copies a layer and no extra region, and keyBytes is 0. The load lines match main's byte for byte: 20.00 MiB pages, 265 and 1222 pages.
  • What the off arm does differ in: one bool test per global layer during graph capture (cuda_forward.zig:436), two more fields in Model, and a different binary layout. The binary also carries one more embedded image, which the off arm never loads.

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:

  • If that arm is still slower, the cost is in the binary, not the V-only wiring. I'll then check it against an A/A of main rebuilt with an unrelated padding change, to see whether layout alone moves it this much.
  • If it isn't slower, the cost is in the hooks, and I'll take them apart one by one.

I'll post both here.

@jschmied

Copy link
Copy Markdown
Contributor Author

The first check from my last comment is done. I built this head with only the Gemma 4 host hooks reverted: cuda_forward, cuda_native, cuda_pages, cuda_snap, cuda_kernels and cuda.zig are back to main, and cuda_vonly*.zig are removed. The new image, the contract, the tests, the environment row and the docs stay as on the PR head. That binary is 4c0dcdf6, against main's 289b22f3. I served it A-B-B-A against main exactly like the off run: 3 rounds, cold 8K/32K/63K requests, 160 tokens, paired within blocks.

ctx decode, nohooks vs main slower decode, off vs main (earlier) slower
8K −0.02 % 2 of 5 +0.13 % 5 of 5
32K −0.13 % 2 of 6 +0.19 % 4 of 6
63K +0.16 % 4 of 6 +0.29 % 6 of 6

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:

  • copies is 2, regions adds 0, and keyBytes is 0.
  • The pages, the page table and the load lines are byte-identical to main.
  • The per-layer branch in cuda_forward.zig:436 falls through to main's lines.
  • Decode replays a CUDA graph captured from the same kernels, so per-layer host code runs only once, at capture.

What the off binary still changes at decode time: Model grows by two fields and Kernels by one optional, so their offsets and sizes move. And the host code around the graph launch sits at different addresses.

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:

  • Interleaved run: off, nohooks, and main rebuilt with an unrelated padding change, one never-taken branch with a ~260-byte string in cuda_refusal.zig (my A/A). Each arm gets its own A-B-B-A block against main, rotated, 2 rounds. It's queued now. If off still loses there and nohooks and the A/A don't, it's the hooks.
  • If the hooks: I bisect them in two builds. The first keeps the Model/Kernels fields and drops the logic; the second keeps the logic and drops the fields.

Don't land yet still holds until I can show the off arm is even with main.

@jschmied

Copy link
Copy Markdown
Contributor Author

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 8751128d89, with the same prompts as before. Two main 8K streams reached the client as 2 events, so 8K has fewer pairs.

Decode, paired, vs main, all in the same session:

ctx off nohooks A/A (padding only)
8K −0.06 % (1 of 3 slower) +0.37 % (3 of 3) +0.10 % (4 of 4)
32K −0.06 % (2 of 4) −0.10 % (1 of 4) −0.14 % (1 of 4)
63K +0.06 % (3 of 4) +0.08 % (2 of 4) −0.05 % (1 of 4)
all 6 of 11 6 of 11 6 of 12

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:

  • nohooks pools to 14 of 28.
  • The A/A has no V-only code at all. Its only change is one never-taken branch in cuda_refusal.zig, yet it is +0.10 % slower at 8K in 4 of 4 pairs. That is the same size as the off delta.

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.

@jschmied

Copy link
Copy Markdown
Contributor Author

Rebased onto main 7b2717a20d; the head is now 975ed0a054. The body is updated, and every receipt in it is on this head against that 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 TF_GEMMA4_V_ONLY=1, --learn-conversations, --prompt-cache-disk and --spill-gib are refused by name (GemmaVOnlyKeptDisk) in open, before any kernel, weight, stream or copy. The disk store only attaches after open returns, so nothing reaches it.

  • Host test: 0 driver calls and only the config's allocations, the same as the other refusals. A planted no-op of the line turns it red (67/69), and in place it passes 69/69. The control in the same test shows that disk keep with the mode off is not refused.
  • Served: all three flags exit with the message and leave the disk dir empty. The control (mode off, --learn-conversations) writes 29 files after one chat.
  • Why not the key: cuda: Gemma 4, Dory and Spark2.5 keep prompt states on disk, on one shared kept image (#840) #3135's facts would need the page layout, parts would need to drop K for V-only layers, and a served disk round trip under the mode would need its own evidence. That can be a follow-up if someone wants both.

On this head:

  • SASS: 1186/1186 kernels are the same, 0 differ, and 4 are new.
  • Replies: main == off == on in all 29 cells (greedy, seeded, drafting, c=4/8, resumed vs fresh). Every sha is the same as on the first head.
  • Census: clean on all 24 servers.
  • Contract: 5 pass, 3 controls red.
  • Capacity: 4 → 8 streams at a 67K window.

Speed on this head (A-B-B-A, 3 rounds, paired):

  • On: decode −1.9 % at 32K and −4.0 % at 63K, and flat at 8K. Cold TTFT is +0.7 % / +1.4 % at 32K / 63K (5 of 6 and 6 of 6), which is the documented opt-in cost.
  • Off: decode is +0.03..0.13 % against main, 14 of 18 pairs, and 27 of 36 with a second session on the same SASS. That is the same size as round 1 and as the A/A, and it is still a slower served cell. So I'm leaving "don't land yet" up until you say how you want to treat it.

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied for the current-head receipts and the disk-keep controls. The opt-in/default-off wiring, 29 exact-token cells, and named GemmaVOnlyKeptDisk refusal before device work cover the correctness and disk requirements.

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 zig/kernels/cuda/contract_controls_set.cu, zig/tests/cuda/contract_family_sets.zig, zig/tests/cuda/contract_limits.zig and zig/tests/cuda/main.zig. We will rebase it, keeping main's newer registrations and moving the bench-help change to zig/tests/cuda/main_usage.zig, and land it with your authorship. Nothing further is needed from you.

  • Synthena

jschmied and others added 3 commits November 20, 2026 06:10
…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.

This branch has not been deployed

No deployments
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.

2 participants