codec: guard the KV ring against models with a wider sliding window

This commit is contained in:
Pascal
2026-07-05 10:36:58 +02:00
parent c39ef15bab
commit a37ff074ff
+9
View File
@@ -245,6 +245,15 @@ static bool pipeline_codec_stream_ensure(PipelineCodec * pc) {
return false;
}
// The ring must hold the whole sliding window plus the fresh frame,
// otherwise window slots alias through the modulo and corrupt the
// attention silently.
if (pc->transformer.sliding_window + 1 > CODEC_STREAM_RING) {
qt_log(QT_LOG_ERROR, "[Pipeline] sliding window %d exceeds KV ring %d", pc->transformer.sliding_window,
CODEC_STREAM_RING);
return false;
}
if (!kv_cache_init(&pc->stream_kv, pc->transformer.num_layers, pc->transformer.num_kv_heads,
pc->transformer.head_dim, CODEC_STREAM_RING, pc->backend)) {
ggml_backend_buffer_free(pc->stream_buf);