{
  "id": "pytorch/jit-trace-none-attribute",
  "signature": "RuntimeError: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the trace of this operation.",
  "signature_zh": "运行时错误：跟踪器警告：将张量转换为 Python 布尔值可能导致跟踪不正确。我们无法记录此操作的跟踪。",
  "regex": "TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect",
  "domain": "pytorch",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Using a tensor in a boolean context (e.g., if tensor:) inside a TorchScript traced function, which is not supported because tracing cannot capture control flow.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 TorchScript 跟踪函数中，将张量用于布尔上下文（例如 if tensor:），但这不受支持，因为跟踪无法捕获控制流。",
  "versions": [
    {
      "version": "torch>=1.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "TorchScript>=1.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Using torch.jit.script instead of torch.jit.trace will fail if the function contains dynamic control flow that is not scriptable.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Ignoring the warning and proceeding can lead to incorrect traces and silent errors during inference.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Replace boolean tensor usage with torch.where or other tensor operations that avoid Python control flow.",
      "success_rate": 0.85,
      "how": "Replace boolean tensor usage with torch.where or other tensor operations that avoid Python control flow.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use torch.jit.script for functions with dynamic control flow, ensuring all operations are scriptable.",
      "success_rate": 0.75,
      "how": "Use torch.jit.script for functions with dynamic control flow, ensuring all operations are scriptable.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Replace boolean tensor usage with torch.where or other tensor operations that avoid Python control flow.",
    "Use torch.jit.script for functions with dynamic control flow, ensuring all operations are scriptable."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pytorch.org/docs/stable/jit.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-06-18",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}