Fix PPFormulaNet training-loss double-shift in encoder-decoder forward - #47495
Closed
ShamSaleem wants to merge 1 commit into
Closed
Fix PPFormulaNet training-loss double-shift in encoder-decoder forward#47495ShamSaleem wants to merge 1 commit into
ShamSaleem wants to merge 1 commit into
Conversation
PPFormulaNetForConditionalGeneration.forward() computes its loss via self.loss_function() (ForCausalLMLoss), which left-shifts labels by one (labels[..., 1:]). PPFormulaNet is an encoder-decoder model whose logits are already aligned with labels, so this extra shift drops the last target token and trains the model against misaligned labels. Pass shift_labels=labels so ForCausalLMLoss skips its internal shift and keeps labels aligned with logits. This is the same fix already merged for Florence2 in huggingface#46898; PPFormulaNet inherits from Florence2 but overrides forward(), so the fix did not propagate. Fixes huggingface#47317
Member
|
Already being fixed on another PR, closing as duplicate |
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 #47317
PPFormulaNetForConditionalGeneration.forward()computes its loss withself.loss_function()→ForCausalLMLoss, which shifts labels left by one(
labels[..., 1:]) whenshift_labelsis not supplied. PPFormulaNet is anencoder-decoder model, so its logits are already aligned with
labelsandno shift is needed. The extra shift drops the last target token and trains the
model against misaligned labels.
This passes
shift_labels=labelstoForCausalLMLoss, which takes the"already-shifted" path and leaves the labels aligned with the logits.
This is the same fix already merged for Florence2 in #46898 (and Moonshine
before it). PPFormulaNet's modular model inherits from
Florence2ForConditionalGenerationbut overridesforward(), so theFlorence2 fix never propagated to it —
eliaghazalflagged PPFormulaNet aslikely-affected in the #47090 discussion.
Change is applied to
modular_pp_formulanet.py(source of truth) and theregenerated
modeling_pp_formulanet.py.Before submitting
Who can review?
@zucchini-nlp (reviewed & merged the identical Florence2 fix #46898)