System Info
PPFormulaNet training-loss bug — ForCausalLMLoss incorrectly shifts labels in encoder-decoder model
The problem: PPFormulaNetForConditionalGeneration.forward() uses self.loss_function() (line 491 in modular_pp_formulanet.py) which maps to ForCausalLMLoss. ForCausalLMLoss internally shifts labels left by 1 (labels[..., 1:]), but PPFormulaNet is an encoder-decoder model where the logits are already aligned with labels — no shift is needed.
This means the model trains against misaligned labels, losing the last target token.
Where:
modular_pp_formulanet.py, line 491
loss = self.loss_function(
logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size, **kwargs
)
The fix (same pattern as Florence2 after #46898):
loss = self.loss_function(
logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size,
shift_labels=labels, **kwargs
)
Passing shift_labels=labels tells ForCausalLMLoss to skip its internal shift, keeping labels aligned with logits.
Context: Florence2 (which PPFormulaNet inherits from) was already fixed in PR #46898 with this same pattern, but PPFormulaNet overrides forward() so the fix didn't propagate. eliaghazal also flagged PPFormulaNet as potentially affected in PR #47090 discussion, but no one has filed or fixed it yet.
Who can help?
No response
Information
Tasks
Reproduction
.
Expected behavior
.
System Info
PPFormulaNet training-loss bug — ForCausalLMLoss incorrectly shifts labels in encoder-decoder model
The problem: PPFormulaNetForConditionalGeneration.forward() uses self.loss_function() (line 491 in modular_pp_formulanet.py) which maps to ForCausalLMLoss. ForCausalLMLoss internally shifts labels left by 1 (labels[..., 1:]), but PPFormulaNet is an encoder-decoder model where the logits are already aligned with labels — no shift is needed.
This means the model trains against misaligned labels, losing the last target token.
Where:
modular_pp_formulanet.py, line 491
loss = self.loss_function(
logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size, **kwargs
)
The fix (same pattern as Florence2 after #46898):
loss = self.loss_function(
logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size,
shift_labels=labels, **kwargs
)
Passing shift_labels=labels tells ForCausalLMLoss to skip its internal shift, keeping labels aligned with logits.
Context: Florence2 (which PPFormulaNet inherits from) was already fixed in PR #46898 with this same pattern, but PPFormulaNet overrides forward() so the fix didn't propagate. eliaghazal also flagged PPFormulaNet as potentially affected in PR #47090 discussion, but no one has filed or fixed it yet.
Who can help?
No response
Information
Tasks
examplesfolder (such as GLUE/SQuAD, ...)Reproduction
.
Expected behavior
.