[cache] Fix batch_quantized_cache extend() truncation bug (#67) #78
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/67-batch-extend-truncation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes: #67
Problem:
extend()silently truncated KV data when merging caches with different buffer sizes and offsets.Root cause:
max_sizeonly considered buffer size, not actual used size plus left padding.Fix: Compute
max_sizeasmax((max_idx - self._idx) + buffer_size, ...)to account for left padding.Test: Added
test_extend_no_truncation_different_idx_and_bufferverifying no data loss.Results:
The extend() method computed max_size as the max buffer size across both caches, ignoring the left padding needed to align them to max_idx. When a cache with a large buffer but small _idx was left-padded, the resulting left + buffer could exceed max_size, causing a negative right pad that silently truncated the buffer tail. Fix max_size to account for left padding: max_size = max((max_idx - self._idx) + self.keys[0].shape[2], (max_idx - other._idx) + other.keys[0].shape[2]) Add test case reproducing the bug with _idx=100/buffer=200 and _idx=150/buffer=150 caches. Fixes #67