hooks/pyramid_attention_broadcast: remove redundant iteration==0 guard and fix stale cache VRAM leak#13497
Open
GitGlimpse895 wants to merge 1 commit intohuggingface:mainfrom
Open
Conversation
6 tasks
5862b50 to
7eee423
Compare
…d and fix stale cache VRAM leak
7eee423 to
c971e07
Compare
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.
What does this PR do?
Fixes two bugs in
PyramidAttentionBroadcastHook.new_forward:1. Redundant
iteration == 0conditionAfter every
reset_state(), bothiterationandcacheare reset to0andNonerespectively. So at iteration 0,self.state.cache is Noneis alwaysTrue, makingself.state.iteration == 0permanently dead code that creates a misleading impression of two independent invariants.2. Stale cache leaking GPU VRAM
When outside the active timestep range, the hook was unconditionally writing
self.state.cache = output, holding a full hidden-state activation tensor on GPU until the next generation'sreset_state()call. For video transformers with dozens of PAB-hooked layers, this accumulates hundreds of MBs of unreleased VRAM. The fix setsself.state.cache = Noneimmediately when outside the range.This is a re-submission of #13467 (accidentally self-closed). Apologies for the noise, @sayakpaul!
Checklist
Who can review?
@sayakpaul @DN6