# RuntimeError: FX tracing failed: 'NoneType' object has no attribute 'shape' during symbolic tracing

- **ID:** `pytorch/fx-graph-tracing-non-tensor`
- **Domain:** pytorch
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| torch>=1.8.0 | active | — | — |
| torch>=2.0.0 | active | — | — |

## Workarounds

1. **Ensure all functions return tensors, use torch.zeros(1) as placeholder for None cases: if x is None: return torch.zeros(1)** (85% success)
   ```
   Ensure all functions return tensors, use torch.zeros(1) as placeholder for None cases: if x is None: return torch.zeros(1)
   ```
2. **Decorate the problematic function with @torch.fx.wrap to skip tracing that part** (75% success)
   ```
   Decorate the problematic function with @torch.fx.wrap to skip tracing that part
   ```
3. **Use torch.jit.trace instead of torch.fx.symbolic_trace for models with dynamic control flow** (70% success)
   ```
   Use torch.jit.trace instead of torch.fx.symbolic_trace for models with dynamic control flow
   ```

## Dead Ends

- **** — FX tracer executes the code symbolically; exceptions are propagated as tracer errors. (90% fail)
- **** — This flag doesn't exist; FX always traces shapes. (95% fail)
