Skip to content

Swa find slot bugfix - #9

Open
cmp-nct wants to merge 2 commits into
masterfrom
swa_find_slot_bugfix
Open

cmp-nct wants to merge 2 commits into
masterfrom
swa_find_slot_bugfix

Conversation

@cmp-nct

@cmp-nct cmp-nct commented Feb 1, 2026

Copy link
Copy Markdown

in swa/full models (gpt-oss) find_slot corrupts swa kv cache of other sequences

Added no_swa_reuse parameter to find_slot to prevent state restoration from destroying other sequences' KV data.
Added 'no_swa_reuse' parameter to find_slot function.
Copilot AI review requested due to automatic review settings February 1, 2026 03:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a bug in the SWA (Sliding Window Attention) KV cache implementation where find_slot could corrupt the KV cache of other sequences during state restoration operations. The fix introduces a new no_swa_reuse parameter to prevent SWA cell reuse when restoring state.

Changes:

  • Added no_swa_reuse parameter to find_slot() to control SWA cell reuse behavior
  • Modified state restoration to prevent destroying other sequences' KV data
  • Added debug logging for non-empty cell reuse

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/llama-kv-cache.h Added no_swa_reuse parameter to find_slot() declaration with default value false
src/llama-kv-cache.cpp Implemented no_swa_reuse logic in find_slot(), added debug logging, and enabled the flag in state_read_meta()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/llama-kv-cache.cpp

// SWA mask
if (llama_hparams::is_masked_swa(n_swa, swa_type, pos_cell, cells.seq_pos_max(seq_id_cell) + 1)) {
if (is_masked_swa(pos_cell, cells.seq_pos_max(seq_id_cell) + 1)) {

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function call is missing the class qualifier and required parameters. It should be llama_hparams::is_masked_swa(n_swa, swa_type, pos_cell, cells.seq_pos_max(seq_id_cell) + 1) to match the static method signature. The current code will fail to compile because is_masked_swa is not defined in this scope.

Suggested change
if (is_masked_swa(pos_cell, cells.seq_pos_max(seq_id_cell) + 1)) {
if (llama_hparams::is_masked_swa(n_swa, swa_type, pos_cell, cells.seq_pos_max(seq_id_cell) + 1)) {

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 857 calls member function is_masked_swa(...) which delegates to llama_hparams::is_masked_swa(n_swa, swa_type, ...) at line 1496

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants