huggingface config_error ai_generated true

ValueError: 截断侧 'left' 与此模型的填充侧 'right' 不兼容。请设置 truncation_side='right' 或 padding_side='left'。

ValueError: Truncation side 'left' is not compatible with padding side 'right' for this model. Set truncation_side='right' or padding_side='left'.

ID: huggingface/truncation-side-mismatch-with-padding

其他格式: JSON · Markdown 中文 · English
93%修复率
89%置信度
1证据数
2024-05-12首次发现

版本兼容性

版本状态引入弃用备注
huggingface/transformers 4.40.0 active
huggingface/tokenizers 0.17.0 active
huggingface/transformers 4.41.0 active

根因分析

分词器的 truncation_side 和 padding_side 设置为相反侧,导致仅解码器模型的标记对齐不一致。

English

The tokenizer's truncation_side and padding_side are set to opposite sides, causing inconsistent token alignment for decoder-only models.

generic

官方文档

https://huggingface.co/docs/transformers/en/pad_truncation

解决方案

  1. Set tokenizer padding_side to 'left' and truncation_side to 'left' for decoder-only models: `tokenizer.padding_side = 'left'; tokenizer.truncation_side = 'left'` before encoding.
  2. Use `tokenizer(text, padding='max_length', truncation=True, return_tensors='pt')` and let the tokenizer auto-resolve by setting `truncation_side='right'` and `padding_side='left'` via `tokenizer.init_kwargs`.

无效尝试

常见但无效的做法:

  1. Set both truncation_side and padding_side to 'right' 70% 失败

    For decoder-only models, padding on the right can cause incorrect attention masking; the model expects left padding for generation.

  2. Ignore the warning and proceed with training 100% 失败

    This is a ValueError, not a warning; it raises an exception and stops execution.