Repository navigation
GRPO rollout scope: off for async tools that call vLLM; leak probe child mode - #18634
Merged
Merged
Conversation
TRL runs async tools on its event-loop thread while _generate blocks on the result. The rollout scope keeps the fold, and with it the merged-rollout lock, for the whole _generate, so an async tool that called a vLLM engine waited on that lock forever. Fold per call when any tool is async.
… own mode modules() yields a shared child once, so restoring a later parent with a recursive train() flipped the child again (an eval-mode shared Dropout came back in training mode). After each module's own train() runs, set every saved flag directly.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Follow-up fixes for #18452, #18438, found while re-checking the PRs merged on 2026-11-19. One commit per fix; every fix has a test that fails on main and passes here.
Tests (this branch vs main
54af93780b, CPU)prepush_gate.pypasses.GRPO rollout scope: off when a tool is async (deadlock) (follows up #18452)
What broke
#18452 wraps TRL's tool-calling
_generateinvllm_rollout_scopeby default (zoo #2610). The scope keeps the merged-rollout fold entered, and with it the process-wide_MERGED_ROLLOUT_LOCK, until_generatereturns. TRL 1.18 runs async tools on its event-loop thread throughasyncio.run_coroutine_threadsafe(...).result()(trl/trainer/grpo_trainer.py:2128) while the main thread waits. An async tool that calls a vLLM engine wrapped for merged rollouts needs that lock, and the main thread holding it is waiting on the tool. So the rollout hangs with no error. This applies both to the policy's own engine (an agent that asks the policy a sub-question) and to another engine.Repro (CPU, zoo merged-rollout test doubles, TRL-style async tool on a separate event-loop thread, 2 s timeout)
DEADLOCK(the async tool blocks on the lock held by the scope)['out']Fix
_unsloth_rollout_scopereturns a null context when any tool is async, checking both TRL's per-batch_async_tool_dictsandinspect.iscoroutinefunctionovertrainer.tools. Each engine call then folds and restores on its own, as before #18452. Rollouts with sync tools only keep the scope.Flip test
tests/test_grpo_rollout_scope.py:test_scope_stays_off_with_an_async_tool[tools|per_batch_dicts]: main 2 failed, branch passedtest_scope_still_on_with_sync_tools_onlypasses on bothGRPO packing leak probe: a child shared by two parents (follows up #18438)
What broke
The GRPO packing leak probe (#18438) saves each module's mode and restores it through
module.train(mode)inmodules()order.modules()yields a child shared by two parents only once. So when the later parent was in training mode, its recursivetrain(True)switched the shared child back on after the child's own restore had run. Example: oneDropoutshared by two decoder blocks and kept in eval mode came back from the probe withtraining == True, so its dropout stayed active for the rest of training.Fix
After each module's own
train(mode)runs (this keeps side effects such asInt4PackedLinearsyncing its quant state), every saved flag is set directly once more.Flip test
tests/test_grpo_packing_leak_probe.py::test_probe_restores_a_child_shared_by_two_parents(tiny Llama on CPU, one Dropout shared by layers 0 and 1):Not proven here
A real GRPO run with an async tool calling fast_generate (vLLM on GPU); the deadlock is shown with the real scope and lock on CPU.