Repository navigation
Fused preference loss test: take TRL's own trainer as the reference - #15269
Merged
Merged
Conversation
Unsloth's RL patch rebinds trl's ORPOTrainer / CPOTrainer / DPOTrainer, and the defining module's attribute, to the generated Unsloth<name>. Since #14185 that class's concatenated_forward takes the fused path, so once TRL had been patched in the process the test's TRL reference ran the code under test, and 16 cases failed on the hidden-states counter and dtype checks against unsloth-zoo main. The reference is now loaded from TRL's own module file under a private name, and the test asserts it is not an Unsloth class.
Member
Author
|
@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 Review: Didn't find any major issues. 👍 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". |
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.
16 cases in
tests/test_fused_preference_loss.pyfail inRepo tests (CPU, rest)on PRs based on current main, for example #15224 and #15245: everytest_orpo_cpo_match_trlcase plus the DDP / FSDP1 / hook fallback cases. The reference run trips the hidden-states counter (assert (1 >= 1) == False) or the dtype check.Cause
The test, not the product. The test builds its reference from
from trl.experimental.orpo import ORPOTrainer(and the CPO / DPO equivalents). Unsloth's RL patch rebinds those names, and the defining module's attribute, to the generatedUnslothORPOTrainer(unsloth/models/rl.py, thetrl.{name} = created_module.Unsloth{name}lines). Since #14185, that generated class'sconcatenated_forwardroutes throughunsloth_fused_orpo_concatenated_forward. So once TRL has been patched in the process, the "TRL" side of the comparison is the code under test. The stack of the reference forward shows it:test_fused_preference_loss.py:437 -> unsloth_compiled_cache/UnslothORPOTrainer.py:1988.It reproduces locally with unsloth-zoo main on the path (16 failed, 9 passed, run alone). With the older installed zoo 2026.10.7, TRL is not rebound here, which is why it looked like an ordering leak at first.
Fix
_trl_trainer(name)loads TRL's own trainer module from its file under a private module name in the same package, so TRL's relative imports still resolve and nothing Unsloth rebinds is reused.Unsloth*class.Verification
tests/test_fused_preference_loss.pyagainst unsloth-zoo main: 16 failed, 9 passed on main; 25 passed here.chosen_logpsby 1.001 inunsloth/models/dpo.pyfails all 10test_orpo_cpo_match_trlcases.