{
  "id": "huggingface/tokenizer-fast-vs-slow-padding",
  "signature": "UserWarning: Using `pad_token_id` but `padding_side` is not set. The tokenizer will use 'right' padding by default, which may not be optimal for decoder-only models.",
  "signature_zh": "UserWarning: 使用了 `pad_token_id` 但未设置 `padding_side`。分词器将默认使用 'right' 填充，这对于仅解码器模型可能不是最优的。",
  "regex": "UserWarning: Using `pad_token_id` but `padding_side` is not set\\. The tokenizer will use 'right' padding by default, which may not be optimal for decoder-only models\\.",
  "domain": "huggingface",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "When a tokenizer's `padding_side` is not explicitly set, it defaults to 'right', which causes incorrect causal masking in decoder-only models like GPT or LLaMA, leading to degraded generation quality.",
  "root_cause_type": "generic",
  "root_cause_zh": "当分词器的 `padding_side` 未显式设置时，默认为 'right'，这会导致仅解码器模型（如 GPT 或 LLaMA）中的因果掩码不正确，从而降低生成质量。",
  "versions": [
    {
      "version": "transformers>=4.34.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tokenizers>=0.14.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Setting `padding_side='right'` explicitly silences the warning but does not fix the causal masking issue for decoder-only models.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Ignoring the warning and proceeding with training often leads to subtle quality degradation that is hard to detect until evaluation.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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.",
      "success_rate": 0.95,
      "how": "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.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the `pad_token_id` and explicitly pass `attention_mask` to the model to avoid reliance on padding_side defaults.",
      "success_rate": 0.85,
      "how": "Use the `pad_token_id` and explicitly pass `attention_mask` to the model to avoid reliance on padding_side defaults.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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.",
    "Use the `pad_token_id` and explicitly pass `attention_mask` to the model to avoid reliance on padding_side defaults."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/pad_truncation#padding-and-truncation",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-11-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}