[Bug] Incorrect error message for T5 model family's decoder input validation
bug
### System Info
- `transformers` version: 5.5.1
- Platform: Windows-11-10.0.26200-SP0
- Python version: 3.12.12
- Huggingface_hub version: 1.8.0
- Safetensors version: 0.7.0
- Accelerate version: 1.13.0
- Accelerate config: not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.6.0+cu124 (CUDA)
- Using distributed or parallel set-up in script?: no
- Using GPU in script?: yes
- GPU type: NVIDIA GeForce RTX 3060 Ti
### Who can help?
@ArthurZucker @Cyrilvallez
### 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
### Steps to reproduce
1. Import and load a T5 model from `transformers`:
```python
from transformers import T5ForConditionalGeneration
model = T5ForConditionalGeneration.from_pretrained("t5-small")
```
2. Extract the decoder:
```python
t5_decoder = model.decoder
```
3. Case 1: Call decoder with **both** `input_ids` and `inputs_embeds`:
```python
import torch
input_ids = torch.tensor([[1, 2, 3]])
inputs_embeds = torch.randn(1, 3, model.config.d_model)
t5_decoder(input_ids=input_ids, inputs_embeds=inputs_embeds)
```
4. Case 2: Call decoder with **neither** `input_ids` nor `inputs_embeds`:
```python
t5_decoder()
```
---
### Observed behavior
The error message is misleading and references incorrect argument names.
Example traceback:
```text
Traceback (most recent call last):
File "repro.py", line XX, in <module>
t5_decoder(input_ids=input_ids, inputs_embeds=inputs_embeds)
File ".../transformers/models/t5/modeling_t5.py", line XXX, in forward
...
ValueError: You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time
```
Note:
* The decoder was called with `input_ids` and `inputs_embeds`
* But the error refers to `decoder_input_ids` and `decoder_inputs_embeds`
### Colab notebook
https://colab.research.google.com/drive/1eggqqICSgiKltsDoY_86iH9D6M8zHc8R?authuser=0#scrollTo=9Ehdgpq7S1p8
### Expected behavior
---
### Expected behavior
The error message should reference the actual arguments passed to the decoder, for example :
```text
ValueError: You cannot specify both decoder's input_ids and decoder's inputs_embeds at the same time
```
### Possible fix
In T5-related models, the error message prefix is currently defined as:
```python
err_msg_prefix = "decoder_" if self.is_decoder else ""
raise ValueError(
f"You cannot specify both {err_msg_prefix}input_ids and {err_msg_prefix}inputs_embeds at the same time"
)
```
This results in misleading messages such as:
```text
ValueError: You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time
```
even when the decoder is directly called with `input_ids` and `inputs_embeds`.
A possible improvement is to make the message clearer by adjusting the prefix:
```python
err_msg_prefix = "decoder's " if self.is_decoder else ""
raise ValueError(
f"You cannot specify both {err_msg_prefix}input_ids and {err_msg_prefix}inputs_embeds at the same time"
)
```
This would produce:
```text
ValueError: You cannot specify both decoder's input_ids and decoder's inputs_embeds at the same time
```
2 条评论