fix: rename loop variable to avoid shadowing outer data in CriticWorker.train_step#375
Open
dubin555 wants to merge 1 commit intoalibaba:mainfrom
Open
fix: rename loop variable to avoid shadowing outer data in CriticWorker.train_step#375dubin555 wants to merge 1 commit intoalibaba:mainfrom
data in CriticWorker.train_step#375dubin555 wants to merge 1 commit intoalibaba:mainfrom
Conversation
In CriticWorker.train_step and diffusion ActorWorker.train_step, the
for-loop used `data` as both the outer batch variable and the loop
iteration variable. After the loop, `data.to("cpu")` only moved the
last mini-batch to CPU instead of the full batch, causing GPU memory
to not be properly released.
Rename the loop variable from `data` to `mini_batch` so the outer
`data` variable remains intact for proper cleanup after the loop.
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
In
CriticWorker.train_step(roll/pipeline/base_worker.py) andActorWorker.train_step(roll/pipeline/diffusion/reward_fl/actor_worker.py), the for-loop variabledatashadows the outerdataparameter:After the loop,
datapoints to the last yielded mini-batch instead of the original full batch. The subsequentdata.to("cpu")only moves the last mini-batch to CPU, leaving the original full batch allocated on GPU — causing a memory leak that accumulates over training steps.Fix
Rename the loop variable from
datatomini_batchso the outerdatareference is preserved:Files Changed
roll/pipeline/base_worker.py— CriticWorker.train_steproll/pipeline/diffusion/reward_fl/actor_worker.py— ActorWorker.train_steptests/test_train_step_variable_shadow.py— AST-based regression test