-
8000
-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Fix signature of torch.sparse_coo_tensor() #152681
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
base: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/152681
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit a6f73ec with merge base 3443627 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@pytorchbot label "release notes: sparse" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @ILCSFNO!
This PR eliminates the TypeError reported in #145371 and is a right step forward fixing the issue but we are not quite there yet.
To be specific, the behavior of sparse_coo_tensor with and without the size
argument should be identical. With this PR, there exists a couple of discrepancies. For instance, consider the following sample data
# uncoalesced indices
i = torch.tensor([[0, 1, 0], [1, 2, 0]])
# coalesced indices
i2 = torch.tensor([[0, 0, 1], [0, 1, 2]])
# values
v = torch.tensor([3.0, 4.0, 5.0])
s = (2, 3)
then:
Inconsistency 1
# succeeds, UNEXPECTED:
result1 = torch.sparse_coo_tensor(i, v, check_invariants=True, is_coalesced=True)
# fails, EXPECTED:
result2 = torch.sparse_coo_tensor(i, v, s, check_invariants=True, is_coalesced=True)
# -> RuntimeError: cannot set is_coalesced to true if indices correspond to uncoalesced COO tensor
Inconsistency 2
result1 = torch.sparse_coo_tensor(i, v, check_invariants=False, is_coalesced=True)
result2 = torch.sparse_coo_tensor(i, v, s, check_invariants=False, is_coalesced=True)
assert result1.is_coalesced() == result2.is_coalesced() # FAILS
Also a related bug:
result1 = torch.sparse_coo_tensor(i2, v, check_invariants=True, is_coalesced=True)
result2 = torch.sparse_coo_tensor(i2, v, s, check_invariants=True, is_coalesced=True)
assert result1.is_coalesced() == result2.is_coalesced() # FAILS
@pearu Fixed ready for your check again! Thanks! |
Fixes #145371
@pearu Searched all and find these codes, wondering whether is the root cause of the issue, could you have a review? Thanks a lot!