Content-Length: 271607 | pFad | http://github.com/pytorch/pytorch/issues/155324

9C The compilation result is incorrect when torch.compile compiles code containing torch.nonzero. · Issue #155324 · pytorch/pytorch · GitHub
Skip to content

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

Closed
hyriverside opened this issue Jun 6, 2025 · 5 comments

Comments

@hyriverside
Copy link

hyriverside commented Jun 6, 2025

🐛 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

@ALUMINIS650
Copy link

how is is incorrect?

@hyriverside
Copy link
Author

how is is incorrect?
correct is (tensor([0, 1, 2, 2, 4, 5]), tensor([1, 0, 0, 1, 0, 1]))
compiled is (tensor([0, 1, 2, 2, 4, 5]), tensor([1, 2, 2, 4, 5, 1]))

@mikaylagawarecki
Copy link
Contributor

mikaylagawarecki commented Jun 6, 2025

I can't repro this. What torch version is this on, could you try upgrading to the latest torch?

@mikaylagawarecki mikaylagawarecki added the needs reproduction Someone else needs to try reproducing the issue given the instructions. No action needed from user label Jun 6, 2025
@hyriverside
Copy link
Author

hyriverside commented Jun 8, 2025

I can't repro this. What torch version is this on, could you try upgrading to the latest torch?
hi @mikaylagawarecki ,

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?

@yf225 yf225 removed the needs reproduction Someone else needs to try reproducing the issue given the instructions. No action needed from user label Jun 9, 2025
@yf225
Copy link
Contributor

yf225 commented Jun 9, 2025

@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.

@yf225 yf225 closed this as completed Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/pytorch/pytorch/issues/155324

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy