CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Fix assigning tensor with requires_grad as constant in export #137997
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
Fix assigning tensor with requires_grad as constant in export #137997
Conversation
When we insert cojstants into unlifted graph, we need to detach them if they require grad. Differential Revision: [D64406859](https://our.internmc.facebook.com/intern/diff/D64406859/) [ghstack-poisoned]
π Helpful Linksπ§ͺ See artifacts and rendered test results at hud.pytorch.org/pr/137997
Note: Links to docs will display an error until the docs builds have been completed. β No FailuresAs of commit a9a5da7 with merge base f173623 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This pull request was exported from Phabricator. Differential Revision: D64406859 |
When we insert cojstants into unlifted graph, we need to detach them if they require grad. Differential Revision: [D64406859](https://our.internmc.facebook.com/intern/diff/D64406859/) ghstack-source-id: 248115756 Pull Request resolved: #137997
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.
Test please
β¦ort" When we insert cojstants into unlifted graph, we need to detach them if they require grad. Differential Revision: [D64406859](https://our.internmc.facebook.com/intern/diff/D64406859/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D64406859 |
Pull Request resolved: #137997 When we insert cojstants into unlifted graph, we need to detach them if they require grad. Differential Revision: [D64406859](https://our.internmc.facebook.com/intern/diff/D64406859/) ghstack-source-id: 248221115
β¦ort" When we insert cojstants into unlifted graph, we need to detach them if they require grad. Differential Revision: [D64406859](https://our.internmc.facebook.com/intern/diff/D64406859/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D64406859 |
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.
Rebase and check CI before landing...
torch/export/_unlift.py
Outdated
@@ -309,6 +318,19 @@ def _create_stateful_graph_module( | |||
for const_name, value in ep.constants.items(): | |||
if not torch.fx.graph_module._has_attr(stateful_gm, const_name): | |||
if isinstance(value, torch.Tensor): | |||
if value.requires_grad: | |||
warnings.warn( | |||
f"A model attribute `{const_name}` requires gradient. " |
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.
no ending period
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.
sg
if value in original_tensor_to_detached_tensor: | ||
value = original_tensor_to_detached_tensor[value] | ||
else: | ||
detached_value = value.detach() |
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 this code should be refactored into a util?
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.
It is bit hard to make it a util because this is only relevant in this specific location.
β¦ort" When we insert cojstants into unlifted graph, we need to detach them if they require grad BUT when we detach we need to preserve the original aliasing information. Differential Revision: [D64406859](https://our.internmc.facebook.com/intern/diff/D64406859/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D64406859 |
β¦ort" When we insert cojstants into unlifted graph, we need to detach them if they require grad BUT when we detach we need to preserve the original aliasing information. Differential Revision: [D64406859](https://our.internmc.facebook.com/intern/diff/D64406859/) [ghstack-poisoned]
Pull Request resolved: #137997 When we insert cojstants into unlifted graph, we need to detach them if they require grad. ghstack-source-id: b218468 Differential Revision: [D64406859](https://our.internmc.facebook.com/intern/diff/D64406859/)
@tugsbayasgalan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Stack from ghstack (oldest at bottom):
When we insert cojstants into unlifted graph, we need to detach them if they require grad BUT when we detach we need to preserve the original aliasing information.
Differential Revision: D64406859