{
  "id": "huggingface/truncation-side-mismatch-with-padding",
  "signature": "ValueError: Truncation side 'left' is not compatible with padding side 'right' for this model. Set truncation_side='right' or padding_side='left'.",
  "signature_zh": "ValueError: 截断侧 'left' 与此模型的填充侧 'right' 不兼容。请设置 truncation_side='right' 或 padding_side='left'。",
  "regex": "ValueError: Truncation side '.*' is not compatible with padding side '.*' for this model\\.",
  "domain": "huggingface",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "The tokenizer's truncation_side and padding_side are set to opposite sides, causing inconsistent token alignment for decoder-only models.",
  "root_cause_type": "generic",
  "root_cause_zh": "分词器的 truncation_side 和 padding_side 设置为相反侧，导致仅解码器模型的标记对齐不一致。",
  "versions": [
    {
      "version": "huggingface/transformers 4.40.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "huggingface/tokenizers 0.17.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "huggingface/transformers 4.41.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Set both truncation_side and padding_side to 'right'",
      "why_fails": "For decoder-only models, padding on the right can cause incorrect attention masking; the model expects left padding for generation.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignore the warning and proceed with training",
      "why_fails": "This is a ValueError, not a warning; it raises an exception and stops execution.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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.",
      "success_rate": 0.95,
      "how": "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.",
      "condition": "",
      "sources": []
    },
    {
      "action": "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`.",
      "success_rate": 0.85,
      "how": "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`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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.",
    "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`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/en/pad_truncation",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.93,
  "resolvable": "true",
  "first_seen": "2024-05-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}