You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(cache): correct mask offset for batched quantized KV caches #75
Batched quantized KV caches (BatchQuantizedKVCache and BatchTurboQuantKVCache) build an incorrect causal mask for left-padded sequences, and they lack a dedicated mask-construction method.
Problem
For batched decode with quantized KV caches, the causal mask must be built from the number of tokens actually stored in the buffer. Using the cache offset field is wrong: offset starts at -left_padding[i] and is negative for padded sequences, so it produces incorrect causal mask shapes. The effect is wrong attention masking during batched quantized decode.
Fix
Track the actual number of buffered tokens separately from offset in both BatchQuantizedKVCache and BatchTurboQuantKVCache, advancing it during decode alongside offset.
Add a make_mask method to both caches that uses the buffered-token count (not offset) as the mask offset and excludes per-sequence padding positions via left_padding.
Add a causal-mask helper that accepts a left_padding argument so padded positions are masked out per sequence.
Acceptance criteria
Both batched quantized cache types expose a correct make_mask.
The mask offset reflects the number of buffered tokens, not the possibly-negative offset.
Left-padding positions are excluded from the causal mask.
The single-token decode path returns no mask, while a non-zero left-padding case returns one.
Unit tests cover the buffered-token advance, mask shape, and left-padding exclusion.
Activity