-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Add warning for legacy autograd function #22922
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
Conversation
torch/autograd/function.py
Outdated
|
|
||
| # old-style functions | ||
| if not has_static_forward: | ||
| warnings.warn('Legacy autograd function with non-static forward method is deprecated. ' |
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.
I'm wondering if test_autograd.py will warning spew. At some point we should convert the legacy functions there that are not explicitly testing legacy behavior to non-legacy ones (probably doesn't have to happen in this PR)
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.
That's a good idea, I opened another PR for it: #22925.
|
Test failure seems like it might be related? |
|
@zou3519 I couldn't make the test work in Python 2.7, but I tested it manually and can confirm that it prints warning in Python 2.7. |
|
we have tests for warnings in python2 and this is a pretty major deprecation; we should have tests for it. |
f8a9b8a to
f56e01d
Compare
|
I moved the warning to the legacy function's forward method so that it can be reliably shown in both Python 2.7 and Python 3. |
Summary: We are planning to put up a deprecation warning for legacy autograd function in 1.2: pytorch#22922. This PR removes all usage of legacy function in PyTorch core and test suite, to prepare for the eventual removal of legacy function. Pull Request resolved: pytorch#22925 Differential Revision: D16344834 Pulled By: yf225 fbshipit-source-id: 8bf4cca740398835a08b7a290f3058c3e46781ba
| def test_legacy_function_deprecation_warning(self): | ||
| with warnings.catch_warnings(record=True) as w: | ||
| # Ensure warnings are being shown | ||
| warnings.simplefilter("always") |
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.
Is this necessary for this warning to be shown? I'm not sure what the default warnings behavior is
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.
Oh, I see why you had to do this:
print the first occurrence of matching warnings for each location (module + line number) where the warning is issued
| std::vector<c10::IValue>(), | ||
| autograd::Function::peek_at_next_sequence_nr()); | ||
|
|
||
| TORCH_WARN("Legacy autograd function with non-static forward method is deprecated. ", |
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.
Maybe give a deadline if you want to remove it asap? "Will be removed in 1.3".
zou3519
left a comment
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.
lgtm, I can't think of a use case where someone constructs an autograd function without calling it so putting a deprecation warning in forward should be fine.
facebook-github-bot
left a comment
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.
@yf225 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
When working on #22762, we discovered that we haven't actually deprecated legacy autograd function. This PR puts up the deprecation warning for 1.2, with the goal to remove legacy function support completely in the near future.