Repository navigation
[BUGFIX] Validate save methods before selecting export paths - #18710
Merged
danielhanchen merged 6 commits intoNov 23, 2026
Merged
Conversation
Member
|
@codex review |
Codex Review Summary: ❌ FailedThis 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. Can't wait for the next one! 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 was referenced Nov 23, 2026
This was referenced Nov 23, 2026
danielhanchen
added a commit
to unslothai/unsloth-zoo
that referenced
this pull request
Nov 23, 2026
…n-module heads (#2706) ## Summary Every `Core zoo` leg of the unsloth CI is red against current zoo `main` (seen on unslothai/unsloth#18710), and the same tests fail locally on `main`: ``` tests/test_fused_lm_head_peft_adapter.py::test_ast_rewritten_forward_trains_the_head_adapter[False] tests/test_fused_lm_head_peft_adapter.py::test_ast_rewritten_forward_trains_the_head_adapter[True] E assert 1728 == 0 (out.logits.numel()) tests/test_per_device_gpu_detection.py::test_the_shared_adapter_skips_inductor_for_a_head_on_an_old_card tests/test_per_device_gpu_detection.py::test_the_shared_adapter_checks_the_head_after_fsdp_unshards_it E AttributeError: 'types.SimpleNamespace' object has no attribute 'modules' ``` Both already fail at the merge commit of #2697. ## Root cause #2688 and #2697 each added a way to keep a live PEFT adapter on `lm_head` out of the fused kernel, and they landed an hour apart: - #2688 put a guard in the AST rewriter's condition (`base_layer is not None and merged == disable_adapters`), sending such a head down the stock path, which returns the full `[tokens, vocab]` logits. - #2697 made `unsloth_fused_lm_head_loss` itself detect a live adapter (`lm_head_needs_module_forward`) and score the head's own forward, then return `EMPTY_LOGITS` like the compiler path. Its test of the AST path expects that route, but #2688's guard catches the head first. - `lm_head_needs_module_forward` walks `lm_head.modules()`, which a head object that is not an `nn.Module` (the shared adapter tests pass a `SimpleNamespace` head) does not have. ## Fix - `fused_losses/ast_rewriter.py`: drop the AST guard. `_lm_head_module_reason` covers both states it caught (merged and disabled, unmerged and enabled) and more: it walks every tuner in the head, and `_module_head_ce_loss` applies the same bias, scale and softcap as the kernel. One route for live adapters, and the AST and compiler paths now both return `EMPTY_LOGITS` under `UNSLOTH_RETURN_LOGITS=0`. - `fused_losses/cross_entropy_loss.py`: `lm_head_needs_module_forward` returns `False` for a head that is not an `nn.Module`; only a module can carry a PEFT tuner. - Tests: `test_fused_lm_head_coverage.py` pinned the old condition text, and `test_merged_then_disabled_peft_head_takes_the_exact_path` used non-empty logits as its route probe. Both now check the new route; the latter still asserts the base loss and that the head was unmerged. ## Testing - The four failing tests above pass, plus the whole fused-loss family (`tests/test_fused_*.py`, the GRPO fused route tests, `test_trl_fused_head_contract.py`, `test_per_device_gpu_detection.py`, `test_inkling2_*.py`): 826 passed, 204 skipped. - Sabotage: making `lm_head_needs_module_forward` always return `False` fails 43 tests in `test_fused_lm_head_peft_adapter.py` and `test_inkling2_fused_softcap_ce.py`, so the single route is guarded. Not covered here: on the `HF=latest` leg (transformers 5.24) `test_inkling_forwards_fuse_with_the_module_softcap` also fails because the Inkling 2 forward is not routed to the AST rewriter at all; that is a separate transformers 5.24 port.
danielhanchen
marked this pull request as ready for review
November 23, 2026 13:40
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.
Problem: In
unsloth_generic_save, an unrecognizedsave_methodon a non-PEFT model silently fell through to full-checkpointsave_pretrained, and theforced_merged_4bitalias was accepted at merge dispatch without being folded alongsidemerged_4bit_forcedinunsloth_generic_saveandunsloth_save_model.Fix: Added up-front
save_methodvalidation inunsloth_generic_savebefore routing or Hub pushes, and normalized bothmerged_4bit_forcedandforced_merged_4bitconsistently inunsloth_generic_saveandunsloth_save_model.Tests: Expanded
tests/saving/test_save_method_lora_routing.pyfor invalidsave_methodrejection on PEFT, non-PEFT, and Hub-push paths plus alias normalization; 162 passed acrosstests/saving/test_save_method_lora_routing.pyandtests/test_merged_hub_destination.py,ruff checkclean.