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

- **ID:** `huggingface/truncation-side-mismatch-with-padding`
- **领域:** huggingface
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 93%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| huggingface/transformers 4.40.0 | active | — | — |
| huggingface/tokenizers 0.17.0 | active | — | — |
| huggingface/transformers 4.41.0 | active | — | — |

## 解决方案

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`.
   ```

## 无效尝试

- **Set both truncation_side and padding_side to 'right'** — For decoder-only models, padding on the right can cause incorrect attention masking; the model expects left padding for generation. (70% 失败率)
- **Ignore the warning and proceed with training** — This is a ValueError, not a warning; it raises an exception and stops execution. (100% 失败率)
