huggingface config_error ai_generated true

ValueError: The combination of parameters `max_new_tokens` and `max_length` is ambiguous. Please set only one of them.

ID: huggingface/generate-max-new-tokens-overlap

Also available as: JSON · Markdown · 中文
95%Fix Rate
90%Confidence
1Evidence
2023-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
transformers>=4.25.0 active

Root Cause

Both `max_new_tokens` and `max_length` were provided to `model.generate()`, creating conflicting constraints on the output length.

generic

中文

在 `model.generate()` 中同时提供了 `max_new_tokens` 和 `max_length`,对输出长度产生了冲突的约束。

Official Documentation

https://huggingface.co/docs/transformers/v4.35.0/en/main_classes/text_generation#transformers.GenerationConfig.max_new_tokens

Workarounds

  1. 95% success Remove one of the conflicting parameters. If you want to limit total sequence length, use `max_length=512`. If you want to limit only new tokens generated, use `max_new_tokens=128`. Example: `model.generate(inputs, max_new_tokens=128)`
    Remove one of the conflicting parameters. If you want to limit total sequence length, use `max_length=512`. If you want to limit only new tokens generated, use `max_new_tokens=128`. Example: `model.generate(inputs, max_new_tokens=128)`
  2. 90% success If using a pipeline, pass only one of the parameters in `pipeline(text, max_new_tokens=128)` and ensure `max_length` is not set in `model.config` or generation config.
    If using a pipeline, pass only one of the parameters in `pipeline(text, max_new_tokens=128)` and ensure `max_length` is not set in `model.config` or generation config.

中文步骤

  1. 移除其中一个冲突的参数。如果要限制总序列长度,使用 `max_length=512`。如果只想限制新生成的 token 数量,使用 `max_new_tokens=128`。示例:`model.generate(inputs, max_new_tokens=128)`
  2. 如果使用 pipeline,在 `pipeline(text, max_new_tokens=128)` 中仅传递其中一个参数,并确保 `model.config` 或 generation config 中没有设置 `max_length`。

Dead Ends

Common approaches that don't work:

  1. 99% fail

    The error is about having both parameters set at all, not about their values. The validation checks for the presence of both, regardless of equality.

  2. 95% fail

    `max_time` is a separate constraint and does not resolve the conflict between `max_new_tokens` and `max_length`. The validation error still occurs.