Skip to content

Commit 644a8a2

Browse files
committed
fix(Llama): implement fallback to full cache clear in eval
If memory_seq_rm fails to clear from current_pos, fallback to clearing the entire sequence to prevent invalid input batch errors.
1 parent 2ff40cc commit 644a8a2

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

llama_cpp/llama.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,13 @@ def eval(self, tokens: Sequence[int]):
673673
current_pos = self.n_tokens
674674

675675
if self._ctx:
676+
# Standard cleanup by current_pos
676677
is_success = self._ctx.memory_seq_rm(0, current_pos, -1)
678+
# Fallback: Broad cleanup
679+
if not is_success:
680+
if self.verbose:
681+
print(f"WARN: memory_seq_rm(0, {current_pos}, -1) failed. Executing fallback: memory_seq_rm(0, 0, -1)")
682+
is_success = self._ctx.memory_seq_rm(0, 0, -1)
677683

678684
for i in range(0, n_eval, self.n_batch):
679685
batch = tokens[i : min(n_eval, i + self.n_batch)]

0 commit comments

Comments
 (0)