transformers - 💡(How to fix) Fix [Bug] Incorrect error message for T5 model family's decoder input validation [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

The error message is misleading and references incorrect argument names.

Fix Action

Fixed

Code Example

from transformers import T5ForConditionalGeneration

model = T5ForConditionalGeneration.from_pretrained("t5-small")

---

t5_decoder = model.decoder

---

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)

---

t5_decoder()

---

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

---

ValueError: You cannot specify both decoder's input_ids and decoder's inputs_embeds at the same time

---

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"
)

---

ValueError: You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time

---

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"
)

---

ValueError: You cannot specify both decoder's input_ids and decoder's inputs_embeds at the same time
RAW_BUFFERClick to expand / collapse

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
  • 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

Steps to reproduce

  1. Import and load a T5 model from transformers:
from transformers import T5ForConditionalGeneration

model = T5ForConditionalGeneration.from_pretrained("t5-small")
  1. Extract the decoder:
t5_decoder = model.decoder
  1. Case 1: Call decoder with both input_ids and inputs_embeds:
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)
  1. Case 2: Call decoder with neither input_ids nor inputs_embeds:
t5_decoder()

Observed behavior

The error message is misleading and references incorrect argument names.

Example traceback:

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 :

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:

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:

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:

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:

ValueError: You cannot specify both decoder's input_ids and decoder's inputs_embeds at the same time

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The error message should reference the actual arguments passed to the decoder, for example :

ValueError: You cannot specify both decoder's input_ids and decoder's inputs_embeds at the same time

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING