Skip to content

fix: initialize buffer_b before for-loop to prevent NameError - #101

Open
Jackie2049 wants to merge 1 commit into
MoonshotAI:mainfrom
Jackie2049:fix/buffer-b-nameerror
Open

fix: initialize buffer_b before for-loop to prevent NameError#101
Jackie2049 wants to merge 1 commit into
MoonshotAI:mainfrom
Jackie2049:fix/buffer-b-nameerror

Conversation

@Jackie2049

Copy link
Copy Markdown

Problem

buffer_b: torch.Tensor is declared inside the outer for loop body. If the loop never executes (e.g. max_len == 0 when all buckets are empty), the name buffer_b is never bound. The del buffer_b in the cleanup path then raises NameError: name 'buffer_b' is not defined.

Fix

Initialize buffer_b: torch.Tensor | None = None before the try: block so the name is always bound regardless of loop execution.

Key Change

File Line Change
checkpoint_engine/ps.py 801 Add `buffer_b: torch.Tensor

Testing

Unit tests pass on 8×RTX 4090 (56/56).

`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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant