Repository navigation
FastLanguageModel.for_training: undo the UNSLOTH_RETURN_LOGITS=1 that generate() forces - #13392
Merged
Merged
Conversation
… FastModel generate() forces
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. |
Member
Author
|
@codex review |
|
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 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.
Follow-up to #13311.
FastLanguageModelloads Qwen3.5, Gemma 3, Gemma 4 and other models throughFastModel, so theirgenerate()runsFastBaseModel.for_inference(), which setsUNSLOTH_RETURN_LOGITS=1(saving the previous value in_UNSLOTH_RETURN_LOGITS_BEFORE_INFERENCE).FastModel.for_training()restores it, butFastLanguageModel.for_training()(the Llama-path method) never touched it, so the common notebook flow of trying the model and then training left it at1:Unsloth: packing=True ignored (UNSLOTH_RETURN_LOGITS=1).Change
FastLlamaModel.for_training()now undoes only the valuefor_inference()forced, exactly asFastBaseModel.for_training()does since #13311: it pops_UNSLOTH_RETURN_LOGITS_BEFORE_INFERENCEand restores it when present. AUNSLOTH_RETURN_LOGITS=1the user set themselves is left alone, and models loaded on the Llama path (whosegenerate()never sets the flag) are unaffected.Before / after
Tiny Gemma 3 text model,
FastLanguageModel.from_pretrained, LoRA,for_inference,generate(),FastLanguageModel.for_training, thenSFTTrainer(..., packing=True)(torch 2.14, transformers 5.17, TRL 1.13):UNSLOTH_RETURN_LOGITSafterfor_training1packing=True ignored (UNSLOTH_RETURN_LOGITS=1), padded rows0The same sequence through
FastModelalready gives0on main.Tests
tests/test_return_logits_survives_for_training.pyliftsFastLlamaModel.for_trainingthe same way the file already lifts theFastBaseModelmethods: afterFastBaseModel.for_inference()it restores an unset,"0"or"1"previous value, and it leaves a user-set1alone. Without the change the two undo cases fail. The file passes on torch 2.14 + transformers 5.17 and torch 2.7.1 + transformers 4.57.6.