Skip to content

[rollout] fix: memory release bug#5917

Open
hustmf wants to merge 1 commit intoverl-project:release/v0.7.1from
hustmf:v0.7.1-fix
Open

[rollout] fix: memory release bug#5917
hustmf wants to merge 1 commit intoverl-project:release/v0.7.1from
hustmf:v0.7.1-fix

Conversation

@hustmf
Copy link
Copy Markdown
Contributor

@hustmf hustmf commented Apr 8, 2026

What does this PR do?

The tensor variable introduced by pr https://github.com/verl-project/verl/pull/5173/changes will lead to possible memory release bug. The vllmworker will hold the tensor when enabling sleep mode

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward, fully_async, one_step_off
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the weight transfer cleanup logic in bucketed_weight_transfer.py. The review feedback highlights a potential NameError due to the removal of the tensor initialization and suggests a more effective way to release memory by using weights.clear() instead of iterating through the list to delete local references.

while True:
metadata = self.socket.recv_pyobj()
weights, tensor = [], None
weights = []
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Initializing tensor to None is recommended to ensure the variable is defined in the function scope. This prevents a potential NameError during the cleanup phase (line 261) if the bucket metadata is empty and the loop at line 243 never executes.

Suggested change
weights = []
weights, tensor = [], None

Comment on lines +258 to +261
for _, tensor in weights:
del tensor
weights.clear()
del weights
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The loop iterating over weights to call del tensor is ineffective for releasing memory of the objects within the list; it only unbinds the local loop variable in each iteration. To properly release the tensors and address the memory issue, weights.clear() should be used. This ensures that even if external references to the weights list exist (e.g., within the callback), the tensors themselves can be garbage collected. A single del tensor is then sufficient to clear the reference leaked from the previous loop.

Suggested change
for _, tensor in weights:
del tensor
weights.clear()
del weights
weights.clear()
del weights, tensor

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.

2 participants