{
  "id": "huggingface/tokenizer-pad-token-id-mismatch",
  "signature": "ValueError: pad_token_id (0) must be within the vocabulary size (32000) but is greater than or equal to the vocab size",
  "signature_zh": "值错误：pad_token_id (0) 必须在词汇表大小 (32000) 范围内，但大于或等于词汇表大小",
  "regex": "ValueError: pad_token_id \\(\\d+\\) must be within the vocabulary size \\(\\d+\\) but is greater than or equal to the vocab size",
  "domain": "huggingface",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "The tokenizer's pad_token_id is set to a value that exceeds the model's vocabulary size, often due to using a tokenizer with a different vocabulary than the model.",
  "root_cause_type": "generic",
  "root_cause_zh": "分词器的pad_token_id设置为超出模型词汇表大小的值，通常是由于使用了与模型词汇表不同的分词器。",
  "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": "",
      "why_fails": "The pad_token_id must be a valid token index within the model's vocabulary; values outside cause index errors in embedding layers.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding tokens changes the embedding layer size, which may not match the pre-trained model's weights, leading to random initialization.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The eos_token_id may also be out of range or not set, causing the same error.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Resize model embeddings to match tokenizer vocabulary: `model.resize_token_embeddings(len(tokenizer))`",
      "success_rate": 0.95,
      "how": "Resize model embeddings to match tokenizer vocabulary: `model.resize_token_embeddings(len(tokenizer))`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Set pad_token to an existing token within vocab: `tokenizer.pad_token = tokenizer.eos_token` if eos_token_id is valid, or `tokenizer.add_special_tokens({'pad_token': '[PAD]'})` then resize.",
      "success_rate": 0.9,
      "how": "Set pad_token to an existing token within vocab: `tokenizer.pad_token = tokenizer.eos_token` if eos_token_id is valid, or `tokenizer.add_special_tokens({'pad_token': '[PAD]'})` then resize.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Load tokenizer with explicit pad_token_id: `AutoTokenizer.from_pretrained('model-name', pad_token_id=0)` ensuring 0 is within vocab size.",
      "success_rate": 0.85,
      "how": "Load tokenizer with explicit pad_token_id: `AutoTokenizer.from_pretrained('model-name', pad_token_id=0)` ensuring 0 is within vocab size.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Resize model embeddings to match tokenizer vocabulary: `model.resize_token_embeddings(len(tokenizer))`",
    "Set pad_token to an existing token within vocab: `tokenizer.pad_token = tokenizer.eos_token` if eos_token_id is valid, or `tokenizer.add_special_tokens({'pad_token': '[PAD]'})` then resize.",
    "Load tokenizer with explicit pad_token_id: `AutoTokenizer.from_pretrained('model-name', pad_token_id=0)` ensuring 0 is within vocab size."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/main/en/troubleshooting",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-11-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}