-
Notifications
You must be signed in to change notification settings - Fork 24.9k
add mv operator to SparseTensor #21782
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
Conversation
add mv operator to SparseTensor
@ezyang if you have time to review this PR. Thanks. |
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.
I would love to see a doc update saying that this does not work on cuda sparse tensors. Also, @ezyang , what was our resolution for the torch.sparse
namespace? Should this be in there or not?
@pytorchbot retest this please. |
@ezyang I think this is ready for review. Thanks |
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.
Hi @shihongzhi, unfortunately, writing a (naive) matrix-vector multiply by hand is not the recommended way of solving the issue. One reason it's not recommended is that in your PR, there is no implementation of the kernel in CUDA; ideally, we'd also have a CUDA implementation.
Since a matrix-vector multiply is simply a matrix-matrix multiply, where the latter matrix is n x 1
matrix, the easiest implementation is to unsqueeze
the vector into a matrix, call the existing matrix-matrix multiply, and then squeeze it back into a vector.
I don't remember what our resolution was. Since @weiyangfb is not working on sparse anymore, we will probably end up relitigating this when someone else picks it up. However, since (FWIW, these days, I'm a lot more on the side of "dense semantics don't have to match sparse semantics exactly, no namespace needed, you never really want a densified gradient flowing to a sparse input") |
@ezyang Thank for for review. I will use matrix-matrix multiply, and also to add a CUDA implementation. |
Good, this is an improvement. But you need to do more:
Also I'm pretty sure you need a squeeze at the end. Don't forget to dismiss the "changes requested" when you want more review. |
2. adapt mv_sparse for cpu and cuda both
@pytorchbot rebase this please. |
@pytorchbot rebase this please. |
@ezyang I think it's ready for review again. |
# Conflicts: # aten/src/ATen/native/native_functions.yaml
@kurtamohler and @nikitaved, since y'all are getting more involved in sparse, do you think you could help review this? |
y = torch.ones(3, device=self.device) | ||
|
||
self.assertEqual(self.value_tensor([3, 9]), x.matmul(y)) | ||
|
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.
We should probably have test cases that make sure your asserts are triggered correctly, with self.assertRaisesRegex
.
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.
Sorry, I don't use self.assertRaisesRegex
before. So I don't how and why to use this.
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.
self.assertRaisesRegex
is for checking to make sure functions raise exceptions when expected. The way to use it is:
with self.assertRaisesRegex(<type of exception>, <regex string that matches the expected error message>):
<call the function with arguments that will cause the expected exception>
The error messages you're regex-matching against are the messages you wrote in your TORCH_CHECK
calls. There are many examples in test_sparse.py
.
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.
Done. Thank you for your detail explain.
💊 CircleCI build failures summary and remediationsAs of commit 45c7079 (more details on the Dr. CI page):
🕵️ 2 new failures recognized by patternsThe following build failures do not appear to be due to upstream breakages (reran 1 job to discount flakiness):
|
@kurtamohler could you help review the code again? thanks. |
Looks like you still need to fix some tests
|
Done. Fixed this bug |
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.
@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Fixes #21266 add mv operator to SparseTensor