# Error: accessing tensor output of CUDAGraphs that has been overwritten by a subsequent run

**URL:** <https://discuss.pytorch.org/t/error-accessing-tensor-output-of-cudagraphs-that-has-been-overwritten-by-a-subsequent-run/218415>\
**Category:** torch.compile\
**Created:** [March 30, 2025, 12:22pm UTC](https://discuss.pytorch.org/t/error-accessing-tensor-output-of-cudagraphs-that-has-been-overwritten-by-a-subsequent-run/218415 "2025-03-30T12:22:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![barakugav](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/barakugav/32/71912_2.png) [@barakugav](https://discuss.pytorch.org/u/barakugav)\
**Post date:** [March 30, 2025, 12:22pm UTC](https://discuss.pytorch.org/t/error-accessing-tensor-output-of-cudagraphs-that-has-been-overwritten-by-a-subsequent-run/218415/1 "2025-03-30T12:22:30Z")

</div>

Im trying to compile my model using torch.compile with mode=‘reduce-overhead’ on a machine with CUDA, and no matter what I do I get a runtime error saying “Error: accessing tensor output of CUDAGraphs that has been overwritten by a subsequent run”.  
Here is a minimal example reproducing the issue:

```python
import torch
import torch.nn as nn

device = 'cuda'
model = nn.Linear(10, 1).to(device)
model = torch.compile(model, fullgraph=True, mode='reduce-overhead')

for _ in range(5):
    torch.compiler.cudagraph_mark_step_begin()

    input = torch.randn((10,), dtype=torch.float32, requires_grad=True, device=device)
    outputs = model(input).clone()
    loss = outputs.sum().clone()
    loss.backward()

```

I get an error:

```bash
Traceback (most recent call last):
  File "runme.py", line 15, in <module>
    loss.backward()
  File "...lib/python3.12/site-packages/torch/_tensor.py", line 626, in backward
    torch.autograd.backward(
  File "...lib/python3.12/site-packages/torch/autograd/ __init__.py", line 347, in backward
    _engine_run_backward(
  File "...lib/python3.12/site-packages/torch/autograd/graph.py", line 823, in _engine_run_backward
    return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Error: accessing tensor output of CUDAGraphs that has been overwritten by a subsequent run. Stack trace: File "...lib/python3.12/site-packages/torch/_dynamo/external_utils.py", line 45, in inner
    return fn(*args, **kwargs). To prevent overwriting, clone the tensor outside of torch.compile() or call torch.compiler.cudagraph_mark_step_begin() before each model invocation.

```

Im using torch ‘2.6.0+cu124’, CUDA Version 12.4, Ubuntu 22.04.5, with NVIDIA A10G.  
Any help appreciated

---

<div class="post-metadata">

**Author:** ![lostmsu](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/lostmsu/32/35744_2.png) [@lostmsu](https://discuss.pytorch.org/u/lostmsu)\
**Post date:** [February 5, 2026, 1:53am UTC](https://discuss.pytorch.org/t/error-accessing-tensor-output-of-cudagraphs-that-has-been-overwritten-by-a-subsequent-run/218415/2 "2026-02-05T01:53:14Z")

</div>

I’m having the same problem on Windows with PyTorch 2.10 and triton-windows
