EncoderDecoderModel emits FutureWarning about v4.12 training path when labels are passed (v4.48.1, „version v4.12.0 introduces a better way to train encoder-decoder models by computing the loss inside the encoder-decoder framework.“)
Author: leaBroe
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.48.1
- Platform: Linux-5.14.0-503.40.1.el9_5.x86_64-x86_64-with-glibc2.34
- Python version: 3.10.18
- Huggingface_hub version: 0.34.4
- Safetensors version: 0.6.2
- Accelerate version: 1.10.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.5.1 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: no


### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

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

### Reproduction

When training an EncoderDecoderModel on transformers v4.48.1, a FutureWarning about the v4.12 training path is printed every forward call whenever labels are provided—even if no decoder_input_ids are passed (i.e., using the new approach where the model derives them from labels). 

The warning is the following:
"FutureWarning: Version v4.12.0 introduces a better way to train encoder-decoder models by computing the loss inside the encoder-decoder framework rather than in the decoder itself. You may observe training discrepancies if fine-tuning a model trained with versions anterior to 4.12.0. The decoder_input_ids are now created based on the labels, no need to pass them yourself anymore."

This happens even if we do not pass decoder_input_ids and rely on labels + decoder_start_token_id.

minimal script for reproduction:
```python
import torch
from transformers import EncoderDecoderModel, AutoTokenizer

tok = AutoTokenizer.from_pretrained("bert-base-uncased")
model = EncoderDecoderModel.from_encoder_decoder_pretrained(
    "bert-base-uncased", "bert-base-uncased"
)
model.config.decoder_start_token_id = tok.cls_token_id
model.config.eos_token_id = tok.sep_token_id
model.config.pad_token_id = tok.pad_token_id

src = tok("hello world", return_tensors="pt")
tgt = tok("hi there", return_tensors="pt").input_ids

labels = tgt.clone()
labels[labels == tok.pad_token_id] = -100

out = model(
    input_ids=src["input_ids"],
    attention_mask=src["attention_mask"],
    labels=labels,
)

print(type(out), out.loss) 
```
with this, i get the ouput: <class 'transformers.modeling_outputs.Seq2SeqLMOutput'> tensor(12.3924, grad_fn=<NllLossBackward0>)
and still the FutureWarning mentioned above.

### Expected behavior

If labels are given and decoder_input_ids are not provided, the model uses the new path (derive decoder_input_ids from labels) without emitting a warning.

A warning should only trigger when the deprecated path is used (e.g., if both labels and decoder_input_ids are passed, or if some legacy pathway is detected).

Workarounds tried
	•	Removing decoder_input_ids entirely (only pass labels) → warning still appears.
	•	Subclassing Seq2SeqTrainer to pop decoder_input_ids → warning still appears.
	•	Subclassing EncoderDecoderModel.forward to pop decoder_input_ids → warning still appears.

Thanks for any help!! 

Comments:
cc @ydshieh since I think you worked on encoder-decoder models! If not, feel free to ping someone else to take this one.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

would still be great to have some help

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.