lightning-thunder icon indicating copy to clipboard operation
lightning-thunder copied to clipboard

Record `Tensor.clone()` in trace

Open crcrpar opened this issue 1 year ago • 0 comments

          It should work if there's a clone between reshape and in-place operation. Currently, it fails with the same error because `clone` is not recorded on the trace:

https://github.com/Lightning-AI/lightning-thunder/blob/ffbebe07bdf003c3a60f2cab88298e96b80bdbba/thunder/torch/init.py#L2521-L2525 In the code review, it was decided that it's fine for the clone not to record itself in the trace, but now it seems we need this clarity to break the chain of view ops (https://github.com/Lightning-AI/lightning-thunder/pull/429#issuecomment-2121041926). The code snippet I tried:

import thunder
import torch

def f(x):
  y = x.reshape(6, 4).clone()
  y.add_(1)
  return y

x = torch.randn((4, 6))
jf = thunder.jit(f)
jf(x)

Originally posted by @IvanYashchuk in https://github.com/Lightning-AI/lightning-thunder/pull/958#discussion_r1715102637

cc @apaz-cli

crcrpar avatar Aug 13 '24 18:08 crcrpar