{
  "id": "huggingface/tokenizer-padding-side-mismatch",
  "signature": "UserWarning: You are using a decoder-only model with padding_side='right'. This may produce incorrect results. Consider setting padding_side='left'.",
  "signature_zh": "UserWarning: 您正在使用仅解码器模型且 padding_side='right'。这可能会产生错误结果。建议将 padding_side 设置为 'left'。",
  "regex": "UserWarning: You are using a decoder-only model with padding_side='right'\\. This may produce incorrect results\\. Consider setting padding_side='left'\\.?",
  "domain": "huggingface",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Decoder-only models (like GPT, LLaMA) expect padding on the left side to maintain causal attention masking; right padding causes the model to attend to padding tokens at the end of sequences.",
  "root_cause_type": "generic",
  "root_cause_zh": "仅解码器模型（如 GPT、LLaMA）期望在左侧进行填充以保持因果注意力掩码；右侧填充会导致模型关注序列末尾的填充 token。",
  "versions": [
    {
      "version": "transformers>=4.30.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": "Setting `padding_side='right'` explicitly to suppress the warning",
      "why_fails": "This does not fix the underlying issue; the model still produces incorrect outputs due to attention mask misalignment.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a different tokenizer without changing padding_side",
      "why_fails": "All decoder-only tokenizers have the same requirement; the warning will persist or outputs will be wrong.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding `attention_mask` manually without changing padding_side",
      "why_fails": "Even with an attention mask, right padding causes the model to attend to padding tokens in the causal mask, leading to degraded generation.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set padding_side to 'left' before tokenization: `tokenizer.padding_side = 'left'; tokenizer.pad_token = tokenizer.eos_token; inputs = tokenizer(texts, padding=True, truncation=True, return_tensors='pt')`",
      "success_rate": 0.95,
      "how": "Set padding_side to 'left' before tokenization: `tokenizer.padding_side = 'left'; tokenizer.pad_token = tokenizer.eos_token; inputs = tokenizer(texts, padding=True, truncation=True, return_tensors='pt')`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the tokenizer's `__call__` with the `padding_side` parameter: `tokenizer(texts, padding=True, truncation=True, padding_side='left', return_tensors='pt')`",
      "success_rate": 0.9,
      "how": "Use the tokenizer's `__call__` with the `padding_side` parameter: `tokenizer(texts, padding=True, truncation=True, padding_side='left', return_tensors='pt')`",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using a pipeline, set padding_side via the tokenizer: `from transformers import pipeline; pipe = pipeline('text-generation', model='gpt2', tokenizer=tokenizer); pipe.tokenizer.padding_side = 'left'`",
      "success_rate": 0.85,
      "how": "If using a pipeline, set padding_side via the tokenizer: `from transformers import pipeline; pipe = pipeline('text-generation', model='gpt2', tokenizer=tokenizer); pipe.tokenizer.padding_side = 'left'`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Set padding_side to 'left' before tokenization: `tokenizer.padding_side = 'left'; tokenizer.pad_token = tokenizer.eos_token; inputs = tokenizer(texts, padding=True, truncation=True, return_tensors='pt')`",
    "Use the tokenizer's `__call__` with the `padding_side` parameter: `tokenizer(texts, padding=True, truncation=True, padding_side='left', return_tensors='pt')`",
    "If using a pipeline, set padding_side via the tokenizer: `from transformers import pipeline; pipe = pipeline('text-generation', model='gpt2', tokenizer=tokenizer); pipe.tokenizer.padding_side = 'left'`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/en/pad_truncation#padding-and-truncation",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-08-25",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}