Skip to content

Boxed variable dispatch#29934

Closed
smessmer wants to merge 12 commits intogh/smessmer/117/basefrom
gh/smessmer/117/head
Closed

Boxed variable dispatch#29934
smessmer wants to merge 12 commits intogh/smessmer/117/basefrom
gh/smessmer/117/head

Conversation

@smessmer
Copy link
Contributor

@smessmer smessmer commented Nov 15, 2019

Stack from ghstack:

Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

Differential Revision: D18542342

Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

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

[ghstack-poisoned]
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
smessmer added a commit that referenced this pull request Nov 16, 2019
Pull Request resolved: #29934

Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.
ghstack-source-id: 94056388

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

void variable_fallback_kernel(const OperatorHandle& op, Stack* stack) {
at::AutoNonVariableTypeMode _var_guard(true);
Dispatcher::singleton().callBoxed(op, stack);
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, this isn't really what I've been advocating for, but I'll let it slide for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not? IIRC, we said we're setting the thread local flag and re-dispatching. That's what I'm doing here. What would you do instead?

Copy link
Contributor

@ezyang ezyang Nov 18, 2019

Choose a reason for hiding this comment

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

We also need to setup grad_fn on the outputs to error if you try to backprop through them! Otherwise you'll just pop out requires_grad=False outputs which will silently fail to backprop if someone uses them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that's what you mean. Yes, we should do that. This doesn't regress behavior though, it's just as broken as it was before. There were some issues with adding the grad_fn if I remember correctly which meant we can't do it right now, but I'll look at it in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that's why I approved.

Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
smessmer added a commit that referenced this pull request Nov 18, 2019
Pull Request resolved: #29934

Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.
ghstack-source-id: 94139776

Differential Revision: [D18542342](https://our.internmc.facebook.com/intern/diff/D18542342/)
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
smessmer added a commit that referenced this pull request Nov 22, 2019
Pull Request resolved: #29934

Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.
ghstack-source-id: 94460733

Differential Revision: [D18542342](https://our.internmc.facebook.com/intern/diff/D18542342/)
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
smessmer added a commit that referenced this pull request Nov 26, 2019
Pull Request resolved: #29934

Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.
ghstack-source-id: 94563165

Differential Revision: [D18542342](https://our.internmc.facebook.com/intern/diff/D18542342/)
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.

See https://fb.quip.com/czCUA1NzMeEt for the detailed plan.

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

[ghstack-poisoned]
smessmer added a commit that referenced this pull request Nov 26, 2019
Pull Request resolved: #29934

Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.
ghstack-source-id: 94618474

Differential Revision: [D18542342](https://our.internmc.facebook.com/intern/diff/D18542342/)
@facebook-github-bot facebook-github-bot deleted the gh/smessmer/117/head branch December 10, 2019 15:20
wuhuikx pushed a commit to wuhuikx/pytorch that referenced this pull request Jan 30, 2020
Summary:
Pull Request resolved: pytorch#29934

Previously, when doing boxed dispatch (e.g. custom ops), the dispatcher manually removed the VariableTensorId flag before dispatching
because custom ops don't have variable kernels.
This is one of the blockers that prevented us from using the boxed dispatch mechanism for ops from native_functions.yaml because they define variable kernels and need them to be called for autograd.

This PR changes that. The dispatcher doesn't remove the VariableTensorId flag anymore.
Instead, to make custom ops work, we implement a variable fallback kernel that is called whenever no other variable kernel was found.
ghstack-source-id: 94618474

Test Plan: unit tests

Differential Revision: D18542342

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants