{
  "id": "tensorflow/invalid-argument-optimizer-slot-variable-mismatch",
  "signature": "InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [5,10] rhs shape= [10,10]",
  "signature_zh": "无效参数错误：赋值要求两个张量的形状匹配。左形状=[5,10] 右形状=[10,10]",
  "regex": "InvalidArgumentError: Assign requires shapes of both tensors to match\\. lhs shape=\\[\\d+,\\d+\\] rhs shape=\\[\\d+,\\d+\\]",
  "domain": "tensorflow",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Optimizer slot variable shape mismatch, often due to loading a checkpoint from a model with different architecture or incompatible optimizer state.",
  "root_cause_type": "generic",
  "root_cause_zh": "优化器槽变量形状不匹配，通常由于从具有不同架构或不兼容优化器状态的模型加载检查点导致。",
  "versions": [
    {
      "version": "tensorflow 2.12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.13.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Checkpoint files are binary; manual modification corrupts them.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This flag only controls device placement, not tensor shapes.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Load only the model weights, not optimizer state, by excluding optimizer variables when restoring:\nmodel.load_weights('checkpoint.ckpt', by_name=True, skip_mismatch=True)\n# Or use: model.load_weights('checkpoint.ckpt', skip_mismatch=True)",
      "success_rate": 0.85,
      "how": "Load only the model weights, not optimizer state, by excluding optimizer variables when restoring:\nmodel.load_weights('checkpoint.ckpt', by_name=True, skip_mismatch=True)\n# Or use: model.load_weights('checkpoint.ckpt', skip_mismatch=True)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Reinitialize the optimizer and train from scratch, or use a checkpoint that matches the current model architecture exactly.",
      "success_rate": 0.9,
      "how": "Reinitialize the optimizer and train from scratch, or use a checkpoint that matches the current model architecture exactly.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Load only the model weights, not optimizer state, by excluding optimizer variables when restoring:\nmodel.load_weights('checkpoint.ckpt', by_name=True, skip_mismatch=True)\n# Or use: model.load_weights('checkpoint.ckpt', skip_mismatch=True)",
    "Reinitialize the optimizer and train from scratch, or use a checkpoint that matches the current model architecture exactly."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/tutorials/keras/save_and_load",
  "official_doc_section": null,
  "error_code": "IAS",
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-01-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}