Skip to content

Commit

Permalink
Don't use NonVariableTypeMode in custom ops
Browse files Browse the repository at this point in the history
Potentially fixes #37306

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

[ghstack-poisoned]
  • Loading branch information
smessmer committed Apr 27, 2020
1 parent 22ac071 commit 89fede5
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions aten/src/ATen/core/VariableFallbackKernel.cpp
Expand Up @@ -28,47 +28,8 @@ using c10::KernelFunction;

namespace {

void variable_fallback_kernel(const OperatorHandle& op, Stack* stack) {
at::AutoNonVariableTypeMode _var_guard(true);
op.callBoxed(stack);
}

TORCH_LIBRARY_IMPL(_, Autograd, m) {
#ifdef C10_MOBILE
// As custom mobile build might not include variable kernels, we need
// leverage variable fallback mechanism as well. The goals are:
// 1) don't break forward pass for inference-only mobile build;
// 2) don't break forward/backward pass for mobile build with necessary
// variable kernels registered;
//
// This `fallthrough` kernel is for #1 - because not all kernels support
// boxed call yet, registering `variable_fallback_kernel` might fail.
// When an op has variable kernel registered explicitly dispatcher will
// call it instead of `fallthrough`, so `fallthrough` won't break
// dispatching to real variable kernels for case #2.
//
// The substantial difference between fallback and fallthrough is whether
// AutoNonVariableTypeMode guard is applied. There are two downstream
// effects of the guard:
// a) stop calling variable kernels of other ops called by the current op;
// For case #1, there is no difference because no variable kernels are
// registered. For case #2, there is no difference as long as ALL used
// ops have real variable kernels registered, where the guard will be
// set properly in real variable kernels. There is potential issue only
// when variable kernels are partially registered for used ops.
// b) `variable_excluded_from_dispatch()` method returns the state of the
// NonVariableTypeMode. As of when this diff is written, the callers of
// the method are ALL asserting it returns true; the only exception is
// the deprecated `is_variable()` method. So we make the method to always
// return true for mobile builds. It shouldn't break case #1/#2 as long
// as `is_variable()` is not used.
//
// We can remove this `fallthrough` kernel when all kernels support boxed
// call.
m.fallback(torch::CppFunction::makeFallthrough());
#else
m.fallback(torch::CppFunction::makeFromBoxedFunction<&variable_fallback_kernel>());
#endif
}

}

0 comments on commit 89fede5

Please sign in to comment.