Inconsistent output lengths when max_length=20
is set implicitly vs explicitly in generate()
#35765
Open
2 of 4 tasks
Labels
System Info
transformers
version: 4.49.0.dev0Who can help?
@gante
@ArthurZucker
Related PR that discusses recent default
max_length
-related changes: #34814.Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
When using
generate()
with a model that hasgeneration_config.max_length=20
, the output length differs depending on whethermax_length
is passed explicitly or used implicitly from thegeneration_config
.In the first case, the generated text is longer than in the second case (36 vs. 20 tokens).
Reason and scope
In the first case,
max_length
is overwritten as follows in filesrc/transformers/generation/utils.py
, function_prepare_generated_length
:Since
GenerationConfig().max_length
defaults to 20, the bug only affects models withgeneration_config.max_length
set to 20.Expected behavior
The calls
model.generate(input_ids=input_ids)
andmodel.generate(input_ids=input_ids, max_length=model.generation_config.max_length)
should generate texts of the same length whengeneration_config.max_length
is set to 20.The text was updated successfully, but these errors were encountered: