Repository navigation
Vulkan: enable TurboQuant and fix prefill/smem issues #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,12 +45,13 @@ void main() { | |
| uint pos0 = uint(p.step.v[0]), last_max = pos0 + p.q_off + min(q0 + p.bq, p.t) - 1, last_q = pos0 + p.q_off + q; | ||
| uint kvd = p.nkv * HD, kvo = kvh * HD; | ||
| float qv[8], acc[8], m = 0.0, l = 0.0; | ||
| if (TQ_K) rotate_q(qv, lane); | ||
| bool first = true; | ||
| [[unroll]] for (uint j = 0; j < PER; j++) { | ||
| qv[j] = live ? p.q.v[(qr * p.nh + hr) * HD + tq_idx(j, lane, KV_MODE)] * p.scale : 0.0; | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 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 agentReply |
||
| for (uint k0 = 0; k0 <= last_max; k0 += BK) { | ||
| barrier(); | ||
| // All threads load the tile (inactive tasks too, they still reach the barrier). Rows past the last key are | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -321,6 +321,14 @@ mod tests { | |
| assert_eq!(shared_bytes("gemmi_s_16", &[0, 10, 84, 0, 0], 0).unwrap(), 20992); | ||
| } | ||
|
|
||
| /// The turbo hd128 prefill staging must fit the smallest supported workgroup limit (49152 B). | ||
| #[test] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 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 agentReply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 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 agentReply |
||
| fn turbo_prefill_128_fits_49152() { | ||
| let bytes = shared_bytes_split("attn_prefill_128", &[], 4, 4).unwrap(); | ||
| assert_eq!(bytes, 47616, "turbo attn_prefill_128 shared memory changed"); | ||
| assert!(bytes <= 49152, "turbo attn_prefill_128 needs {bytes} B"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn shared_memory_refusal_names_the_kernel_spec_and_both_sizes() { | ||
| let e = check_shared_memory("gemmi_dp", &[0, 10, 84, 0, 0], 0, 0, 40960).unwrap_err().to_string(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ fn set(k: &str, v: &str) { | |
| unsafe { | ||
| std::env::set_var("STRATA_KV_K", k); | ||
| std::env::set_var("STRATA_KV_V", v); | ||
| std::env::set_var("STRATA_VK_TURBO", "1"); | ||
| std::env::remove_var("STRATA_KV"); | ||
| std::env::remove_var("STRATA_KV_Q8"); | ||
| } | ||
|
|
@@ -86,7 +85,6 @@ fn cu_caches(k: &str, v: &str, s: Shape) -> (Vec<u16>, Vec<u16>) { | |
| } | ||
|
|
||
| #[test] | ||
| #[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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 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 agentReply |
||
|
|
@@ -169,3 +167,21 @@ fn vulkan_inkling_turbo_hd64() { | |
| eprintln!("vulkan turbo hd64 prefill vs decode {:.2e}", rel_l2(&got, &want)); | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 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 agentReply |
||
| #[test] | ||
| fn vulkan_turbo_tiled_prefill_matches_decode() { | ||
| let _lock = common::gpu_lock(); | ||
| set("turbo4", "turbo4"); | ||
| unsafe { std::env::set_var("STRATA_VK_NO_COOP", "1") }; | ||
| let Some(vk) = open_vk() else { | ||
| unsafe { std::env::remove_var("STRATA_VK_NO_COOP") }; | ||
| return; | ||
| }; | ||
| for hd in [128, 256] { | ||
| let (_, _, pf, dec) = run(&vk, (4, 2, hd, 16, 3)); | ||
| eprintln!("vulkan turbo4 tiled hd {hd} prefill vs decode {:.2e}", rel_l2(&pf, &dec)); | ||
| assert!(rel_l2(&pf, &dec) < 5e-4, "vulkan turbo4 tiled hd {hd} prefill vs decode"); | ||
| } | ||
| unsafe { std::env::remove_var("STRATA_VK_NO_COOP") }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 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
Reply
/dismiss(optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.