Lightning-AI / Lightning-AI/lightning-thunder
[diagonal] Inconsistency between compile time and runtime
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 121
- PR merge metrics
- No merged PRs in 30d
Description
## 🐛 Bug
For the second sample https://github.com/Lightning-AI/lightning-thunder/blob/2d1b36fe7c76e7f3318df7ba8de31ab19e97ed7a/thunder/tests/opinfos.py#L3700-L3706, Thunder generates a trace whose shape information is different from runtime results.
### To Reproduce
#### Code sample
```python
import torch
import thunder
def f(x, offset, dim1, dim2):
return torch.diagonal(x, offset, dim1, dim2)
x, offset, dim1, dim2 = torch.ones((1, 2, 0, 3)), -1, 0, -1
ref = f(x, offset, dim1, dim2)
jitted = thunder.jit(f)
out = jitted(x, offset, dim1, dim2)
print(thunder.last_traces(jitted)[0])
```
##### console
```
# Constructed by Unwrap the actual return value
import torch
from thunder.executors.torchex import no_autocast
@torch.no_grad()
@no_autocast
def computation(t_0):
# t_0: "cpu f32[1, 2, 0, 3]"
t44 = torch.diagonal(t_0, -1, 0, -1) # t44: "cpu f32[2, 0]"
# t44 = ltorch.diagonal(t_0, -1, 0, -1) # t44: "cpu f32[2, 0]"
# t31 = prims.transpose(t_0, (1, 2, 0, 3)) # t31: "cpu f32[2, 0, 1, 3]"
# t32 = prims.iota(0, start=0, step=1, device=devices.Device("cpu"), dtype=dtypes.int64) # t32: "cpu i64[]"
# t33 = prims.iota(0, start=1, step=1, device=devices.Device("cpu"), dtype=dtypes.int64) # t33: "cpu i64[]"
# t34 = prims.reshape(t31, (2, 0, 3)) # t34: "cpu f32[2, 0, 3]"
# t35 = prims.lt(t32, 0) # t35: "cpu b8[]"
# t36 = prims.where(t35, 3, 0) # t36: "cpu i64[]"
# t37 = prims.add(t32, t36) # t37: "cpu i64[]"
# t38 = prims.lt(t33, 0) # t38: "cpu b8[]"
# t39 = prims.where(t38, 1, 0) # t39: "cpu i64[]"
# t40 = prims.add(t33, t39) # t40: "cpu i64[]"
# t41 = prims.mul(t40, 3) # t41: "cpu i64[]"
# t42 = prims.add(t37, t41) # t42: "cpu i64[]"
# t43 = prims.take(t34, t42, 2) # t43: "cpu f32[2, 0, 1]"
# t44 = prims.squeeze(t43, (2,)) # t44: "cpu f32[2, 0]"
return (t44,)
thunder_result.shape = torch.Size([2, 0, 0]), torch_result.shape = torch.Size([2, 0, 0])
```
### Expected behavior
`t44` should have `(2, 0, 0)` instead.
### Additional context
- https://github.com/NVIDIA/Fuser/issues/4414
- https://github.com/Lightning-AI/lightning-thunder/pull/2031#issuecomment-2876974925
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.
Research direction
Start with the second diagonal sample in thunder/tests/opinfos.py around lines 3700-3706 and run the reproduction against Thunder and PyTorch. Compare the generated trace's diagonal shape with the runtime result, using the linked NVIDIA Fuser issue and PR discussion for context. Done means the trace reports t44 with shape (2, 0, 0), matching runtime.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100