System Info
transformers version: 5.13.0.dev0 (main branch at commit dc5a497)
-
-
-
-
-
- Using GPU: N/A (code-level bug, not runtime)
Who can help?
@eustlb @ebezzam @vasqu
Information
Tasks
Reproduction
aIn src/transformers/models/cohere_asr/modular_cohere_asr.py, CohereAsrForConditionalGeneration.forward() has a double-shift bug:
- Labels are shifted right via
shift_tokens_right() (line 483) to create decoder_input_ids
-
- Then
self.loss_function() is called (line 503), which maps to ForCausalLMLoss
-
ForCausalLMLoss shifts labels again internally (labels[..., 1:] in loss/loss_utils.py line 63-64)
This means the model trains against labels[..., 1:] instead of labels.
This is the exact same bug that was fixed in Moonshine in PR #46784 (commit d8c2354). The Moonshine fix replaced self.loss_function() with CrossEntropyLoss(), but CohereAsr — which inherits from Moonshine and overrides forward — was not updated.
# Buggy code (line 503 in modular_cohere_asr.py):
loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size)
# Should be:
loss_fct = CrossEntropyLoss()
loss = loss_fct(logits.reshape(-1, self.config.vocab_size), labels.reshape(-1))
Expected behavior
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 model. 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?
@eustlb @ebezzam @vasqu
Information
Tasks
examplesfolder (such as GLUE/SQuAD, ...)Reproduction
aIn
src/transformers/models/cohere_asr/modular_cohere_asr.py,CohereAsrForConditionalGeneration.forward()has a double-shift bug:shift_tokens_right()(line 483) to createdecoder_input_idsself.loss_function()is called (line 503), which maps toForCausalLMLossForCausalLMLossshifts labels again internally (labels[..., 1:]inloss/loss_utils.pyline 63-64)This means the model trains against
labels[..., 1:]instead oflabels.This is the exact same bug that was fixed in Moonshine in PR #46784 (commit d8c2354). The Moonshine fix replaced
self.loss_function()withCrossEntropyLoss(), butCohereAsr— which inherits from Moonshine and overridesforward— was not updated.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 model. The fix should useCrossEntropyLoss()instead ofself.loss_function(), as done in Moonshine PR #46784.