Repository navigation
fix(longsana): clamp KV cache windows to available history - #577
Merged
lawrence-cj merged 1 commit intoNov 12, 2026
Merged
Conversation
lawrence-cj
approved these changes
Nov 12, 2026
lawrence-cj
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @yuhengcai1, LGTM. This matches the existing clamp in the self-forcing sampler.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A positive
num_cached_blockslarger than the available history makes five legacy LongSANA cache accumulators start at a negative Python list index. For example, with three cache slots while processing chunk 1, a window of 4 counts chunk 0 twice; a window of 5 raisesIndexError. Short videos can therefore produce incorrect history totals or fail with a larger configured cache window.Clamp the window start to zero in the five accumulators, matching the existing streaming/self-forcing helpers. Add 45 parameterized regression cases across all five owners covering oversized windows, bounded windows, full-history settings (zero and negative), and the first chunk. The tests also check current-cache identity, previous convolution-state reuse, and that historical cache entries are not mutated.
Validation against main
b3bad9563288b5fd0dc5734fc230827acf70f23e:git diff --checkpass.Validation scope: the standalone runner compiles the exact production method and submitted test function definitions while isolating unrelated model imports, then runs the 45 cases in each dtype. It does not construct pretrained models or validate the full Sana dependency/import setup or end-to-end video generation. Source hashes and per-case results were captured. The committed test uses normal project imports.
Related to #345: this bounds bug was found while tracing the cache path discussed there. The attention writer already correctly stores chunk-local statistics before adding history; this PR preserves that behavior and does not implement the proposed writer reordering or close that issue.