You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
My own task or dataset (give details below)
Reproduction
aIn src/transformers/models/florence2/modular_florence2.py, Florence2ForConditionalGeneration.forward() has a double-shift bug introduced in PR #40914:
Labels are shifted right via shift_tokens_right() (line 1588) to create decoder_input_ids
Then self.loss_function() is called (line 1613), which maps to ForCausalLMLoss
Training loss should be computed directly against labels without any additional shifting, since shift_tokens_right() already handles the decoder input alignment. This matches the behavior of Whisper, Bart, and the now-fixed Moonshine and CohereASR models. The fix should use CrossEntropyLoss() instead of self.loss_function(), as done in Moonshine PR #46784.
System Info
transformersversion: 5.13.0.dev0 (main branch at commit dc5a497)Who can help?
@zucchini-nlp @yonigozlan
Information
Tasks
examplesfolder (such as GLUE/SQuAD, ...)Reproduction
aIn
src/transformers/models/florence2/modular_florence2.py,Florence2ForConditionalGeneration.forward()has a double-shift bug introduced in PR #40914:shift_tokens_right()(line 1588) to createdecoder_input_idsself.loss_function()is called (line 1613), which maps toForCausalLMLossForCausalLMLossshifts labels again internally (labels[..., 1:]inloss/loss_utils.pyline 63-64)This means the model trains against
labels[..., 1:]instead oflabels. Same bug fixed in Moonshine PR Fix Moonshine training-loss double-shift (train against labels, not labels[..., 1:]) #46784.Expected behavior
Training loss should be computed directly against
labelswithout any additional shifting, sinceshift_tokens_right()already handles the decoder input alignment. This matches the behavior of Whisper, Bart, and the now-fixed Moonshine and CohereASR models. The fix should useCrossEntropyLoss()instead ofself.loss_function(), as done in Moonshine PR #46784.