Lightning-AI / Lightning-AI/lightning-thunder
Inconsistent behavior for copy_
@IvanYashchuk is already working on this.
Since Mar 26, 2025.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 121
- PR merge metrics
- No merged PRs in 30d
Description
There are two inconsistencies for the behavior of `copy_` between PyTorch and Thunder. In Thunder, it is [enforced](https://github.com/Lightning-AI/lightning-thunder/blob/4627db83cd0e36edef031b6c2c6d4019b2fca6a5/thunder/core/prims.py#L4118) that when data is copied from one tensor to another that the tensors both live on the same device and have the same shape. Neither of these conditions are required in PyTorch. For the second point, it is required that the source tensor have a shape which is broadcast-able to the destination's shape.
```
import torch
import thunder
def f(x, y):
x.copy_(y)
return x
x = torch.rand(5)
y = torch.rand(())
z = torch.rand(5, device='cuda')
f(x, y) # OK
f(x, z) # OK
jf = thunder.jit(f)
jf(x, y) # not OK
jf(x, z) # not OK
```
rel: https://github.com/Lightning-AI/lightning-thunder/pull/1847#discussion_r1984666983
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.