fix(llama4): honour skip_logits in lce_forward - #1445
Open
yupengtang wants to merge 2 commits into
Open
yupengtang wants to merge 2 commits into
yupengtang wants to merge 2 commits into
Conversation
linkedin#704 added `skip_logits` so callers can pick between the fused loss and materialised logits, and swept every model that existed at the time. llama4 landed a month later in linkedin#740 and never picked it up - it is now the only one of the 42 forwards under transformers/model/ without the parameter, and it still hardcodes `self.training and (labels is not None or shift_labels is not None)`. Because the signature does not name it, `skip_logits` falls into `**kwargs` and is ignored, so `skip_logits=False` during training takes the fused path anyway and returns `logits=None`. Mirrors mllama, which has the same LigerForCausalLMLoss shape. The default (`skip_logits=None`) evaluates to the previous condition, so nothing changes for callers that do not pass it.
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.
Summary
llama4.lce_forwardis the only one of the 42 forwards undertransformers/model/that has noskip_logitsparameter. It still decides on its own:#704 added
skip_logitsprecisely so a caller could override that, and swept every model that existed on 2025-05-23. llama4 arrived a month later in #740 and never picked it up; everything added since has it.Because the signature does not name it, a
skip_logitsargument lands in**kwargsand is silently ignored, soskip_logits=Falseduring training still takes the fused path and returnslogits=None. That is the one thing the flag exists to prevent, and the convergence harness relies on it, settingeval_batch["skip_logits"] = Falsebefore readingeval_output.logits.The change mirrors
mllama, which has the identicalLigerForCausalLMLossshape.skip_logits=Noneevaluates to the previous condition, so nothing moves for callers that do not pass it.Testing Done
New
test/transformers/test_llama4.py. Both cases stay on the non-fused branch, so they run without a GPU:skip_logits=Falsein training mode returns logits and a loss. Onmainthis fails: the flag is ignored, the fused path runs, and on a CPU box Triton raisesRuntimeError: 0 active drivers. On a GPU box it fails onlogits is Noneinstead.skip_logits=Truewith no labels raisesValueError, as it does on every other model. Onmainthis isDID NOT RAISE.pytest test/transformers/test_monkey_patch.py test/transformers/test_llama4.py: 65 passed / 1 skipped (63 + the 2 new; the skip ismuse_glimmermissing from the installed transformers).ruff check .andruff format --check .with the v0.14.11 pinned in.pre-commit-config.yaml: clean.Hardware Type: CPU. Ran on transformers 5.9.0 / torch 2.11.0.