8000 Fix signature of torch.sparse_coo_tensor() by ILCSFNO · Pull Request #152681 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

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

8000
Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ILCSFNO
Copy link
Contributor
@ILCSFNO ILCSFNO commented May 2, 2025

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!

@ILCSFNO ILCSFNO requested review from albanD and soulitzer as code owners May 2, 2025 11:01
Copy link
pytorch-bot bot commented May 2, 2025

🔗 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 Failures

As of commit a6f73ec with merge base 3443627 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@ILCSFNO
Copy link
Contributor Author
ILCSFNO commented May 2, 2025

@pytorchbot label "release notes: sparse"

8000

@pytorch-bot pytorch-bot bot added the release notes: sparse release notes category label May 2, 2025
@albanD albanD requested a review from pearu May 2, 2025 13:55
@mikaylagawarecki mikaylagawarecki added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label May 2, 2025
Copy link
Collaborator
@pearu pearu left a 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

@ILCSFNO
Copy link
Contributor Author
ILCSFNO commented May 16, 2025

@pearu Fixed ready for your check again! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open source release notes: sparse release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set size when is_coalesced is set in torch.sparse_coo_tensor()
5 participants
0