Skip to content

cleanup static_cast of AutogradMeta#54103

Closed
albanD wants to merge 3 commits intogh/albanD/73/basefrom
gh/albanD/73/head
Closed

cleanup static_cast of AutogradMeta#54103
albanD wants to merge 3 commits intogh/albanD/73/basefrom
gh/albanD/73/head

Conversation

@albanD
Copy link
Copy Markdown
Collaborator

@albanD albanD commented Mar 16, 2021

The goal is to reduce the spread of static casts in the autograd code as per the comment in #49097 (comment)
I wasn't sure how to use a virtual method here but a simple method in impl clean it up quite nicely.

Stack from ghstack:

Differential Revision: D27117840

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Mar 16, 2021

💊 CI failures summary and remediations

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


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

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.

@albanD albanD requested a review from ezyang March 16, 2021 21:58
return static_cast<AutogradMeta*>(self.unsafeGetTensorImpl()->autograd_meta());
}

DifferentiableViewMeta* get_view_autograd_meta(const Variable& self) {
Copy link
Copy Markdown
Contributor

@soulitzer soulitzer Mar 17, 2021

Choose a reason for hiding this comment

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

nit: Would we want to use Tensor here? or do we keep Variable for consistency.

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.

Yes we have a using Variable = at::Tensor at the top of the header.
We should remove that and rename all of them I think yes.

The goal is to reduce the spread of static casts in the autograd code as per the comment in #49097 (comment)
I wasn't sure how to use a virtual method here but a simple method in impl clean it up quite nicely.





[ghstack-poisoned]
albanD added a commit that referenced this pull request Mar 17, 2021
ghstack-source-id: 4cdb26e
Pull Request resolved: #54103
@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Mar 17, 2021

This seems OK, but given that all the call sites are testing for view-ness before calling the cast, it seems like it might just be better to make this function return a nullptr/ullopt when it's not castable, and then force callers to test the return output.

albanD added a commit to albanD/pytorch that referenced this pull request Mar 17, 2021
ghstack-source-id: 4cdb26e
Pull Request resolved: pytorch#54103
The goal is to reduce the spread of static casts in the autograd code as per the comment in #49097 (comment)
I wasn't sure how to use a virtual method here but a simple method in impl clean it up quite nicely.



Differential Revision: [D27117840](https://our.internmc.facebook.com/intern/diff/D27117840)

[ghstack-poisoned]
albanD added a commit that referenced this pull request Mar 17, 2021
ghstack-source-id: 096aba4
Pull Request resolved: #54103
@albanD
Copy link
Copy Markdown
Collaborator Author

albanD commented Mar 17, 2021

@ezyang I updated following your recommendation. Does that look better? It does make the code simpler but it is a less clear that we use this to check if a Tensor is a view.

@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Mar 17, 2021

One way to make it clearer is to jiggle the naming; e.g., maybe_view_XXX or try_view_XXX

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@albanD merged this pull request in cc92117.

@facebook-github-bot facebook-github-bot deleted the gh/albanD/73/head branch March 22, 2021 14:16
albanD added a commit that referenced this pull request Mar 24, 2021
[ghstack-poisoned]
@albanD albanD mentioned this pull request Mar 24, 2021
albanD added a commit that referenced this pull request Mar 29, 2021
The `.is_view()` method actually only refers to backward mode views
This is not a problem right now in master (and thus I didn't revert the other PR) because nothing creates forward AD views.




[ghstack-poisoned]
albanD added a commit that referenced this pull request Mar 29, 2021
The `.is_view()` method actually only refers to backward mode views
This is not a problem right now in master (and thus I didn't revert the other PR) because nothing creates forward AD views.




[ghstack-poisoned]
albanD added a commit to albanD/pytorch that referenced this pull request Mar 29, 2021
ghstack-source-id: b26a8be
Pull Request resolved: pytorch#54610
facebook-github-bot pushed a commit that referenced this pull request Apr 5, 2021
Summary:
Pull Request resolved: #54610

The `.is_view()` method actually only refers to backward mode views
This is not a problem right now in master (and thus I didn't revert the other PR) because nothing creates forward AD views.

Test Plan: Imported from OSS

Reviewed By: gchanan

Differential Revision: D27396756

Pulled By: albanD

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants