Make PyTorch models up to 40% faster! Thunder is a source to source compiler for PyTorch. It enables using different hardware executors at once; across one or thousands of GPUs.
Apache License 2.0
1.07k
stars
60
forks
source link
functionalization fails to replace in-place operands with new tensors #652
Note: If you have a model or program that is not supported yet but should be, please use the program coverage template.
š Bug
Functionalization fails to update some signatures in replacing in-place operands with new tensors.
Code sample
assert_close(e, e_) in the snippet below fails with
Traceback (most recent call last):
File "/home/mkozuki/ghq/github.com/Lightning-AI/lightning-thunder/issue_foobarbaz.py", line 33, in <module>
main()
File "/home/mkozuki/ghq/github.com/Lightning-AI/lightning-thunder/issue_foobarbaz.py", line 29, in main
torch.testing.assert_close(e, e_)
File "/home/mkozuki/ghq/github.com/crcrpar/pytorch/torch/testing/_comparison.py", line 1524, in assert_close
raise error_metas[0].to_error(msg)
AssertionError: Tensor-likes are not close!
Mismatched elements: 4 / 4 (100.0%)
Greatest absolute difference: 0.4451824426651001 at index (0,) (up to 1e-05 allowed)
Greatest relative difference: 0.4193967282772064 at index (0,) (up to 1.3e-06 allowed)
import torch
import thunder
def f(a: torch.Tensor, b: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
c = torch.exp(a)
d = torch.tanh(b)
e = c.view(-1)
e.add_(d.flatten())
d.div_(a)
return c, d, e / 2.0
def main():
a, b = [torch.randn((2, 2), device="cuda", requires_grad=False) for _ in range(2)]
a_, b_ = a.clone().detach(), b.clone().detach()
jitted_f = thunder.jit(f)
c, d, e = jitted_f(a, b)
c_, d_, e_ = f(a_, b_)
traces: list[thunder.core.trace.TraceCtx] = thunder.last_traces(jitted_f)
print(traces[0])
print(traces[2])
torch.testing.assert_close(c, c_)
torch.testing.assert_close(d, d_)
torch.testing.assert_close(e, e_)
if __name__ == "__main__":
main()
Traces before/after functionalization are as follows:
Note: If you have a model or program that is not supported yet but should be, please use the program coverage template.
š Bug
Functionalization fails to update some signatures in replacing in-place operands with new tensors.
Code sample
assert_close(e, e_)
in the snippet below fails withTraces before/after functionalization are as follows:
result = ltorch.true_divide(e, 2.0)
should beresult = ltorch.true_divide(t4, 2.0)