Skip to content

GRPO rollout scope: off for async tools that call vLLM; leak probe child mode - #18634

Merged
danielhanchen merged 2 commits into
mainfrom
kr4b-grpo-rollout-scope
Nov 20, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
kr4b-grpo-rollout-scope

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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.

Fix Follows up Severity
GRPO rollout scope: off when a tool is async (deadlock) #18452 P1
GRPO packing leak probe: a child shared by two parents #18438 P2

Tests (this branch vs main 54af93780b, CPU)

  • New and changed tests: main 3 failed / 20 passed, this branch 23 passed. Each test loads the code of its own tree.
  • Neighbouring suites on this branch: rollout scope, packing probe and boundary leak suites: 44 passed, 2 skipped.
  • prepush_gate.py passes.

GRPO rollout scope: off when a tool is async (deadlock) (follows up #18452)

What broke

#18452 wraps TRL's tool-calling _generate in vllm_rollout_scope by default (zoo #2610). The scope keeps the merged-rollout fold entered, and with it the process-wide _MERGED_ROLLOUT_LOCK, until _generate returns. TRL 1.18 runs async tools on its event-loop thread through asyncio.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)

  • main: DEADLOCK (the async tool blocks on the lock held by the scope)
  • this branch: completes, ['out']

Fix

_unsloth_rollout_scope returns a null context when any tool is async, checking both TRL's per-batch _async_tool_dicts and inspect.iscoroutinefunction over trainer.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 passed
  • test_scope_still_on_with_sync_tools_only passes on both
  • File total on the branch: 11 passed

GRPO 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) in modules() order. modules() yields a child shared by two parents only once. So when the later parent was in training mode, its recursive train(True) switched the shared child back on after the child's own restore had run. Example: one Dropout shared by two decoder blocks and kept in eval mode came back from the probe with training == 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 as Int4PackedLinear syncing 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):

  • main: failed
  • this branch: passed
  • The full leak-probe and boundary-blind files pass: 19 passed.

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.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T13:56:14.483040Z a905cf0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: a905cf0283

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen
danielhanchen merged commit 3bce692 into main Nov 20, 2026
@danielhanchen
danielhanchen deleted the kr4b-grpo-rollout-scope branch November 20, 2026 16:19
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