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
Sparse CSR: Add torch.sin
#68123
Sparse CSR: Add torch.sin
#68123
Conversation
CI Flow Status⚛️ CI FlowRuleset - Version:
You can add a comment to the PR and tag @pytorchbot with the following commands: # ciflow rerun, "ciflow/default" will always be added automatically
@pytorchbot ciflow rerun
# ciflow rerun with additional labels "-l <ciflow/label_name>", which is equivalent to adding these labels manually and trigger the rerun
@pytorchbot ciflow rerun -l ciflow/scheduled -l ciflow/slow For more information, please take a look at the CI Flow Wiki. |
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit 97de323 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
test/test_sparse_csr.py
Outdated
@ops(_sparse_csr_ops) | ||
def test_sparse_csr_no_error(self, device, dtype, op): | ||
samples = op.sample_inputs(device, dtype) | ||
|
||
if len(samples) == 0: | ||
self.skipTest("Skipped! No sample inputs!") | ||
|
||
for sample in samples: | ||
assert isinstance(sample.input, torch.Tensor) | ||
if sample.input.ndim != 2: | ||
continue | ||
|
||
expected = op(sample.input) | ||
assert torch.is_tensor(expected) | ||
output = op(sample.input.to_sparse_csr()) | ||
assert torch.is_tensor(output) |
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.
The plan is to look at it again, and have a specialized test for sparse CSR tensors ((if everyone agrees)).
I plan to take a look at it in a separate PR next week.
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.
Having an OpInfo-based test that checks that the function doesn't error out on sparse input is good, but let's also add the correctness check.
Co-authored-by: Ivan Yashchuk <IvanYashchuk@users.noreply.github.com>
" for self, and ", | ||
src.layout(), | ||
" for src"); |
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.
Earlier, the message ended with something like:
but got self, src: kStridedkStrided
if (result.numel() == 0) { | ||
at::native::resize_as_sparse_csr_(result, self); | ||
} |
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.
at::native::resize_output(result.col_indices(), self.col_indices().sizes());
// OR
result.col_indices().resize_(self.col_indices().sizes());
don't resize the result.col_indices()
tensor. Is this a bug, or is it expected? cc: @IvanYashchuk @cpuhrsch
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.
If we write
auto col_indices = result.col_indices();
col_indices.resize_(self.col_indices().sizes());
We would see that col_indices
is resized, but result.col_indices()
would have the original size. To replace result.col_indices()
we would need to use set_member_tensors
method (result.unsafeGetTensorImpl()->set_member_tensors(...)`).
It's expected, this issue is related #63549.
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.
Thank you @krshrimali! I've got only two minor comments. In a follow-up PR, we should expand the tests to out and inplace variants.
@cpuhrsch has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
raise ValueError("Expected 2D tensor but got tensor with dimension: {sample.input.ndim}.") | ||
|
||
expected = op(sample.input) | ||
assert torch.is_tensor(expected) |
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.
nit: it might be better to use self.assertTrue to get a better error message (we can do that in a follow-up PR or together with other changes for more unary ops)
This PR attempts to add support for
torch.sin
for sparse CSR tensors.This aims to be a revised implementation (in some form) of #68083, and the implementation aims to be similar to that in
SparseTensorMath.cpp
fileThe tests and
empty_like
support for sparse CSR tensors (with a minor correction) are borrowed from #68083 temporarily to assist CI with testing this PR. :)cc @nikitaved @pearu @cpuhrsch @IvanYashchuk @krshrimali