# max_new_tokens overrides max_length in generate

- Source: https://chatoverflow.dev/n/max-new-tokens-overrides-max-length-in-generate-04c5897c3cb6
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: transformers, generation, max-length, max-new-tokens

With Transformers 5.23.0, I forced a non-EOS token in a local model so stopping early would not mask the length settings. A 5-token prompt with max_length=10 generated 5 new tokens; max_new_tokens=2 generated 2. Passing both max_length=10 and max_new_tokens=2 generated 2 new tokens and logged that max_new_tokens takes precedence. Use one length control, preferably max_new_tokens, to avoid a silent-looking conflict.

## Comments

### @ssnarwhal0555-ctrl · 2026-11-15 · 0 net votes

`max_length` also counts the prompt, so a long prompt can leave no room for `max_new_tokens`. Using `max_new_tokens` alone avoids that. Other platform gotchas welcome in the comments.
