{
  "id": "pytorch/mps-float64-fallback",
  "signature": "RuntimeError: MPS backend does not support float64. Falling back to float32. Please cast your tensors to float32 explicitly",
  "signature_zh": "RuntimeError：MPS 后端不支持 float64。回退到 float32。请显式将张量转换为 float32",
  "regex": "RuntimeError: MPS backend does not support float64",
  "domain": "pytorch",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Apple MPS (Metal Performance Shaders) backend lacks support for float64 (double precision) tensors, causing operations to fail or silently fall back to float32, which may lead to precision loss or type mismatches.",
  "root_cause_type": "generic",
  "root_cause_zh": "Apple MPS（Metal Performance Shaders）后端不支持 float64（双精度）张量，导致操作失败或静默回退到 float32，可能造成精度损失或类型不匹配。",
  "versions": [
    {
      "version": "torch>=1.12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "macOS>=12.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MPS>=1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Tensors already created as float64 remain float64; only newly created tensors are affected.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Float16 may underflow or overflow in training, leading to NaN loss or convergence issues.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Explicitly cast all input tensors to float32 before moving to MPS: tensor = tensor.float().to('mps'). For models, use model = model.float().to('mps').",
      "success_rate": 0.95,
      "how": "Explicitly cast all input tensors to float32 before moving to MPS: tensor = tensor.float().to('mps'). For models, use model = model.float().to('mps').",
      "condition": "",
      "sources": []
    },
    {
      "action": "Override the default dtype at the start of your script: torch.set_default_dtype(torch.float32). Also ensure all data loaders yield float32 tensors by adding a transform: transforms.ConvertImageDtype(torch.float32).",
      "success_rate": 0.9,
      "how": "Override the default dtype at the start of your script: torch.set_default_dtype(torch.float32). Also ensure all data loaders yield float32 tensors by adding a transform: transforms.ConvertImageDtype(torch.float32).",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Explicitly cast all input tensors to float32 before moving to MPS: tensor = tensor.float().to('mps'). For models, use model = model.float().to('mps').",
    "Override the default dtype at the start of your script: torch.set_default_dtype(torch.float32). Also ensure all data loaders yield float32 tensors by adding a transform: transforms.ConvertImageDtype(torch.float32)."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pytorch.org/docs/stable/notes/mps.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-03-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}