Repository navigation
Keep fused-loss engagement counters out of traced code - #15575
Conversation
The trainer counters (_unsloth_*_chunked_calls / *_fused_calls) were read and written inside the chunked and fused loss helpers. Under torch.compile Dynamo guards on the counter value, so every step recompiled; with fullgraph=True ORPO / CPO hit the recompile limit after 8 steps. Count only when not compiling; eager runs still report engagement. The ORPO decline test also assumed importing unsloth had rebound TRL's ORPOTrainer to the patched class. Where that build fails the stock class has no rewritten method, so the override check has nothing to compare against and the test failed. Build the patched class in the test instead.
The installer wrapped any _ChunkedLogProbFunction whose forward took a bias. TRL main now passes support_ids and score_ids on every call and returns six outputs, so the wrapped apply() raised TypeError before any fallback could run. Compare the forward signature with the contracts the adapter reproduces (TRL 1.14, 1.15 - 1.16, and the support_ids slot) and leave any other kernel, or one whose signature cannot be read, untouched. Tests: a TRL-main-shaped kernel stays TRL's and serves its 11-argument call; the installed TRL kernel (1.14, 1.15, 1.16) is still wrapped and the fused path serves it, matching the float64 reference in value and gradient.
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". |
[skip ci]
…ith TRL [skip ci]
[skip ci]
|
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". |
|
Codex Review: Didn't find any major issues. Swish! 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". |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
Follow-up to #14185. Fused-loss engagement counters were updated inside traced scoring helpers, so repeated calls guarded on an ever-changing Python integer and recompiled until
fullgraph=Truereached the limit.Count engagement only outside tracing. Eager calls still update the counters; compiled calls retain the same loss and gradient calculations. This covers the preference, DPO, KTO, online DPO, GKD, PPO and RLOO scoring helpers.
The branch is synced with main. The original TRL contract-whitelist half has been removed because #16220 already fixes its reported compatibility crash. The fused-head adapter and installer are identical to main, including TRL 1.17 score-ID support.
Validation completed so far:
The tests use small synthetic tensors and random model initialization. No model checkpoint weights are required for the reproductions.