fix: initialize buffer_b before for-loop to prevent NameError - #101
Open
Jackie2049 wants to merge 1 commit into
Open
fix: initialize buffer_b before for-loop to prevent NameError#101Jackie2049 wants to merge 1 commit into
Jackie2049 wants to merge 1 commit into
Conversation
`buffer_b: torch.Tensor` is type-annotated inside the outer for-loop (line ~825). If the loop never executes (e.g. zero-length iteration), the name `buffer_b` is never bound. The `del buffer_b` at line ~864 then raises `NameError: name 'buffer_b' is not defined`. Fix: initialize `buffer_b: torch.Tensor | None = None` before `try:`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
buffer_b: torch.Tensoris declared inside the outerforloop body. If the loop never executes (e.g.max_len == 0when all buckets are empty), the namebuffer_bis never bound. Thedel buffer_bin the cleanup path then raisesNameError: name 'buffer_b' is not defined.Fix
Initialize
buffer_b: torch.Tensor | None = Nonebefore thetry:block so the name is always bound regardless of loop execution.Key Change
checkpoint_engine/ps.pyTesting
Unit tests pass on 8×RTX 4090 (56/56).