CUDA DSA: fix v_offset for quantized K/V caches (#2387)

v_offset is used as a column index into the dequantized f16 buffer, but was
computed as a half-pointer difference. That is only correct for f16 K/V. With
q8_0 (34 bytes per 32 elements) it yields the wrong column, so the sparse
attention path reads V from the wrong positions and generation degenerates.
This commit is contained in:
Alex 2026-08-31 19:35:17 +03:00 committed by GitHub
parent 15dddc60b3
commit ab6d816818
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -296,7 +296,9 @@ bool ggml_cuda_dsa_attn_ext(ggml_backend_cuda_context & ctx, ggml_tensor * dst)
ggml_cuda_pool_alloc<half> v16(ctx.pool());
size_t v_offset = 0;
if (is_k_view) {
v_offset = (const half *)V->data - (const half *)K->data;
// Using /sizeof(half) is only correct for f16 K/V, for a quantized cache(i.e. q8_0) it yields the wrong column
const size_t v_byte_off = (const char *)V->data - (const char *)K->data;
v_offset = v_byte_off / ggml_type_size(K->type) * ggml_blck_size(K->type);
} else {
v16.alloc(v_cache_size);
}