Skip to content

GRPO: default to TRL's dapo loss with beta 0, cap CISPO weights at 5.0 - #12088

Merged
danielhanchen merged 1 commit into
mainfrom
grpo-policy-defaults
Sep 27, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
grpo-policy-defaults

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Follow up to #11951 and #12069. Three GRPO defaults move to match TRL and the other RL frameworks.

Changes

Setting Before After
loss_type when unset "bnpo" TRL's own default, "dapo" (TRL >= 0.22). TRL 0.20 / 0.21 stay on "bnpo", since they have no dapo
beta when unset 0.001 0.0 for dapo and dr_grpo, 0.001 otherwise. An explicit beta is always kept
epsilon_high for loss_type="cispo" when unset TRL falls back to epsilon = 0.2 5.0

A default run prints one line saying GRPO now defaults to loss_type = 'dapo' with beta = 0.0, and how to get the previous default back (loss_type = 'bnpo', beta = 0.001).

Token-level loss is the common default now

Framework Default Since
TRL loss_type="dapo" (huggingface/trl#3938) v0.22.0, 2025-08
verl loss_agg_mode="token-mean" (verl-project/verl#623) v0.4.0, 2025-04
SkyRL loss_reduction="token_mean" (skyrl-project/SkyRL#90) 2025-07
open-instruct loss_denominator="token" (allenai/open-instruct#1161) 2025-12
torchtitan divides by global valid tokens (pytorch/torchtitan#3237) 2026-05

The DAPO paper's other two settings (epsilon_high = 0.28, mask_truncated_completions = True) are still filled only when loss_type="dapo" is passed explicitly, exactly as today. TRL does not turn them on for its default either, and masking every truncated row zeroes the whole update when a short max_completion_length truncates every completion (reproduced on the tiny GRPO job: grad norm 0, adapter unchanged).

beta = 0 for dapo and Dr GRPO

TRL has defaulted to beta = 0.0 since v0.19 (huggingface/trl#3516). The DAPO paper removes the KL term. beta = 0 also skips the reference model forward, so memory drops.

CISPO cap

TRL's CISPO loss clamps the importance sampling weight at epsilon_high itself, not 1 + epsilon_high: clamp(coef_1, max=epsilon_high).detach(). With epsilon_high unset, TRL falls back to epsilon = 0.2, so every weight is capped at 0.2 and the gradient shrinks about 5x. 5.0 is the value in TRL's own docs and SkyRL's effective cap, and sits inside the range ScaleRL (arXiv 2510.13786) found equivalent ({4, 5, 8}). An explicit value is kept; one below 1 prints a warning.

Who sees a change

  • GRPO users who never set loss_type on TRL >= 0.22: bnpo -> dapo, beta 0.001 -> 0.0. Clip range and truncation masking are unchanged.
  • Explicit dapo / dr_grpo without beta: 0.001 -> 0.0.
  • cispo without epsilon_high: cap 0.2 -> 5.0.
  • TRL 0.20 / 0.21, anyone setting these values explicitly, and HfArgumentParser / YAML configs (the parser passes TRL's field defaults explicitly): unchanged.

Tests

tests/version_compat/test_trl_config_defaults_contract.py adds cases for the default loss type, the default keeping TRL's clip and truncation settings, beta when unset and when explicit, and the CISPO cap. test_trl_loss_normalization_contract.py now expects dapo on TRL >= 0.22.

Base (main) vs this branch, contract files plus the preference clamp file:

TRL main this PR
0.21.0 1 failed, 50 passed 51 passed
0.22.2 4 failed, 50 passed 54 passed
0.25.1 4 failed, 56 passed 60 passed
1.14.0 5 failed, 52 passed 57 passed

jobs/grpo.py --tiny --backend unsloth --max-steps 5 with a fresh compile cache passes on both sides for the default, dr_grpo and cispo runs; losses are finite, 0 graph breaks on both sides, and unique graphs drop from 10 to 7 with beta = 0 because the reference forward is skipped. cispo grad norm rises from 0.0075 to 0.0373, which is the removed 0.2 cap.

… 5.0

loss_type and beta now default to None sentinels resolved in the generated
config: loss_type -> "dapo" on TRL >= 0.22 (TRL's default since
huggingface/trl#3938; older TRL has no dapo and passes no num_items_in_batch,
so "bnpo" stays there), beta -> 0.0 for dapo / dr_grpo and 0.001 otherwise.
Explicit values are kept. Only an explicit loss_type="dapo" gets the DAPO
paper's epsilon_high = 0.28 and mask_truncated_completions = True; the default
keeps TRL's, since masking every truncated row zeroes the update when all rows
are truncated.

CISPO: TRL clamps the IS weight at epsilon_high itself, and an unset
epsilon_high falls back to epsilon = 0.2, capping every weight below 1. Default
it to 5.0 (ScaleRL eps_max, TRL's documented recipe, SkyRL's 1 + 4) and warn on
an explicit value below 1.

An unsloth_zoo without unsloth-zoo#1369 divides dapo / cispo / vespo by the
whole generation batch; rescale num_items_in_batch to one accumulation window
in that case so steps_per_generation != gradient_accumulation_steps matches
TRL (huggingface/trl#6024).
@danielhanchen danielhanchen self-assigned this Sep 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 27, 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 ✅ Completed 2026-09-27T05:46:43.667366Z b0b3de7 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

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: b0b3de7d4a

ℹ️ 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 a9982dc into main Sep 27, 2026
38 of 40 checks passed
@danielhanchen
danielhanchen deleted the grpo-policy-defaults branch September 27, 2026 11:45
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
… 5.0 (unslothai#12088)

loss_type and beta now default to None sentinels resolved in the generated
config: loss_type -> "dapo" on TRL >= 0.22 (TRL's default since
huggingface/trl#3938; older TRL has no dapo and passes no num_items_in_batch,
so "bnpo" stays there), beta -> 0.0 for dapo / dr_grpo and 0.001 otherwise.
Explicit values are kept. Only an explicit loss_type="dapo" gets the DAPO
paper's epsilon_high = 0.28 and mask_truncated_completions = True; the default
keeps TRL's, since masking every truncated row zeroes the update when all rows
are truncated.

CISPO: TRL clamps the IS weight at epsilon_high itself, and an unset
epsilon_high falls back to epsilon = 0.2, capping every weight below 1. Default
it to 5.0 (ScaleRL eps_max, TRL's documented recipe, SkyRL's 1 + 4) and warn on
an explicit value below 1.

An unsloth_zoo without unsloth-zoo#1369 divides dapo / cispo / vespo by the
whole generation batch; rescale num_items_in_batch to one accumulation window
in that case so steps_per_generation != gradient_accumulation_steps matches
TRL (huggingface/trl#6024).
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
…rch (unslothai#12274)

* tests: skip two version_compat suites where the daily sweep has no torch

daily-fresh-fetch in version-compat-ci.yml runs all of tests/version_compat/
after installing nothing but pytest. The other suites there that need torch
skip in that job, eight of them on a module-scope find_spec("torch") guard, and
two of those say why: "daily-fresh-fetch collects this directory with only
pytest installed." test_trl_config_defaults_contract.py (unslothai#12069, unslothai#12088) and
test_pref_max_length_clamp.py (unslothai#12069) have no guard. They pass in
grpo-fake-run, which installs torch, and in the sweep every `import unsloth`
stops at unsloth/_gpu_init.py's `import numpy`.

The sweep passed daily up to 2026-09-26 and has failed daily since unslothai#12069
merged: 43 failed on 09-28 and 09-29, all 43 in these two files on that
ModuleNotFoundError. The 09-27 run exited 1 and its log has expired.

The defaults contract imports unsloth in every test, so it takes its
neighbours' guard at module scope. In the clamp file seven tests read rl.py as
text and still run in the sweep, so only test_patched_trainer_carries_the_clamp,
which imports unsloth and trl, is guarded.

test_the_daily_sweep_skips_what_it_cannot_import runs every suite the sweep
collects outside the pip-free bundle in a subprocess with torch, numpy,
transformers, trl, peft, accelerate and unsloth_zoo hidden, and fails on any
test that fails rather than skips. workflow-trigger-lint runs that file on
every pull request with no torch installed, so a suite added without the guard
now fails its own pull request instead of the next morning's cron. It fails on
main with the sweep's 43 tests and passes here.

One consequence worth naming: the new test adds about 2 s to
workflow-trigger-lint on every pull request, measured in that job's environment.

* Tighten comments in the version-compat sweep guard

---------

Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant