Repository navigation
GRPO: one vLLM rollout scope per tool-calling generate - #18452
Merged
Merged
Conversation
TRL's tool loop calls the engine once per turn with unchanged weights, and Unsloth hands every call a fresh load_lora, so each turn folded and restored the adapter and dropped vLLM's prefix cache. Run _generate inside unsloth_zoo's vllm_rollout_scope when tools are set, vLLM shares the training weights and no custom rollout_func runs. Off with UNSLOTH_VLLM_ROLLOUT_SCOPE=0 and a no-op on an older unsloth_zoo.
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. Keep it up! 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". |
oobabooga
pushed a commit
to oobabooga/unsloth
that referenced
this pull request
Nov 20, 2026
…ild mode (unslothai#18634) Follow-up fixes for unslothai#18452, unslothai#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) | unslothai#18452 | P1 | | GRPO packing leak probe: a child shared by two parents | unslothai#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 unslothai#18452) #### What broke unslothai#18452 wraps TRL's tool-calling `_generate` in `vllm_rollout_scope` by default (zoo unslothai#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 unslothai#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 unslothai#18438) #### What broke The GRPO packing leak probe (unslothai#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.
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.
Summary
Runs TRL's GRPO
_generateinside unsloth-zoo's newvllm_rollout_scope, so a multi-turn tool rollout folds the adapter and resets the prefix cache once per rollout instead of once per vLLM call (companion PR: unslothai/unsloth-zoo#2610). Engaged only when tools are set, vLLM shares the training weights, and there is no customrollout_func(one could run the training model while the weights are folded).UNSLOTH_VLLM_ROLLOUT_SCOPE=0turns it off; with an older unsloth-zoo it does nothing.Tests
8 tests (2 fail on main, 8 pass here), including the wrapper applied to real TRL 0.24.0 and 1.18.0
_generatesource; the generatedUnslothGRPOTrainer.pycompiles. Correctness and Colab T4 numbers (-7.0% merged rollout, -6.9% vLLM LoRA on a 4-turn tool loop) are in the zoo PR.Not covered
No full GRPOTrainer run with tools on a GPU.