{
  "id": "pytorch/torch-compile-graph-break-unsupported-op",
  "signature": "RuntimeError: torch.compile: function 'forward' failed with a graph break. Falling back to eager mode. Consider rewriting the function to avoid unsupported operations.",
  "signature_zh": "运行时错误：torch.compile：函数'forward'因图断裂失败。回退到即时模式。请考虑重写函数以避免不支持的运算。",
  "regex": "RuntimeError: torch\\.compile: function 'forward' failed with a graph break\\. Falling back to eager mode\\. Consider rewriting the function to avoid unsupported operations\\.",
  "domain": "pytorch",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "torch.compile encountered an operation that cannot be traced or compiled (e.g., dynamic control flow, unsupported Python built-ins), causing a graph break and fallback to eager mode.",
  "root_cause_type": "generic",
  "root_cause_zh": "torch.compile遇到了无法追踪或编译的操作（例如动态控制流、不支持的Python内置函数），导致图断裂并回退到即时模式。",
  "versions": [
    {
      "version": "torch>=2.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "torch>=2.1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Disabling torch.compile entirely and using eager mode",
      "why_fails": "This removes the performance benefit of compilation; the error is a warning, not a crash, so eager fallback already occurs.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding @torch.jit.script decorator to the forward function",
      "why_fails": "TorchScript has different restrictions and may cause additional errors; it's not a direct fix for torch.compile graph breaks.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Refactor the forward method to remove dynamic control flow (e.g., if-else statements) and use static operations like torch.where or torch.stack with masks.",
      "success_rate": 0.8,
      "how": "Refactor the forward method to remove dynamic control flow (e.g., if-else statements) and use static operations like torch.where or torch.stack with masks.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use torch.compiler.disable() decorator on specific submodules that cause graph breaks, allowing the rest to compile.",
      "success_rate": 0.7,
      "how": "Use torch.compiler.disable() decorator on specific submodules that cause graph breaks, allowing the rest to compile.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Refactor the forward method to remove dynamic control flow (e.g., if-else statements) and use static operations like torch.where or torch.stack with masks.",
    "Use torch.compiler.disable() decorator on specific submodules that cause graph breaks, allowing the rest to compile."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pytorch.org/docs/stable/torch.compiler.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.75,
  "resolvable": "partial",
  "first_seen": "2024-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}