huggingface
config_error
ai_generated
true
ValueError:参数 `max_new_tokens` 和 `max_length` 的组合不明确。请仅设置其中一个。
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
95%修复率
90%置信度
1证据数
2023-06-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| transformers>=4.25.0 | active | — | — | — |
根因分析
在 `model.generate()` 中同时提供了 `max_new_tokens` 和 `max_length`,对输出长度产生了冲突的约束。
English
Both `max_new_tokens` and `max_length` were provided to `model.generate()`, creating conflicting constraints on the output length.
官方文档
https://huggingface.co/docs/transformers/v4.35.0/en/main_classes/text_generation#transformers.GenerationConfig.max_new_tokens解决方案
-
移除其中一个冲突的参数。如果要限制总序列长度,使用 `max_length=512`。如果只想限制新生成的 token 数量,使用 `max_new_tokens=128`。示例:`model.generate(inputs, max_new_tokens=128)`
-
如果使用 pipeline,在 `pipeline(text, max_new_tokens=128)` 中仅传递其中一个参数,并确保 `model.config` 或 generation config 中没有设置 `max_length`。
无效尝试
常见但无效的做法:
-
99% 失败
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.
-
95% 失败
`max_time` is a separate constraint and does not resolve the conflict between `max_new_tokens` and `max_length`. The validation error still occurs.