Lightning-AI / Lightning-AI/lightning-thunder

In-place ops on cloned tensor propagates to the original tensor

Open
#2,793 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
121
PR merge metrics
No merged PRs in 30d

Description

## 🐛 Bug

On `main` 006a2435a74acce2f86056f3d6b8a8d28154a5a2

```py
import torch, thunder

@thunder.jit
def fn(x):
y = x.clone()
y.sin_()
return x + y

x = torch.randn(4, device="cuda")
x_ref = x.clone()
out = fn(x)

torch.testing.assert_close(x, x_ref) # AssertionError: Tensor-likes are not close!
torch.testing.assert_close(out, x_ref + x_ref.sin()) # AssertionError: Tensor-likes are not close!
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Python reproducer on the referenced main revision, focusing on the interaction between x.clone(), y.sin_(), and the returned values. Trace the compiler path exercised by @thunder.jit and identify where the clone's in-place operation affects x. Done means both torch.testing.assert_close checks pass without modifying the original tensor.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
compilers, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.