Repository navigation
Conversation
Rotate Q after loading it in the non-coop tiled prefill kernel. Give the two 128-value groups of kv_store their own shared-memory rows. Size the cooperative prefill Q staging by HD instead of a fixed 256, cutting hd 128 prefill from 64000 B to 47616 B. Remove the STRATA_VK_TURBO gate, unignore the hd 128 test, and add tiled hd 128/256 and smem-limit coverage.
| @@ -369,10 +369,6 @@ impl Vk { | |||
| /// The usable GPU with index `device` (`backend::device_order`). Fails with "Vulkan init" (and the reasons) when there is none. | |||
| pub fn new(device: usize) -> anyhow::Result<Vk> { | |||
| let (kv_k_mode, kv_v_mode) = (crate::cuda::kv_k_mode(), crate::cuda::kv_v_mode()); | |||
There was a problem hiding this comment.
🟠 High · Correctness · 1 of 6
Turbo KV is now enabled on Vulkan unconditionally, though the removed comment recorded wrong output on Qwen3-4B. Users running --kv turbo* on Vulkan with a model like Qwen3-4B get garbled text, because the only evidence of the fix is a non-coop test that is opt-in. The default coop prefill path has no test, so the removed guard now lets the known bad output reach users.
Prompt for your AI agent
File: src/vulkan/mod.rs
Line: 371
Symbol: new
Issue: Turbo KV is now enabled on Vulkan unconditionally, though the removed comment recorded wrong output on Qwen3-4B. Users running --kv turbo* on Vulkan with a model like Qwen3-4B get garbled text, because the only evidence of the fix is a non-coop test that is opt-in. The default coop prefill path has no test, so the removed guard now lets the known bad output reach users.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| assert!(rel_l2(&got, &want) < 5e-4, "vulkan turbo hd64 prefill vs decode"); | ||
| } | ||
|
|
||
| /// Exercises the non-coop tiled prefill path, where Q used to be rotated before it was loaded. |
There was a problem hiding this comment.
🔵 Low · Maintainability · 2 of 6
The new tiled-prefill test covers only the non-coop path, so default prefill correctness is unverified. The default coop prefill (attn_prefill.glsl) still uses the Q-rotation ordering the tile shader had, or is wrong for turbo. The tests pass with STRATA_VK_NO_COOP=1 while real turbo prefill on the default path still produces wrong output.
Prompt for your AI agent
File: tests/vulkan_split_kv.rs
Line: 171
Symbol: vulkan_inkling_turbo_hd64
Issue: The new tiled-prefill test covers only the non-coop path, so default prefill correctness is unverified. The default coop prefill (attn_prefill.glsl) still uses the Q-rotation ordering the tile shader had, or is wrong for turbo. The tests pass with STRATA_VK_NO_COOP=1 while real turbo prefill on the default path still produces wrong output.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| acc[j] = 0.0; | ||
| } | ||
| // Rotate after loading: rotating first would scramble uninitialized values and leave Q unrotated. | ||
| if (TQ_K) rotate_q(qv, lane); |
There was a problem hiding this comment.
🟠 High · Correctness · 3 of 6
Q is rotated right after shared-memory loads, which may need a barrier before rotate_q reads the staged values. If rotate_q reads Q values written to shared memory by other lanes during the load, a lane can read a stale value because no barrier separates the writes from the rotation. The result is nondeterministic, wrong Q rotation on some GPUs.
Prompt for your AI agent
File: src/vulkan/shaders/attn_prefill_tile.comp
Line: 54
Issue: Q is rotated right after shared-memory loads, which may need a barrier before rotate_q reads the staged values. If rotate_q reads Q values written to shared memory by other lanes during the load, a lane can read a stale value because no barrier separates the writes from the rotation. The result is nondeterministic, wrong Q rotation on some GPUs.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| } | ||
|
|
||
| /// The turbo hd128 prefill staging must fit the smallest supported workgroup limit (49152 B). | ||
| #[test] |
There was a problem hiding this comment.
🔵 Low · Maintainability · 4 of 6
The shared-memory test checks only hd128; the hd256 turbo prefill is not checked against the 49152 B limit. With the Vulkan turbo gate removed, hd256 turbo prefill can exceed 49152 B on an RTX 3060-class device. The hd128 test still passes, so the regression reaches users as a pipeline creation failure.
Prompt for your AI agent
File: src/vulkan/spv_smem.rs
Line: 325
Symbol: shared_memory_refusal_names_the_kernel_spec_and_both_sizes
Issue: The shared-memory test checks only hd128; the hd256 turbo prefill is not checked against the 49152 B limit. With the Vulkan turbo gate removed, hd256 turbo prefill can exceed 49152 B on an RTX 3060-class device. The hd128 test still passes, so the regression reaches users as a pipeline creation failure.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| #[ignore = "turbo attn_prefill_128 needs 64000 B of shared memory, more than the 49152 of an RTX 3060 under Vulkan"] | ||
| fn vulkan_split_legacy_and_turbo() { | ||
| let _lock = common::gpu_lock(); | ||
| let shape: Shape = (4, 2, 128, 16, 3); |
There was a problem hiding this comment.
🔵 Low · 5 of 6
Removing #[ignore] runs the heavy turbo test by default. The env vars set in the new test are not restored on panic. The new test panics inside the loop after set_var(STRATA_VK_NO_COOP). The env var is never removed, so later tests in the same process take the non-coop path and fail or pass for the wrong reason.
Prompt for your AI agent
File: tests/vulkan_split_kv.rs
Line: 90
Symbol: vulkan_split_legacy_and_turbo
Issue: Removing #[ignore] runs the heavy turbo test by default. The env vars set in the new test are not restored on panic. The new test panics inside the loop after set_var(STRATA_VK_NO_COOP). The env var is never removed, so later tests in the same process take the non-coop path and fail or pass for the wrong reason.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| } | ||
|
|
||
| /// The turbo hd128 prefill staging must fit the smallest supported workgroup limit (49152 B). | ||
| #[test] |
There was a problem hiding this comment.
🔵 Low · Maintainability · 6 of 6
The test hard-codes the exact byte count 47616, so any unrelated shader change breaks it. Adding a small shared array to the prefill shader changes the byte count and fails this test, even though the 49152 limit is still met. Maintainers then update the constant without checking the limit.
Prompt for your AI agent
File: src/vulkan/spv_smem.rs
Line: 325
Symbol: shared_memory_refusal_names_the_kernel_spec_and_both_sizes
Issue: The test hard-codes the exact byte count 47616, so any unrelated shader change breaks it. Adding a small shared array to the prefill shader changes the byte count and fails this test, even though the 49152 limit is still met. Maintainers then update the constant without checking the limit.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
Aletheore Flash Lite reviewWhat this PR does. This PR enables TurboQuant KV-cache modes (turbo*) on the Vulkan backend by removing the guard that refused them, and fixes several related bugs: Q is now rotated after loading in the tiled prefill shader, the KV store shader's WHT staging is split per workgroup group, and the prefill Q staging array is sized by HD.
6 finding(s) posted as inline review comment(s).
Review detailsReviewed 6 file(s); skipped 4. Dismissed 0; outside PR diff 0. Grounding: 6 of 6 proposed finding(s). Fix all with your agentNote: 4 of 10 changed file(s) were not included in this review (the review reads at most 30 files, and skips any file over 100KB). Issues in them would not be found, and citations pointing into them could not be checked against the real file: |
🔍 Aletheore evidence diffgraph LR
n0["src/vulkan/mod.rs"]
n1["spv_smem.rs"]
n2["src/backend.rs"]
n3["lib.rs"]
n4["preflight.rs"]
n5["tests/backend.rs"]
n6["tests/common/mod.rs"]
n7["gpu_model.rs"]
n8["kernels.rs"]
n9["kv_q8.rs"]
n10["llama_numerics.rs"]
n0 --> n2
n0 --> n3
n0 --> n4
n0 --> n5
n0 --> n6
n0 --> n7
n0 --> n8
n0 --> n9
n0 --> n10
n1 --> n4
n1 --> n5
classDef changed fill:#d9772c,color:#fff,stroke:#b85f1c;
classDef changedFinding fill:#c0392b,color:#fff,stroke:#922b21;
classDef dependent fill:#f2f0ec,color:#18140f,stroke:#d6d0c5;
class n0 changed
class n1 changed
class n2 dependent
class n3 dependent
class n4 dependent
class n5 dependent
class n6 dependent
class n7 dependent
class n8 dependent
class n9 dependent
class n10 dependent
What changed
Aggregate deltas
|
Re-enable TurboQuant on Vulkan after the three issues found after the first merge.
Fixes
attn_prefill_tile.comprotated Q before loading it, so the non-coop tiled fallback used uninitialized values and never rotated the loaded Q. The rotation now runs after the load.kv_store.compdeclared 128-element shared rows but 256 threads wrote into them, and each 128-value group rotated using an out-of-range base. The rows are now[2][128]and each half rotates its own row. This matters for head_dim 256, where one workgroup handles two groups.attn_prefill.glslstaged Q in a fixed[4][16][256]array. Sizing it byHDcuts head_dim 128 prefill from 64000 B of workgroup memory to 47616 B, under the 49152 B limit of the smaller Vulkan devices. The gate onSTRATA_VK_TURBOis removed and the previously ignored head_dim 128 test is active again.Verification
cargo test --release --lib --test backend --test vulkan_split_kvis green: 159 lib tests, 10 backend tests and 3 Vulkan split-KV tests. New coverage checks the non-coop tiled prefill at head_dim 128 and 256, and asserts the committed head_dim 128 prefill SPIR-V stays at 47616 B. Prefill versus decode relative L2 is 1.88e-7 tiled at head_dim 128, 1.56e-7 tiled at head_dim 256, 4.32e-4 cooperative at head_dim 128, 3.17e-4 for K=turbo4 V=f16, 3.04e-4 for K=f16 V=turbo4, and 2.43e-7 for the Inkling 2 head_dim 64 path. Legacy formats remain byte-identical to CUDA.The original quality numbers still stand: on Tiel Coder 35B A3B over 511 scored positions, turbo4 has PPL 5.8122, top-1 agreement 90.80% and mean KLD 0.0361, against q4 at 5.8526, 89.04% and 0.0429 with the same cache size.