{
  "id": "huggingface/peft-adapter-shape-mismatch",
  "signature": "RuntimeError: PEFT adapter weight shape mismatch: expected [4096, 4096] but got [4096, 2048]",
  "signature_zh": "运行时错误：PEFT 适配器权重形状不匹配：期望 [4096, 4096] 但得到 [4096, 2048]",
  "regex": "RuntimeError: PEFT adapter weight shape mismatch: expected \\[\\d+, \\d+\\] but got \\[\\d+, \\d+\\]",
  "domain": "huggingface",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The PEFT adapter was trained on a model with different hidden dimensions (e.g., a smaller variant) and is being loaded onto a model with incompatible dimensions.",
  "root_cause_type": "generic",
  "root_cause_zh": "PEFT 适配器是在不同隐藏维度的模型上训练的（例如较小的变体），并被加载到维度不兼容的模型上。",
  "versions": [
    {
      "version": "peft>=0.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "transformers>=4.30.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "torch>=1.13.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Force load the adapter with `strict=False` to ignore mismatched layers",
      "why_fails": "The model will silently drop or partially load weights, leading to undefined behavior and poor performance.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Manually resize the adapter weights using interpolation",
      "why_fails": "Adapters are not spatially structured; interpolation can break the learned patterns and cause numerical instability.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Set `torch.set_default_dtype(torch.float16)` to avoid shape errors",
      "why_fails": "Dtype does not affect tensor shape; shape mismatch is a structural issue, not a precision issue.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Verify the base model used for adapter training: load the correct base model with matching hidden size: from transformers import AutoModel; model = AutoModel.from_pretrained('original-base-model'); model.load_adapter('./adapter_path')",
      "success_rate": 0.95,
      "how": "Verify the base model used for adapter training: load the correct base model with matching hidden size: from transformers import AutoModel; model = AutoModel.from_pretrained('original-base-model'); model.load_adapter('./adapter_path')",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check adapter config metadata: print(PeftConfig.from_pretrained('./adapter_path').base_model_name_or_path) to identify the correct base model.",
      "success_rate": 0.9,
      "how": "Check adapter config metadata: print(PeftConfig.from_pretrained('./adapter_path').base_model_name_or_path) to identify the correct base model.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "验证适配器训练使用的基础模型：加载具有匹配隐藏大小的正确基础模型：from transformers import AutoModel; model = AutoModel.from_pretrained('original-base-model'); model.load_adapter('./adapter_path')",
    "检查适配器配置元数据：print(PeftConfig.from_pretrained('./adapter_path').base_model_name_or_path) 以识别正确的基础模型。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/peft/troubleshooting#adapter-weight-shape-mismatch",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.92,
  "resolvable": "true",
  "first_seen": "2024-02-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}