graph: pad the KQ bias of the no-cache attention (#30446)

The no-cache attention pads K, V and the mask to 256, but T5 also adds
a relative position bias of [n_tokens, n_tokens], so the add with KQ
fails unless n_tokens divides the padded width. Pad the bias with
zeros up to the KV dimension of the mask, like K and V.
This commit is contained in:
Pascal authored and GitHub committed 2026-10-13 16:34:10 +02:00
1 parent b9f3599fb1
commit ace20f679e
1 file changed
+5 -1
+5 -1
View File
@@ -3056,12 +3056,16 @@ ggml_tensor * llm_graph_context::build_attn(
ggml_tensor * k = k_cur;
ggml_tensor * v = v_cur;
// the KV values are padded with zeros up to the KV dimension of the mask
// the KV values and the KQ bias are padded with zeros up to the KV dimension of the mask
const int64_t n_kv_pad = kq_mask->ne[0] - k->ne[2];
k = ggml_pad(ctx0, k, 0, 0, n_kv_pad, 0);
v = ggml_pad(ctx0, v, 0, 0, n_kv_pad, 0);
if (kq_b) {
kq_b = ggml_pad(ctx0, kq_b, n_kv_pad, 0, 0, 0);
}
ggml_tensor * cur = build_attn_mha(q, k, v, kq_b, kq_mask, sinks, v_mla, 0, kq_scale, il);
cb(cur, "kqv_out", il);