Repository navigation
Fused preference loss: fall back when a global forward hook is registered - #733
Open
Imagineer99 wants to merge 3 commits into
Open
Imagineer99 wants to merge 3 commits into
Imagineer99 wants to merge 3 commits into
Conversation
…ered unslothai#14788 made _output_head refuse the fused kernel when the head has module backward hooks or a global full-backward (pre-)hook is registered, since the kernel never calls the head module. The global forward tables were left out: register_module_forward_hook / register_module_forward_pre_hook fire on every nn.Linear in TRL's stock forward, so with one registered the fused path silently skipped a hook that rewrites the head's input or output. Check those two tables in the same gate. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Owner
Author
|
@codex review |
1 similar comment
Owner
Author
|
@codex review |
Imagineer99
changed the base branch from
fix/mirror-base-20261029
to
fix/mirror-base-20261030
October 30, 2026 11:18
Owner
Author
|
@codex review |
1 similar comment
Owner
Author
|
@codex review |
Imagineer99
changed the base branch from
fix/mirror-base-20261030
to
fix/mirror-base-16090-20261030
October 30, 2026 11:57
Owner
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. Keep it up! 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.
What
_output_headinunsloth/models/dpo.pydecides whether DPO / ORPO / CPO underUNSLOTH_FUSED_PREFERENCE_LOSS=1may read the head's weight directly instead of calling the head module. unslothai#14788 added the module backward hooks and the global full-backward (pre-)hook tables to that gate, because the kernel never calls the head and so none of its hooks fire. The global forward tables were left out:torch.nn.modules.module.register_module_forward_hook/register_module_forward_pre_hookfire on everynn.Linearin TRL's stock forward, the head included, so with one registered (activation capture, profiling, a hook that rewrites the head's input or output) the fused path was still taken and the hook silently skipped. Same defect class unslothai#14788 closed, one table over.How
_global_module_backward_hooksbecomes_global_module_hooksand also checks_global_forward_hooksand_global_forward_pre_hooks; the gate's call site follows. The_with_kwargs/_always_calledtables are keyed by the same hook ids, so the two main tables cover them. Nothing else changes: per-module hooks,_hf_hook, overriddenforwardand subclassed heads were already refused.Verification
tests/test_fused_preference_loss.py::test_hooked_or_custom_head_falls_backgainsglobal_forward_hookandglobal_pre_hookcases (registered through the torch module-level API, removed by a finalizer). Each asserts_output_headreturns(None, None), the hidden-states path is not taken, and the loss equals TRL's stock path with the hook honoured.(None, None)assert)Whole file on CPU with the zoo kernels: 27 passed, 53 skipped (the skips are the GPU rows).
ruff check,enforce_kwargs_spacing.pyand theruff-format-with-kwargshook pass;dpo.pyparses under Python 3.9.🤖 Generated with Claude Code
Mirror of unslothai#15226 by @lonexreb, opened for review only.
Do not merge here. Fixes agreed on this mirror must be applied to the source PR.
Source description digest at mirror time:
0eefe0c250d4Prepared against upstream main
316e5757fe7b541d6172498a7bee2076be9d941b.Original PR replay only; no new product edits.
Validation: 80 fused preference-loss CPU tests passed; no skips.
Latest CI base: upstream main
4e799e0fdc09fa3757674fa8c513b9773f7a2b08at mirror head09abfec28c3203b1f7510f90122d9f3e24d9b021. The PR diff is byte-for-byte unchanged after integration. 80 targeted tests pass with no skips. This includes main's existing correction for the media-turn source-contract assertion; no unrelated test patch was added to this PR.Current CI base: upstream
754bd217dcb1bff4c7f358075615ba743a2a3d8a(the test-only unslothai#16090 correction). The translated-label and runtime-list expectations now come from upstream; 248 affected tests pass. The net PR diff remains byte-for-byte unchanged by this base integration. Current mirror head:11c391d19cc40ba5d3e3c02193f5a4bb77637003.