{
  "id": "pytorch/fx-graph-tracing-non-tensor",
  "signature": "RuntimeError: FX tracing failed: 'NoneType' object has no attribute 'shape' during symbolic tracing",
  "signature_zh": "RuntimeError：FX追踪失败：符号追踪期间'NoneType'对象没有属性'shape'",
  "regex": "FX tracing failed.*object has no attribute 'shape'",
  "domain": "pytorch",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "During torch.fx symbolic tracing, a function or method returned None instead of a tensor, causing the tracer to fail when accessing .shape attribute.",
  "root_cause_type": "generic",
  "root_cause_zh": "在torch.fx符号追踪期间，函数或方法返回了None而不是张量，导致追踪器在访问.shape属性时失败。",
  "versions": [
    {
      "version": "torch>=1.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "torch>=2.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "FX tracer executes the code symbolically; exceptions are propagated as tracer errors.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This flag doesn't exist; FX always traces shapes.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure all functions return tensors, use torch.zeros(1) as placeholder for None cases: if x is None: return torch.zeros(1)",
      "success_rate": 0.85,
      "how": "Ensure all functions return tensors, use torch.zeros(1) as placeholder for None cases: if x is None: return torch.zeros(1)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Decorate the problematic function with @torch.fx.wrap to skip tracing that part",
      "success_rate": 0.75,
      "how": "Decorate the problematic function with @torch.fx.wrap to skip tracing that part",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use torch.jit.trace instead of torch.fx.symbolic_trace for models with dynamic control flow",
      "success_rate": 0.7,
      "how": "Use torch.jit.trace instead of torch.fx.symbolic_trace for models with dynamic control flow",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure all functions return tensors, use torch.zeros(1) as placeholder for None cases: if x is None: return torch.zeros(1)",
    "Decorate the problematic function with @torch.fx.wrap to skip tracing that part",
    "Use torch.jit.trace instead of torch.fx.symbolic_trace for models with dynamic control flow"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pytorch.org/docs/stable/fx.html#limitations",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.78,
  "resolvable": "true",
  "first_seen": "2023-11-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}