[Bug Skip] test_fx - CSEPass Mutation tests fail with RuntimeError: Tried to trace mutable operation aten::add_.Tensor on XPU
- Dominant language
- Python
- Stars
- 113
- Forks
- 128
- Avg merge
- 5d 13h
- Merged PRs (30d)
- 107
Description
## Bug Description
CSEPass Mutation tests in `TestCommonPass` (parametrized tests from `fx/test_common_passes.py`) fail on XPU device with `RuntimeError: Tried to trace mutable operation`. The error occurs when `make_fx` attempts to trace functions using in-place operations (e.g., `add_`) on XPU tensors. FX only supports functional (non-mutating) code, but on XPU the trace fails while it passes on CPU/CUDA.
## Affected Tests
Cases:
op_ut,test/test_fx.py,TestCommonPass.test_correctness_CSEPass_Mutation_xpu
op_ut,test/test_fx.py,TestCommonPass.test_correctness_CSEPass_MutationTorchTensorCall_xpu
op_ut,test/test_fx.py,TestCommonPass.test_correctness_factory_CSEPass_MutationFactory_xpu
## Error Message
```
RuntimeError: Tried to trace mutable operation aten::add_.Tensor(Tensor(a!) self, Tensor other, *, Scalar alpha=1) -> Tensor(a!). FX only supports functional code, so operations that mutate operands in place are not supported.
```
## Test Code Snippet
```python
# test/fx/test_common_passes.py:39-42
def Mutation(x):
y = x + 2
y.add_(1)
return x + y
```
```python
# test/fx/test_common_passes.py:57-60
def MutationTorchTensorCall(x):
y = torch.tensor(3)
y.add_(1)
return x + y
```
```python
# test/fx/test_common_passes.py:51-54
def MutationFactory(x, device):
y = torch.full(x.shape, 3, device=device)
y.add_(1)
return x + y
```
The parametrized test runs these functions through `make_fx`:
```python
# test/fx/test_common_passes.py:93-110
@parametrize("common_pass,f,device", itertools.product(Passes, Test_Cases, Devices), name_fn)
def test_correctness(self, common_pass, f, device):
inp = torch.randn(10, device=device)
traced_m = make_fx(f)(inp)
...
```
## Root Cause Analysis
The tests use `make_fx` to trace functions that contain in-place operations (`.add_(1)`). FX tracing captures operations into a graph, and in-place mutating operations are not supported in FX graphs. On CPU and CUDA, `make_fx` can handle these operations (likely by decomposing or functionalizing them), but on XPU the tracing fails with this error.
The root cause is likely that the XPU backend\(\s\)s `make_fx` implementation does not support functionalization of in-place operations like `aten::add_.Tensor` for tensor inputs created on XPU device. This may require implementing the `Functionalize` dispatch key or ensuring the XPU functionalization pass handles in-place ops properly.
## Related Issues
None found.
## Versions
PyTorch: main
Contributor guide
Assessment
This issue has not been assessed yet.