Repository navigation
Conversation
- updated unary ops to fix negative op dispatch
💊 CI failures summary and remediationsAs of commit 09d14eb (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).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 21 times. |
pearu
left a comment
There was a problem hiding this comment.
LGTM, added few nits to tests.
Could you also add tests for autograd support of sparse neg and asin?
Nvm, I noticed that the plan is to address autograd support in another PR. |
Codecov Report
@@ Coverage Diff @@
## master #44028 +/- ##
=======================================
Coverage 68.08% 68.08%
=======================================
Files 384 384
Lines 49776 49776
=======================================
Hits 33892 33892
Misses 15884 15884 Continue to review full report at Codecov.
|
|
Hey @vfdev-5! Thanks for fixing the negative alias. I just have a couple questions about dispatch and test coverage. |
|
@mruberry I updated the PR according to your review and left one thread as unresolved if we have to continue the discussion about the dispatch. |
|
Looking good, @vfdev-5, we can revisit dispatch later as I don't have a strong opinion on it at the moment. Just a couple nits: cleaning up an assert, minor comment update, and you can remove an extra check. After that I think we're good to go! Nice work. |
vfdev-5
left a comment
There was a problem hiding this comment.
@mruberry thanks a lot for your review, explanations and suggestions ! I really appreciate them !
I'll update the code and tests according to that. By the way, if you do not mind I can also update in this PR the code and test for log1p I inspired a lot from (I also rename the PR mentioning log1p). Otherwise, I can create another PR for that, but changes are rather minor...
- additionally improved code/tests for log1p
Sure. If you'd like to add log1p that's OK. |
| return r; | ||
| } | ||
|
|
||
| SparseTensor& neg_sparse_(SparseTensor& t) { |
There was a problem hiding this comment.
Writing each of these separately is OK for now but in the future we should probably make a helper function that implements unary elementwise functions (with an option for whether they are or aren't linear maps).
| with self.assertRaisesRegex(RuntimeError, "log1p of a sparse tensor is made to be non-differentiable"): | ||
| y.backward(x) | ||
|
|
||
| def test_log1p(self): |
There was a problem hiding this comment.
We should think about generating these tests in the future using the OpInfos in common_methods_invocations.py. We could add an attribute to the OpInfos like "supports_sparse" to only selection functions intended to work on sparse tensors.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
We should stop this PR here to merge it. A separate PR could add test support (using OpInfos) or implementation support (see native/UnaryOps.cpp for some ideas) for ops like this, if you're planning to add more of them, that is. I'm not sure how many there are. |
|
@mruberry thanks for the suggestions ! Yes, the plan is to add more functions like these. Here is a list of functions that should be potentially added: https://github.com/Quansight-Labs/rfcs/blob/pearu/rfc0005/RFC0003-sparse-roadmap/SparseSupportState.md#trigonometry-functions For a test support using OpInfos, we have N similar element-wise functions to test on various sparse data. I was analyzing your PR on OpInfo and UnaryUfuncInfo. Do you think Concering implementation support, I think we can do this with a template functions like that SparseTensor& asin_out_sparse(SparseTensor& r, const SparseTensor& t) {
return linmap_unary_op_impl_out_sparse<&Tensor::asin_>(r, t, "asin: in-place on uncoalesced tensors is not supported");
}
using FuncSig = void (Tensor::*)();
template<FuncSig F>
void linmap_unary_op_impl_out_sparse(Tensor & r, const Tensor & t, const std::string & err_msg)
{
TORCH_CHECK(r.is_sparse(), "Tensor should be sparse");
TORCH_CHECK(t.is_sparse(), "Tensor should be sparse");
if (is_same_tensor(r, t)) {
// don't have in-place asin for uncoalesced input because coalesce() is not in-place, see above comment
TORCH_CHECK(r.is_coalesced(), err_msg);
} else {
copy_sparse_to_sparse_(r, t.coalesce());
}
(r._values().*F)();
return r;
}I'll try to apply these ideas to #43330 |
|
@vfdev-5 Yep. I think extending the current UnaryUfuncInfos with sparse properties and data would be interesting to pursue. Maybe a function like "get_sparse_samples" analogous to Template sounds like a great idea, and thanks for the RFC link. I'd like to see the Sparse tracking issue (#44634) with when we expect these features to be delivered to, so we can coordinate with PyTorch releases and better understand our sparse investment. |
@mruberry |
UnaryUfuncInfos is currently tightly coupled to testing against NumPy, and this will probably change in the future. When adding annotations for sparse support, however, I was thinking you'd write tests explicitly targeting sparse. These sparse tests don't have to use the current references. They could even have their own |
|
@mruberry thanks a lot for prompt reply !
Yes, I was thinking about something like @ops(op_db)
def test_unary_sparse_ops(self, op):
sparse_tensor = op.sample_sparse_input(...)
# run and assert testMy problem is with predefined |
|
Sure, you could create but if you're going to do that more than once you might as well pre-filter and save the filtered list, like your suggesting. |
|
Example sublists: pytorch/test/test_unary_ufuncs.py Line 199 in 76dc50e pytorch/test/test_unary_ufuncs.py Line 154 in 76dc50e |
|
That's true! But in addition I'm also missing there functions like |
It should be straightforward to add those functions. |
Description:
asinandnegops similarly tolog1popnegativeandarcsinBackprop will be addressed in another PR.