Repository navigation
Conversation
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.
There was a problem hiding this comment.
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_reuseparameter tofind_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.
|
|
||
| // 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)) { |
There was a problem hiding this comment.
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.
| 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)) { |
There was a problem hiding this comment.
Line 857 calls member function is_masked_swa(...) which delegates to llama_hparams::is_masked_swa(n_swa, swa_type, ...) at line 1496
in swa/full models (gpt-oss) find_slot corrupts swa kv cache of other sequences