Repository navigation
Patch the TRL trainers that moved to trl.experimental (ORPO, CPO, Online DPO, GKD, ...) - #12097
Conversation
TRL 0.29 moved ORPO, CPO, GKD, PPO, Online DPO, Nash-MD, XPO, BCO and PRM out of trl.trainer into trl.experimental.<name>, so the trl.trainer walk in patch_trl_rl_trainers never generated Unsloth<Name>Trainer or Config for them. Run the same pipeline on those modules and rebind the experimental namespaces. The modules are imported before the walk rebinds SFTTrainer, so GKDTrainer keeps TRL's own base class regardless of import order.
Codex Review SummaryThis 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. |
|
@codex review |
Codex Review SummaryThis 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. |
|
@codex security review |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
…ine DPO, GKD, ...) (unslothai#12097) * Patch TRL trainers that moved to trl.experimental TRL 0.29 moved ORPO, CPO, GKD, PPO, Online DPO, Nash-MD, XPO, BCO and PRM out of trl.trainer into trl.experimental.<name>, so the trl.trainer walk in patch_trl_rl_trainers never generated Unsloth<Name>Trainer or Config for them. Run the same pipeline on those modules and rebind the experimental namespaces. The modules are imported before the walk rebinds SFTTrainer, so GKDTrainer keeps TRL's own base class regardless of import order. * Test that trl.experimental trainers are patched and GKD keeps its base * Run the trl.experimental patch test in version-compat CI
TRL 0.29 moved ORPO, CPO, Online DPO, GKD, PPO, Nash-MD, XPO, BCO and PRM out of
trl.trainerintotrl.experimental.<name>. Unsloth only walkstrl.trainer, so on TRL 0.29+ none of these trainers get Unsloth's patched trainer / config (padding-free, fused loss, the #12069 sequence length clamp, the config default contract, and so on), while they were all patched on TRL 0.28 and older.trl.experimentaltrl.trainer)Changes
_import_trl_experimental_trainers()importstrl.experimental.<name>.<name>_trainerfor each of those names that is not undertrl.trainer(TRL's experimental warning suppressed, missing modules skipped)._patch_trl_experimental_trainer()runs the existingtrl.trainerpipeline through temporarytrl.traineraliases, rebinds the patched classes ontrl.experimental.<name>and its config module, then removes the aliases, sotrl.ORPOTrainerand friends stay absent as in TRL.trl.trainerwalk. On main,GKDTrainer(SFTTrainer)picked upUnslothSFTTraineras its base or TRL'sSFTTrainerdepending on whether the user imported it before or after Unsloth; now it is alwaysUnslothGKDTrainer -> _UnslothGKDTrainer -> SFTTrainer.trainer.__name__instead of the hardcodedtrl.trainer.<file>(same value for existing trainers), and the thin wrapper resolution skips classes defined intrl.experimentalitself, soNashMDTrainer(OnlineDPOTrainer)is not patched as its parent.Every trainer Unsloth already generated (SFT, DPO, GRPO, KTO, RLOO, Reward) is byte-identical before and after on TRL 0.22.2, 0.25.1, 0.27.0, 0.29.0 and 1.14.0; the only new files are the experimental trainers. The extra imports cost about 0.02 s on TRL 1.14 (4 modules) and 0.11 s on TRL 1.0 (9 modules).
Evidence
Two step LoRA smokes on tiny Qwen3, TRL 1.14 unless noted:
UnslothORPOTrainerUnslothCPOTrainerUnslothOnlineDPOTrainerlmbda=0UnslothGKDTrainerUnslothXPOTrainerNash-MD fails the same way in plain TRL on transformers 5.17 (
'GeometricMixtureWrapper' object has no attribute 'get_experts_implementation'), and PPO with an Unsloth model already fails on main, where it is not patched; neither changes here.Tests
New
tests/version_compat/test_trl_experimental_trainers_patched.py(registered in version-compat CI): the experimental trainers and configs are patched,trl.<Name>stays absent, and GKD keeps TRL'sSFTTraineras its base.test_trl_config_defaults_contract.pynow also runs its ORPO, CPO and GKD cases on TRL 0.29+ (they skipped with "Unsloth does not patch ORPOConfig on this TRL") and they pass. The rest oftests/version_compatis unchanged on TRL 1.14 and 0.25.1.