Repository navigation
Conversation
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit bb5e742 (more details on the Dr. CI page): Commit bb5e742 was recently pushed. Waiting for builds... 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 to the (internal) Dr. CI Users group. |
0bc74ee to
87f7c4b
Compare
pearu
left a comment
There was a problem hiding this comment.
Looks good.
I added some suggestions on what to test: hybrid tensors, negative entries in uncoalesced tensors.
Also, I think inplace abs on uncoalesed tensors should never be implemented, hence, drop the "yet!" promise.
- test backprop for abs - commented test backprop for sign
87f7c4b to
8f47993
Compare
pearu
left a comment
There was a problem hiding this comment.
Looks good!
I have some nit-comments regarding tests but I think you can drop the Draft status.
|
I think this PR is a good example of why test infrastructure improvements can help. Adding sparse support to two
There is quite a bit of generic test machinery in Note, no action needed in this PR, but we should follow up on this soon so next PRs that add sparse support to new operators are easier/smaller. |
- refactored python tests for those functions
There was a problem hiding this comment.
@vfdev-5, I like the nonlinmap_unary_op_impl_out_sparse approach, thanks!
In the testing site, I added suggestions for code reduction. In fact, the code reduction could be increased even more if the suggested for-loops could be incorporated into the _test_unary_op method.
|
|
||
| if ops_inplace is not None: | ||
| for op in ops_inplace: | ||
| self.assertEqual(expected_output, op(sparse_tensor.clone().coalesce()).to_dense()) |
There was a problem hiding this comment.
This does not test in-place operation. Use:
sparse_tensor_copy = sparse_tensor.clone().coalesce()
op(sparse_tensor_copy)
self.assertEqual(expected_output, sparse_tensor_copy.to_dense())
| sparse_tensor, | ||
| ops=(torch.log1p, torch.Tensor.log1p), | ||
| ops_out=(torch.log1p, ), | ||
| ops_inplace=(torch.Tensor.log1p_, ) |
There was a problem hiding this comment.
There is also torch.log1p_. Could you add it to ops_inplace?
| torch.negative, torch.Tensor.negative, torch.Tensor.negative_, | ||
| operator.neg | ||
| ), | ||
| ops_out=(torch.neg, torch.negative), |
There was a problem hiding this comment.
Is there a reason why
ops_inplace = (torch.neg_, torch.negative_, torch.Tensor.neg_, torch.Tensor.negative_)
is not used here?
| def _test_log1p_tensor(self, sparse_tensor): | ||
| self._test_unary_op( | ||
| sparse_tensor, | ||
| ops=(torch.log1p, torch.Tensor.log1p), |
There was a problem hiding this comment.
Include torch.log1p_, torch.Tensor.log1p_ to ops.
| @@ -1846,29 +1856,14 @@ def test_neg_negative(self): | |||
| self._test_neg_negative(input_uncoalesced) | |||
There was a problem hiding this comment.
This code block could be reduced to:
for indices, values, size in [
([[0, 1, 2]], [3.0, -4.0, 5.0], [3,]),
([[1, 3], [2, 4]], [[-1.0, 3.0], [-5.0, 7.0]], [4, 5, 2]),
([[0, 1, 2, 0, 1, 2]], 2.0, -3.0, -4.0, 1.0, -1.0, 1.5], [3, ]),
(torch.zeros([2, 0]), torch.zeros([0, 5, 5, 5, 5, 5, 5, 0]), [0, 0, 5, 5, 5, 5, 5, 5, 0])
]:
input = torch.sparse_coo_tensor(indices, values, size, device=self.device)
if not self.is_uncoalesced:
input = input.coalesce()
self._test_neg_negative(input)
| if not self.is_uncoalesced: | ||
| input_coalesced = torch.sparse_coo_tensor( | ||
| indices=torch.tensor([[0, 1, 2, 3]]), | ||
| values=torch.tensor([3.0, -4.0, 5.0, -6.0]), | ||
| size=[4, ], | ||
| device=self.device | ||
| ).coalesce() | ||
| self._test_sign(input_coalesced) | ||
|
|
||
| # hybrid sparse input | ||
| input_coalesced = torch.sparse_coo_tensor( | ||
| indices=torch.tensor([[1, 3], [2, 4]]), | ||
| values=torch.tensor([[-1.0, 3.0], [-5.0, 7.0]]), | ||
| size=[4, 5, 2], | ||
| device=self.device | ||
| ).coalesce() | ||
| self._test_sign(input_coalesced) | ||
|
|
||
| if self.is_uncoalesced: | ||
| # test uncoalesced input | ||
| input_uncoalesced = torch.sparse_coo_tensor( | ||
| indices=torch.tensor([[0], [1], [2], [0], [1], [2]]).transpose(1, 0), | ||
| values=torch.tensor([2.0, -3.0, 4.0, 1.0, -1.0, 1.0]), | ||
| size=[3, ], | ||
| device=self.device | ||
| ) | ||
| self._test_sign(input_uncoalesced) | ||
|
|
||
| input_uncoalesced = torch.sparse_coo_tensor( | ||
| indices=torch.zeros([2, 0]), | ||
| values=torch.zeros([0, 5, 5, 5, 5, 5, 5, 0]), | ||
| size=[0, 0, 5, 5, 5, 5, 5, 5, 0], | ||
| device=self.device | ||
| ) | ||
| self._test_sign(input_uncoalesced) |
There was a problem hiding this comment.
Reduce this code block to
for indices, values, size in [
([[0, 1, 2]], [3.0, -4.0, 5.0], [3,]),
([[1, 3], [2, 4]], [[-1.0, 3.0], [-5.0, 7.0]], [4, 5, 2]),
([[0, 1, 2, 0, 1, 2]], 2.0, -3.0, -4.0, 1.0, -1.0, 1.5], [3, ]),
(torch.zeros([2, 0]), torch.zeros([0, 5, 5, 5, 5, 5, 5, 0]), [0, 0, 5, 5, 5, 5, 5, 5, 0])
]:
input = torch.sparse_coo_tensor(indices, values, size, device=self.device)
if not self.is_uncoalesced:
input = input.coalesce()
self._test_sign(input)
| def _test_sign(self, sparse_tensor): | ||
| self._test_unary_op( | ||
| sparse_tensor, | ||
| ops=(torch.sign, torch.Tensor.sign), |
There was a problem hiding this comment.
OT: Is there a reason why torch.sign_ is missing?
| @@ -5935,10 +5939,14 @@ | |||
| - func: sign_(Tensor(a!) self) -> Tensor(a!) | |||
| use_c10_dispatcher: full | |||
| variants: method | |||
There was a problem hiding this comment.
Perhaps OT: is there a reason why torch.sign_ does not exist? Use variants: function, method to make torch.sign_ a thing.
| TORCH_CHECK(r.is_sparse(), "Tensor should be sparse"); | ||
| TORCH_CHECK(t.is_sparse(), "Tensor should be sparse"); |
There was a problem hiding this comment.
Can the user trigger these errors with their input? If not, use TORCH_INTERNAL_ASSERT instead of TORCH_CHECK.
| TORCH_CHECK(r.is_sparse(), "Tensor should be sparse"); | ||
| TORCH_CHECK(t.is_sparse(), "Tensor should be sparse"); |
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
|
Let's close this PR as stale since this is unlikely to move it forward. |
Description:
absandsignops similarly tolog1poplog1p,asin,negopsUnaryUfuncInfo(Added sparse support for asin and neg functions, updated log1p #44028 (comment))OLD
absandsignops similarly tolog1popabs.sign-> to fix in another PRabsoluteBlocked by #43699