huggingface
config_error
ai_generated
true
ValueError: repetition_penalty 和 no_repeat_ngram_size 不能同时设置,因为它们可能冲突
ValueError: repetition_penalty and no_repeat_ngram_size cannot be set simultaneously as they may conflict
ID: huggingface/generation-repetition-penalty-conflict
90%修复率
83%置信度
1证据数
2024-02-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| transformers>=4.35.0 | active | — | — | — |
根因分析
在生成配置中同时设置了 `repetition_penalty` 和 `no_repeat_ngram_size`,但它们的组合效果可能对 token 选择产生矛盾约束。
English
Both `repetition_penalty` and `no_repeat_ngram_size` are set in the generation config, but their combined effect can produce contradictory constraints on token selection.
官方文档
https://huggingface.co/docs/transformers/en/generation_strategies#repetition-penalty解决方案
-
Remove one of the conflicting parameters: `model.generate(input_ids, repetition_penalty=1.2) # no no_repeat_ngram_size` or `model.generate(input_ids, no_repeat_ngram_size=3) # no repetition_penalty`
-
Set the removed parameter to its default value explicitly: `model.generate(input_ids, repetition_penalty=1.0, no_repeat_ngram_size=0)`
-
Use a custom generation config that overrides the conflict check: `from transformers import GenerationConfig; config = GenerationConfig.from_pretrained('model-name', repetition_penalty=1.2, no_repeat_ngram_size=3, _from_model_config=True)` but this may cause undefined behavior.
无效尝试
常见但无效的做法:
-
Setting both parameters to very low values (e.g., 0.1 and 1)
95% 失败
The conflict check is boolean; any non-default values for both triggers the error, regardless of magnitude.
-
Ignoring the warning and proceeding with generation
100% 失败
This is a ValueError, not a warning; it halts execution entirely.
-
Upgrading transformers to 4.40.0
80% 失败
The conflict detection was introduced in 4.35.0; newer versions still enforce the rule.