{
  "id": "pytorch/model-save-load-device-mismatch",
  "signature": "RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map the storages to the CPU.",
  "signature_zh": "RuntimeError: 尝试在 CUDA 设备上反序列化对象，但 torch.cuda.is_available() 为 False。如果你在仅 CPU 的机器上运行，请使用 torch.load 并设置 map_location=torch.device('cpu') 将存储映射到 CPU。",
  "regex": "Attempting to deserialize object on a CUDA device but torch\\.cuda\\.is_available\\(\\) is False",
  "domain": "pytorch",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Loading a model checkpoint that was saved on a GPU machine onto a CPU-only machine without specifying map_location, causing PyTorch to try to load CUDA tensors on a non-CUDA system.",
  "root_cause_type": "generic",
  "root_cause_zh": "将在 GPU 机器上保存的模型检查点加载到仅 CPU 的机器上，而未指定 map_location，导致 PyTorch 尝试在非 CUDA 系统上加载 CUDA 张量。",
  "versions": [
    {
      "version": "1.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This doesn't address the device mismatch; the model still expects CUDA.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This just changes the file path but doesn't fix the loading device.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use torch.load with map_location=torch.device('cpu') to load the checkpoint onto CPU, then move the model to the desired device afterward.",
      "success_rate": 0.95,
      "how": "Use torch.load with map_location=torch.device('cpu') to load the checkpoint onto CPU, then move the model to the desired device afterward.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Alternatively, use map_location='cpu' directly as a string argument.",
      "success_rate": 0.9,
      "how": "Alternatively, use map_location='cpu' directly as a string argument.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use torch.load with map_location=torch.device('cpu') to load the checkpoint onto CPU, then move the model to the desired device afterward.",
    "Alternatively, use map_location='cpu' directly as a string argument."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pytorch.org/docs/stable/generated/torch.load.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-04-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}