# UserWarning: 使用了 `pad_token_id` 但未设置 `padding_side`。分词器将默认使用 'right' 填充，这对于仅解码器模型可能不是最优的。

- **ID:** `huggingface/tokenizer-fast-vs-slow-padding`
- **领域:** huggingface
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

当分词器的 `padding_side` 未显式设置时，默认为 'right'，这会导致仅解码器模型（如 GPT 或 LLaMA）中的因果掩码不正确，从而降低生成质量。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| transformers>=4.34.0 | active | — | — |
| tokenizers>=0.14.0 | active | — | — |

## 解决方案

1. ```
   Set `tokenizer.padding_side = 'left'` before tokenization for decoder-only models. This ensures padding tokens are on the left and do not interfere with causal attention.
   ```
2. ```
   Use the `pad_token_id` and explicitly pass `attention_mask` to the model to avoid reliance on padding_side defaults.
   ```

## 无效尝试

- **** — Setting `padding_side='right'` explicitly silences the warning but does not fix the causal masking issue for decoder-only models. (60% 失败率)
- **** — Ignoring the warning and proceeding with training often leads to subtle quality degradation that is hard to detect until evaluation. (40% 失败率)
