Skip to content

Refactor sparse unary ops tests#49158

Closed
vfdev-5 wants to merge 29 commits intopytorch:masterfrom
Quansight:vfdev-5/refactor-sparse-unaryops-tests
Closed

Refactor sparse unary ops tests#49158
vfdev-5 wants to merge 29 commits intopytorch:masterfrom
Quansight:vfdev-5/refactor-sparse-unaryops-tests

Conversation

@vfdev-5
Copy link
Copy Markdown
Contributor

@vfdev-5 vfdev-5 commented Dec 10, 2020

Description:

  • Added TestSparseUnaryUfuncs test case to test_sparse.py
  • Removed old test code for neg, asin, log1p ops on sparse data
  • Added sparse unary ops testing helpers in OpInfo, e.g. sample_sparse_inputs
  • Added abs, sign UnaryUfuncInfo to op_db

cc @mruberry

@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Dec 10, 2020

🔗 Helpful links

💊 CI failures summary and remediations

As of commit d352e0e (more details on the Dr. CI page):


Commit d352e0e 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.

Click here to manually regenerate this comment.

Comment thread test/test_sparse.py Outdated
@H-Huang H-Huang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Dec 10, 2020
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 11, 2020

Codecov Report

Merging #49158 (50d741e) into master (2d8795c) will increase coverage by 3.28%.
The diff coverage is 94.28%.

❗ Current head 50d741e differs from pull request most recent head d352e0e. Consider uploading reports for the commit d352e0e to get more accurate results

@@            Coverage Diff             @@
##           master   #49158      +/-   ##
==========================================
+ Coverage   77.47%   80.75%   +3.28%     
==========================================
  Files        1889     1975      +86     
  Lines      184759   216871   +32112     
==========================================
+ Hits       143140   175137   +31997     
- Misses      41619    41734     +115     

vfdev-5 added 2 commits December 15, 2020 03:21
@vfdev-5 vfdev-5 force-pushed the vfdev-5/refactor-sparse-unaryops-tests branch from 2414b6c to 523155a Compare December 24, 2020 12:15
@vfdev-5 vfdev-5 requested a review from mruberry December 24, 2020 18:20
@mruberry
Copy link
Copy Markdown
Collaborator

Failures are all in the base, sorry about that @vfdev-5. We can ignore them and I've reverted the PR causing them.

@vfdev-5 vfdev-5 force-pushed the vfdev-5/refactor-sparse-unaryops-tests branch from 3f35fe0 to 4adbfca Compare February 23, 2021 00:56
Comment thread test/test_sparse.py Outdated
Comment thread test/test_sparse.py
def _get_dense_and_sparse_samples(self, device, dtype, op):
test_backward = op.test_complex_grad or not dtype.is_complex
samples = op.sample_inputs(device, dtype, requires_grad=test_backward)
sparse_samples = op.sparse_sample_inputs(device, dtype, requires_grad=test_backward)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So in this model sparse_sample_inputs() are ADDITIONAL sparse-specific inputs?

Comment thread test/test_sparse.py
Comment thread test/test_sparse.py
Comment thread test/test_sparse.py Outdated
Comment thread test/test_sparse.py Outdated
Comment thread torch/testing/_internal/common_methods_invocations.py Outdated
Comment thread torch/testing/_internal/common_methods_invocations.py
Comment thread torch/testing/_internal/common_methods_invocations.py
dtype = kwargs.get('dtype', torch.double)
device = kwargs.get('device', 'cpu')
singular = kwargs.get("singular", False)
values_domain = kwargs.get("domain", None)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In the future we should also add tests to test_testing to ensure that random_sparse_matrix() (and make_tensor()) work as expected

Comment thread torch/testing/_internal/common_utils.py Outdated
Comment thread torch/testing/_internal/common_utils.py Outdated
dtype = kwargs.get('dtype', torch.double)
device = kwargs.get('device', 'cpu')
singular = kwargs.get("singular", False)
values_domain = kwargs.get("domain", None)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this function **kwargs?

We don't need to fix random_sparse_matric() in this PR but that seems odd, and it makes documenting its supported kwargs tricky.

A = torch.sparse_coo_tensor(
indices_tensor, values, (rows, columns), device=device, requires_grad=requires_grad
)
if not uncoalesced:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In the future I'd like to better consider how to generate sparse tensors, especially how to handle coalescing (or not) and the density target

Comment thread torch/testing/_internal/common_methods_invocations.py Outdated
Copy link
Copy Markdown
Collaborator

@mruberry mruberry left a comment

Choose a reason for hiding this comment

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

Hey @vfdev-5!

Overall this looks pretty good. I made some inline comments/questions, mostly requesting more comments in the code to explain the choices/assumptions we're making. In the future we probably want to look more closely at generating sparse tensors, too.

@vfdev-5 vfdev-5 requested a review from mruberry February 24, 2021 10:34
Copy link
Copy Markdown
Collaborator

@mruberry mruberry left a comment

Choose a reason for hiding this comment

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

Nice step forward for sparse testing, @vfdev-5!

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@github-actions github-actions Bot closed this May 12, 2022
@vfdev-5 vfdev-5 deleted the vfdev-5/refactor-sparse-unaryops-tests branch May 12, 2022 07:41
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Introduced operator variant to OpInfo

Context: Split of pytorch#49158

cc mruberry

Pull Request resolved: pytorch#50370

Reviewed By: mrshenli

Differential Revision: D25897821

Pulled By: mruberry

fbshipit-source-id: 4387ea10607dbd7209842b685f1794bcb31f434e
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Introduced AliasInfo for OpInfo.

Context: Split of pytorch#49158

cc mruberry , please let me know if you'd like to see here more code to cover

> [ ] fold test_op_aliases.py into OpInfo-based testing in test_ops.py

from pytorch#50006

and/or add `UnaryUfuncInfo('abs')` as discussed https://github.com/pytorch/pytorch/pull/49158/files#r548774221

Pull Request resolved: pytorch#50368

Reviewed By: ngimel

Differential Revision: D26177261

Pulled By: mruberry

fbshipit-source-id: 2e3884a387e8d5365fe05945375f0a9d1b5f5d82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed open source Stale 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.

6 participants