-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent output lengths when max_length=20
is set implicitly vs explicitly in generate()
#35765
Comments
cc @gante |
Btw, is there any reason why we made default |
That is expected, the default is to generate 20 tokens, so |
Ok, I understand that. But is it safe to assume that For example, if |
Yeah it does not because sometimes your prompt can be answered in less thank 20 tokens! If you explicitly set |
I understand that the generation uses Yet, I still think that
|
I agree with the above. We can have defaults |
Happy to update as well! Sorry that this created confusion, many things are kept for BC 😿 |
I'll open a PR to update this new behavior and make the default clearer :) |
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: