Skip to content

PPFormulaNet training-loss bug #47317

Description

@sharmax-vikas

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

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

.

Expected behavior

.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions