Vulkan: delta_net_cols_f16 runs with 64-wide subgroups, corrupts prefill (n_tok >= 32)
Summary
On Vulkan devices whose default subgroup size is 64 (e.g. RADV PHOENIX /
Radeon 780M), any prefill step with n_tok >= 32 corrupts the delta-net
recurrent state. Short chats work; anything with a long system prompt (e.g.
q36-agent, whose bootstrap prompt is ~2600 tokens) answers with repeated
garbage tokens.
The batched delta-net column kernel assumes 32-wide subgroups but its f16 variant never receives the required-subgroup-size override.
Environment
- commit
0cbb90c(also present onmain@2a9096a) - GPU: AMD Radeon 780M (RADV PHOENIX), 26 GiB UMA, Vulkan generic backend
q36: Vulkan generic backend, subgroup 64- model:
gguf/Qwen3.6-35B-A3B-IQ2XXS-Q2K-Q8.gguf - default settings: f16 recurrent state, delta-column prefill enabled
(
q36_vk_use_delta_col_prefill()defaults on for non-BC250)
Reproduction
Any prompt reaching >= 32 tokens in one prefill step fails:
./q36 -m gguf/Qwen3.6-35B-A3B-IQ2XXS-Q2K-Q8.gguf --vulkan \
-p "$(cat prompt_of_at_least_32_tokens.txt)" -n 16
# -> "4444444444", "<|im_start|>", repeated CJK fragments, ...
Bisect with the chunk size; 16 is fine, 32 breaks:
for ch in 8 16 32; do
./q36 -m gguf/Qwen3.6-35B-A3B-IQ2XXS-Q2K-Q8.gguf --vulkan \
--prefill-chunk $ch -p "$(cat prompt.txt)" -n 10
done
Isolation:
Q36_VK_DELTA_COL_PREFILL=0-> correct outputQ36_VK_RECURRENT_STATE_F16=0-> correct output (f32 state usesdelta_net_cols.spv, which is forced to 32 lanes)- CPU reference on the same 66-token prompt -> correct output
q36-agent --vulkan -p "Reply with exactly: OK" --non-interactive-> garbage before the fix,OKafter
Root cause
vulkan/delta_net_cols.comp hardcodes LANES = 32, COLS = 4 and derives the
column from gl_SubgroupID / gl_SubgroupInvocationID.
q36_vk_kernel_init() (q36_vulkan.c) attaches
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo{ .requiredSubgroupSize = 32 }
only when the pipeline path matches "delta_net_cols.spv". The f16 variant is
named delta_net_cols_f16.spv, so it runs at the device default (64 lanes).
With 64-wide subgroups a workgroup has only two subgroups: only two of the four
columns are visited, j = workgroup.y * 4 + gl_SubgroupID never covers the full
row, and i = r * 32 + lane with lane up to 63 misindexes/overruns the 128x128
state.
Fix
- strstr(k->path, "delta_net_cols.spv") ||
+ strstr(k->path, "delta_net_cols") ||
Additionally, checkpoints written by the buggy build contain corrupted f16
recurrent state and still load afterwards (agent's sysprompt.kv keeps the
failure alive). Bumping the payload ABI rejects them:
-#define KV_CACHE_PAYLOAD_ABI 2u
+#define KV_CACHE_PAYLOAD_ABI 3u
Full patch (including a regression test that compares the batched f16 state
update against a scalar per-column reference; it fails without the fix) is
attached. It applies on 0cbb90c and needs a trivial rebase on 2a9096a.
Unrelated observation
On the same Radeon 780M, ./q36_test --vulkan-kernels already fails
test_vulkan_delta_verify at the two state/output memcmp assertions with
unmodified 0cbb90c (4 failures). It looks like a separate f16
delta_net_verify_reg_f16 precision issue on this device, but I did not
investigate.