Skip to content

Let TRL AsyncGRPOTrainer train Unsloth models; fix GRPO vision rewards for tool images and TRL 1.15 - #13205

Merged
danielhanchen merged 6 commits into
mainfrom
trl-async-grpo
Oct 10, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
trl-async-grpo

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Two things for agent RL with TRL's newer trainers.

1. trl.experimental.async_grpo.AsyncGRPOTrainer with Unsloth models

On main it rejects any model object: TRL only takes a model id and loads it with flash-attn 3. patch_trl_async_grpo (called from PatchFastRL):

  • passes a loaded (PEFT) model through and derives the default config from its name (positional or keyword None config);
  • puts TRL's fused LM head under the PEFT wrapper, not on it (TRL 1.14's chunked head too);
  • packed rows: AsyncGRPO packs several sequences per row, and Unsloth's attention cannot see position_ids resets, so sequences attended to each other. Unsloth backbones now get per-sequence lengths from position_ids. Scoring one sequence inside a packed row vs alone: logprobs differed by up to 4.70 before, identical after. A non-Unsloth model on sdpa gets a clear error instead of silently wrong training; flash attention is left to TRL;
  • hands the spawned rollout worker a tokenizer without instance-bound methods, so it pickles.

3 steps, Qwen3-0.6B LoRA, vLLM server on a second GPU: finite losses, ~55 sequences per row, the LoRA adapter synced to the server 7 times. Needs TRL >= 1.14 (1.13's AsyncGRPO has no LoRA support), so it pairs with #13203.

2. GRPO vision reward inputs

Unsloth rewrites TRL's reward call to prompts_text / completions_text when images are present. TRL's tool-image branch never builds prompts_text (every image-returning tool crashed on its first tool round), and TRL 1.15 dropped completions_text (every image GRPO run would crash on 1.15). The rewrite now keeps TRL's inputs when prompts_text is absent and rebuilds completions_text the way TRL 1.13 did; TRL 1.13 behaviour is unchanged. Qwen3-VL-2B with a tool returning an image: 8 tool calls, tool images reach the model.

Also checked, no change needed

OpenReward (local server from the SDK) and Harbor (HarborBashEnv with a fake sandbox) environments through environment_factory work as-is with fast_inference False and True.

Tests: tests/test_async_grpo_patch.py, tests/test_grpo_vision_reward_inputs.py (CPU). Regression smoke A/B (merge base vs this stack, TRL 1.13): 0 regressions.

Related: #10580, #3528

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-10T07:40:54.029651Z 094d9f2 New commits
ℹ️ 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

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: f3f402b77c

ℹ️ 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

Copy link
Copy Markdown
Member Author

pre-commit.ci run

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