Skip to content

Allow Tensor-likes in torch.autograd.gradcheck#43877

Closed
hameerabbasi wants to merge 3 commits intopytorch:masterfrom
hameerabbasi:gradcheck-override
Closed

Allow Tensor-likes in torch.autograd.gradcheck#43877
hameerabbasi wants to merge 3 commits intopytorch:masterfrom
hameerabbasi:gradcheck-override

Conversation

@hameerabbasi
Copy link
Copy Markdown
Collaborator

@hameerabbasi hameerabbasi commented Aug 31, 2020

Fixes #42942

@hameerabbasi hameerabbasi marked this pull request as draft August 31, 2020 11:58
@hameerabbasi hameerabbasi requested review from cpuhrsch and rgommers and removed request for apaszke August 31, 2020 11:59
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Aug 31, 2020

💊 CI failures summary and remediations

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


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 failed


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.

See how this bot performed.

This comment has been revised 63 times.

Comment thread torch/autograd/gradcheck.py Outdated
Comment thread torch/autograd/gradcheck.py Outdated
@hameerabbasi hameerabbasi force-pushed the gradcheck-override branch 3 times, most recently from 8460f7b to 588dd4a Compare September 1, 2020 11:01
@hameerabbasi hameerabbasi marked this pull request as ready for review September 1, 2020 11:02
@hameerabbasi hameerabbasi force-pushed the gradcheck-override branch 3 times, most recently from 0c1e60a to 7d2a403 Compare September 1, 2020 14:20
Comment thread torch/autograd/gradcheck.py Outdated
Comment thread torch/overrides.py Outdated
@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Sep 1, 2020

The overall approach looks pretty reasonable. Please ping when not WIP.

@hameerabbasi hameerabbasi changed the title WIP: Allow Tensor-likes in torch.autograd.gradcheck Allow Tensor-likes in torch.autograd.gradcheck Sep 1, 2020
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 1, 2020

Codecov Report

Merging #43877 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #43877   +/-   ##
=======================================
  Coverage   69.24%   69.25%           
=======================================
  Files         381      381           
  Lines       47573    47580    +7     
=======================================
+ Hits        32943    32951    +8     
+ Misses      14630    14629    -1     
Impacted Files Coverage Δ
torch/autograd/__init__.py 85.71% <100.00%> (+0.86%) ⬆️
torch/autograd/gradcheck.py 87.64% <100.00%> (+0.44%) ⬆️
torch/overrides.py 98.05% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cce5982...cec5804. Read the comment docs.

@hameerabbasi
Copy link
Copy Markdown
Collaborator Author

I think this is ready for review. The CI failure is unrelated: It's a bunch of connection refused errors.

Comment thread torch/overrides.py Outdated
Copy link
Copy Markdown
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

The autograd part looks good to me.
I'll let @rgommers or @ezyang make a final review to make sure the override testing is doing the right thing.

Comment thread torch/overrides.py
Currently, this occurs whenever there's a ``__torch_function__``
attribute on the input.
"""
return type(inp) is torch.Tensor or hasattr(inp, "__torch_function__")
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.

nit: Why not use isinstance here? the type check is better?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It’s faster, I believe.

@smessmer smessmer added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 2, 2020
Comment thread test/test_overrides.py
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.

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

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.

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

@hameerabbasi
Copy link
Copy Markdown
Collaborator Author

Do we know why the internal tests are failing? Can someone provide a repro-er and/or a traceback?

@albanD
Copy link
Copy Markdown
Collaborator

albanD commented Sep 7, 2020

Hey,
OSS failure show up as internal failures as well, and some flaky tests.
Landing is taking a bit more time with the long week end here ;)

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.

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

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@ezyang merged this pull request in f9a0d0c.

@anjali411
Copy link
Copy Markdown
Contributor

anjali411 commented Sep 11, 2020

reverting this because of test failure in #43208

Sep 10 15:36:06 ======================================================================
Sep 10 15:36:06 ERROR: test_gradcheck (__main__.TestGradCheckOverride)
Sep 10 15:36:06 ----------------------------------------------------------------------
Sep 10 15:36:06 Traceback (most recent call last):
Sep 10 15:36:06   File "test_overrides.py", line 772, in test_gradcheck
Sep 10 15:36:06     gradcheck(torch.add, (a, b), raise_exception=False)
Sep 10 15:36:06   File "/Users/distiller/workspace/miniconda3/lib/python3.7/site-packages/torch/autograd/gradcheck.py", line 334, in gradcheck
Sep 10 15:36:06     numerical = get_numerical_jacobian(fn, tupled_inputs, eps=eps)
Sep 10 15:36:06   File "/Users/distiller/workspace/miniconda3/lib/python3.7/site-packages/torch/autograd/gradcheck.py", line 148, in get_numerical_jacobian
Sep 10 15:36:06     update_jacobians(x_tensor, x_idx, d_tensor, d_idx)
Sep 10 15:36:06   File "/Users/distiller/workspace/miniconda3/lib/python3.7/site-packages/torch/autograd/gradcheck.py", line 104, in update_jacobians
Sep 10 15:36:06     d[d_idx] = ds_dx * v
Sep 10 15:36:06 TypeError: unsupported operand type(s) for *: 'Wrapper' and 'float'

@hameerabbasi can you fix this?

ezyang added a commit that referenced this pull request Sep 11, 2020
ezyang added a commit that referenced this pull request Sep 11, 2020
This reverts commit f9a0d0c.

ghstack-source-id: d662f56
Pull Request resolved: #44554
@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Sep 11, 2020

Just to clarify, @hameerabbasi, I forgot that there is a high priority update being made to gradcheck right now to make it support complex numbers. This takes priority over enhanced __torch_function__ support, so it may be better to revert this PR for now, get complex gradcheck in, and then reland the gradcheck so that it handles the updated gradcheck code correctly.

I briefly looked at the error with @anjali411 but I couldn't figure out why the torch function test stopped working, even when passing non-complex inputs.

@hameerabbasi
Copy link
Copy Markdown
Collaborator Author

Sure. I can make those changes in a follow-up PR.

@hameerabbasi hameerabbasi deleted the gradcheck-override branch October 2, 2020 11:11
facebook-github-bot pushed a commit that referenced this pull request Oct 9, 2020
Summary:
Fixes #42942

Re-do of #43877.

Pull Request resolved: #45732

Reviewed By: mruberry

Differential Revision: D24195820

Pulled By: albanD

fbshipit-source-id: 8f43353077f341e34371affd76be553c0ef7d98a
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Fixes pytorch#42942

Pull Request resolved: pytorch#43877

Reviewed By: zou3519

Differential Revision: D23493257

Pulled By: ezyang

fbshipit-source-id: 6cdaabe17157b484e9491189706ccc15420ac239
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Fixes pytorch#42942

Re-do of pytorch#43877.

Pull Request resolved: pytorch#45732

Reviewed By: mruberry

Differential Revision: D24195820

Pulled By: albanD

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

Labels

Merged open source 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.

torch.autograd.gradcheck support for Tensor-like types (__torch_function__).

9 participants