Fix Phi3/Phimoe prepare_inputs_for_generation forwarding logits_to_keep=None#47531
Open
pwasiewi wants to merge 1 commit into
Open
Fix Phi3/Phimoe prepare_inputs_for_generation forwarding logits_to_keep=None#47531pwasiewi wants to merge 1 commit into
pwasiewi wants to merge 1 commit into
Conversation
…ep=None Phi3ForCausalLM and PhimoeForCausalLM override prepare_inputs_for_generation with a logits_to_keep=None default and forward it unconditionally. When GenerationMixin._supports_logits_to_keep() cannot introspect a wrapped forward() (e.g. TRL/PEFT training stacks wrap forward without functools.wraps), generate() never injects its default of 1, so None reaches forward(). There, None as a slice index turns the lm_head slice into an unsqueeze (hidden_states[:, None, :]) producing 4-dim logits, which crashes sampling with "RuntimeError: prob_dist must be 1 or 2 dim" in torch.multinomial. Coerce None -> 1: generation only consumes the last position, and assisted decoding overrides model_inputs["logits_to_keep"] afterwards, so it is unaffected. Phi4Multimodal already avoids this by defaulting to 0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: phi3, phimoe |
Contributor
CI recapDashboard: View test results in Grafana |
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 does this PR do?
Fixes a generation crash in Phi3 and Phimoe: their
prepare_inputs_for_generationoverrides defaultlogits_to_keep=Noneand forward it unconditionally intoforward(). WhenGenerationMixin._supports_logits_to_keep()cannot introspect a wrappedforward()(e.g. TRL/PEFT training stacks wrap forward withoutfunctools.wraps),generate()never injects its default of1, soNonereachesforward()— whereNoneas a slice index turns the lm_head slice into an unsqueeze (hidden_states[:, None, :]), producing 4-dim logits and crashing sampling withRuntimeError: prob_dist must be 1 or 2 dimintorch.multinomial.The fix coerces
None -> 1in the two overrides (modular + regenerated modeling files): generation only consumes the last position, and assisted decoding overridesmodel_inputs["logits_to_keep"]afterwards, so it is unaffected.Phi4Multimodalalready avoids the bug by defaulting to0in its own override; all non-overriding models are unaffected because the kwarg is simply absent.Fixes #47530
Before submitting
make fix-repoconsistency: modular converter regenerates identical files.Who can review?
@gante