{
  "id": "tensorflow/checkpoint-incompatible-shape",
  "signature": "InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [100,256] rhs shape= [200,256]",
  "signature_zh": "无效参数错误：赋值要求两个张量的形状匹配。左形状= [100,256] 右形状= [200,256]",
  "regex": "Assign requires shapes of both tensors to match\\. lhs shape= \\[\\d+,\\d+\\] rhs shape= \\[\\d+,\\d+\\]",
  "domain": "tensorflow",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to restore a checkpoint into a model whose layer shapes differ from the saved checkpoint due to model architecture changes.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试将检查点恢复到模型时，由于模型架构更改，层形状与保存的检查点不匹配。",
  "versions": [
    {
      "version": "tensorflow 2.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Deleting and recreating the checkpoint file",
      "why_fails": "The checkpoint is valid; the problem is the model definition mismatch. Deleting the checkpoint loses training progress without addressing the root cause.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Changing learning rate or optimizer",
      "why_fails": "The error is about tensor shape mismatch during assignment, not optimization hyperparameters.",
      "fail_rate": 0.99,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Modify the model to match the checkpoint shapes. For example, if the checkpoint has a Dense layer with 256 units but your model has 200 units, change to 256: model.add(tf.keras.layers.Dense(256)). Then restore: model.load_weights('path/to/checkpoint').",
      "success_rate": 0.85,
      "how": "Modify the model to match the checkpoint shapes. For example, if the checkpoint has a Dense layer with 256 units but your model has 200 units, change to 256: model.add(tf.keras.layers.Dense(256)). Then restore: model.load_weights('path/to/checkpoint').",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use load_weights with by_name=True and skip_mismatch=True to load only matching layers: model.load_weights('path/to/checkpoint', by_name=True, skip_mismatch=True)",
      "success_rate": 0.75,
      "how": "Use load_weights with by_name=True and skip_mismatch=True to load only matching layers: model.load_weights('path/to/checkpoint', by_name=True, skip_mismatch=True)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Modify the model to match the checkpoint shapes. For example, if the checkpoint has a Dense layer with 256 units but your model has 200 units, change to 256: model.add(tf.keras.layers.Dense(256)). Then restore: model.load_weights('path/to/checkpoint').",
    "Use load_weights with by_name=True and skip_mismatch=True to load only matching layers: model.load_weights('path/to/checkpoint', by_name=True, skip_mismatch=True)"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/guide/checkpoint#restoring_variable_values",
  "official_doc_section": null,
  "error_code": "CIS",
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2023-08-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}