Skip to content

Update misleading torch.sparse_coo_tensor error check#161900

Closed
parsshar-RH wants to merge 1 commit intopytorch:mainfrom
parsshar-RH:issue-160622
Closed

Update misleading torch.sparse_coo_tensor error check#161900
parsshar-RH wants to merge 1 commit intopytorch:mainfrom
parsshar-RH:issue-160622

Conversation

@parsshar-RH
Copy link
Collaborator

@parsshar-RH parsshar-RH commented Sep 1, 2025

Fixes #160622

Summary

Updated the misleading torch.sparse_coo_tensor error check to provide clear context.
earlier:
RuntimeError: number of dimensions must be sparse_dim (3) + dense_dim (0), but got 1

Updated:
RuntimeError: 'len(size) == sparse_dim + dense_dim' is not satisfied: len(size) = 1, sparse_dim = 3, dense_dim = 0

Impacts:

  • Comprehensive error message that will improve developer experience.
  • module: sparse

cc @alexsamardzic @nikitaved @pearu @cpuhrsch @amjames @bhosmer @jcaip

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 1, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/161900

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

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

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

@pytorch-bot pytorch-bot bot added the release notes: sparse release notes category label Sep 1, 2025
@parsshar-RH
Copy link
Collaborator Author

@salilsdesai @kimishpatel @digantdesai @jianyuh

Please review the PR
Thanks

@parsshar-RH
Copy link
Collaborator Author

@pytorchbot label "module: sparse"

@pytorch-bot pytorch-bot bot added the module: sparse Related to torch.sparse label Sep 9, 2025
@bdhirsh bdhirsh requested review from cpuhrsch and pearu September 9, 2025 17:21
@bdhirsh bdhirsh added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 9, 2025
Copy link
Collaborator

@nikitaved nikitaved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the update. Thank you! @pearu , the call is ultimately yours as you were active in the discussion.

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.

LGTM! Thanks, @parsshar-RH!

Btw, apparently we don't have tests for exceptions that may be raised from sparse COO tensors construction. For sparse compressed tensors we have

def test_invalid_input(self, layout, device, target):

However, I don't expect that the missing tests for sparse COO tensors covering all invalid input cases should be implemented in this PR, but it would be a nice follow-up that would reveal if there exists more exception messages that could be improved similar to this PR.

@parsshar-RH
Copy link
Collaborator Author

@pearu @nikitaved

Thanks for the valuable feedback and reviews.
I appreciate you pointing out the lack of exception tests for sparse COO tensors.
I will address the feedback in a follow-up PR

Thanks

@pearu
Copy link
Collaborator

pearu commented Sep 10, 2025

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 10, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
Fixes pytorch#160622

### Summary
Updated the misleading torch.sparse_coo_tensor error check to provide clear context.
earlier:
`RuntimeError: number of dimensions must be sparse_dim (3) + dense_dim (0), but got 1`

Updated:
`RuntimeError: 'len(size) == sparse_dim + dense_dim' is not satisfied: len(size) = 1, sparse_dim = 3, dense_dim = 0`

**Impacts:**

- Comprehensive error message that will improve developer experience.
- module: sparse

Pull Request resolved: pytorch#161900
Approved by: https://github.com/nikitaved, https://github.com/pearu
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
Fixes pytorch#160622

### Summary
Updated the misleading torch.sparse_coo_tensor error check to provide clear context.
earlier:
`RuntimeError: number of dimensions must be sparse_dim (3) + dense_dim (0), but got 1`

Updated:
`RuntimeError: 'len(size) == sparse_dim + dense_dim' is not satisfied: len(size) = 1, sparse_dim = 3, dense_dim = 0`

**Impacts:**

- Comprehensive error message that will improve developer experience.
- module: sparse

Pull Request resolved: pytorch#161900
Approved by: https://github.com/nikitaved, https://github.com/pearu
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
Fixes pytorch#160622

### Summary
Updated the misleading torch.sparse_coo_tensor error check to provide clear context.
earlier:
`RuntimeError: number of dimensions must be sparse_dim (3) + dense_dim (0), but got 1`

Updated:
`RuntimeError: 'len(size) == sparse_dim + dense_dim' is not satisfied: len(size) = 1, sparse_dim = 3, dense_dim = 0`

**Impacts:**

- Comprehensive error message that will improve developer experience.
- module: sparse

Pull Request resolved: pytorch#161900
Approved by: https://github.com/nikitaved, https://github.com/pearu
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
Fixes pytorch#160622

### Summary
Updated the misleading torch.sparse_coo_tensor error check to provide clear context.
earlier:
`RuntimeError: number of dimensions must be sparse_dim (3) + dense_dim (0), but got 1`

Updated:
`RuntimeError: 'len(size) == sparse_dim + dense_dim' is not satisfied: len(size) = 1, sparse_dim = 3, dense_dim = 0`

**Impacts:**

- Comprehensive error message that will improve developer experience.
- module: sparse

Pull Request resolved: pytorch#161900
Approved by: https://github.com/nikitaved, https://github.com/pearu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged module: sparse Related to torch.sparse 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.

torch.sparse_coo_tensor fails for valid 1D case with misleading dimension error

6 participants