Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate symbols from autoregistration (torch.foo vs. torch.Tensor.foo) #1140

Open
t-vi opened this issue Sep 11, 2024 · 1 comment
Open
Labels
bug Something isn't working dynamo+thunder for things that could be applicable to the dynamo+thunder frontend

Comments

@t-vi
Copy link
Collaborator

t-vi commented Sep 11, 2024

Autoregistration registers duplicate symbols under the same name, which is not ideal, and we should go the same way as for manually registered symbols (see below).

Repro:

import thunder, torch
def fn(a):
     return torch.positive(a.positive())
jf = thunder.jit(fn)
jf(torch.randn(1))
lt = thunder.last_traces(jf)[0]
print(lt)
s1 = lt.bound_symbols[1].sym
s2 = lt.bound_symbols[2].sym
assert s1 == s2, f"{s1} != {s2}"
import thunder
import thunder.torch as ltorch
import torch
from thunder.executors.torchex import no_autocast

@torch.no_grad()
@no_autocast
def computation(a):
  # a: "cpu f32[1]"

  # <ipython-input-2-d90f2ca6b8df>:2: 	    return torch.positive(a.positive())
  t0 = ltorch.positive(a)  # t0: "cpu f32[1]"
  t1 = ltorch.positive(t0)  # t1: "cpu f32[1]"
  return t1

AssertionError                            Traceback (most recent call last)
----> 1 assert s1 == s2, f"{s1} != {s2}"

AssertionError: [Symbol name=positive] != [Symbol name=positive]

By contrast, manually registered functions register both with a single symbol:

@torchsymbol(torch.numel, torch.Tensor.numel, is_method=True)
def numel(a: TensorLike, /) -> int:
return a._numel
register_method("numel", numel)

(credit for discovery and analysis: @k223kim , thank you)

@t-vi t-vi added the bug Something isn't working label Sep 11, 2024
@tfogal tfogal added the dynamo+thunder for things that could be applicable to the dynamo+thunder frontend label Sep 11, 2024
@tfogal
Copy link
Collaborator

tfogal commented Sep 11, 2024

@kiya00 is this something that you could take a look at?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dynamo+thunder for things that could be applicable to the dynamo+thunder frontend
Projects
None yet
Development

No branches or pull requests

2 participants