-
Notifications
You must be signed in to change notification settings - Fork 24.4k
The compilation result is incorrect when torch.compile compiles code containing torch.nonzero. #155324
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
Comments
how is is incorrect? |
|
I can't repro this. What torch version is this on, could you try upgrading to the latest torch? |
I tried version 2.7.0 and it indeed has no problem, but versions 2.7.0 below have this issue. Since our projects are all developed based on 2.5.1, the workload of upgrading to 2.7.0 is relatively large. Is there a patch available to fix this? |
@hyriverside I'd recommend upgrading to 2.7.0, since 2.5.1 is a relatively old version, there are many PRs in between and it's hard to tell which PR fixed the issue. |
Uh oh!
There was an error while loading. Please reload this page.
🐛 Describe the bug
import numpy as np
arr3 = np.array([
[0, 1],
[2, 0],
[3, 4],
[0, 0],
[5, 0],
[0, 6],
])
print(arr3)
import torch
tensor0 = torch.from_numpy(arr3)
print(tensor0)
def non_zero(x):
tmps = torch.nonzero(x)
return (tmps[:,0], tmps[:,1])
print("non_zero ori: ", non_zero(tensor0))
print("compiled non_zero", torch.compile(non_zero)(tensor0))
#output
[[0 1]
[2 0]
[3 4]
[0 0]
[5 0]
[0 6]]
tensor([[0, 1],
[2, 0],
[3, 4],
[0, 0],
[5, 0],
[0, 6]])
non_zero ori: (tensor([0, 1, 2, 2, 4, 5]), tensor([1, 0, 0, 1, 0, 1]))
compiled non_zero (tensor([0, 1, 2, 2, 4, 5]), tensor([1, 2, 2, 4, 5, 1]))
Versions
The output result after compilation is incorrect.
cc @chauhang @penguinwu
The text was updated successfully, but these errors were encountered: