Skip to content

internal fixes for FunctionalTensorMode usage in AOTAutograd #538

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 5 additions & 36 deletions exir/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,13 @@ def call_delegate_fake_tensor_mode(mode, lowered_module, *args):
return lowered_module.original_module(*args)


@executorch_call_delegate.py_impl(torch._C.DispatchKey.Functionalize)
@executorch_call_delegate.py_functionalize_impl
# pyre-ignore
def call_delegate_func(lowered_module, *args):
reapply_views = torch._C._functionalization_reapply_views_tls()
# At this point, we will see functionalized tensors, so need to unwrap them first
unwrapped_args = tuple(
_unwrap_all_tensors_from_functional(arg, reapply_views=reapply_views)
for arg in args
)
guard = torch._C.ExcludeDispatchKeyGuard(
torch._C.DispatchKeySet(torch._C.DispatchKey.Functionalize)
)
try:
delegate_return = executorch_call_delegate(lowered_module, *unwrapped_args)
return _wrap_all_tensors_to_functional(delegate_return, level=0)
finally:
del guard


# pyre-ignore
@executorch_call_delegate.py_impl(torch._C._functorch.TransformType.Functionalize)
# pyre-ignore
def call_delegate_functionalize(interpreter, lowered_module, *args):
"""
Functionalization implementation for torch.ops.executorch_call_delegate. We
don't need to do anything since the delegated program is controlled by
users.
"""
reapply_views = interpreter.functionalize_add_back_views()
# At this point, we will see functionalized tensors, so need to unwrap them first
unwrapped_args = tuple(
_unwrap_all_tensors_from_functional(arg, reapply_views=reapply_views)
for arg in args
)

with interpreter.lower():
def call_delegate_functionalize(ctx, lowered_module, *args):
unwrapped_args = tuple(ctx.unwrap_tensors(arg) for arg in args)
with ctx.redispatch_to_next():
res = executorch_call_delegate(lowered_module, *unwrapped_args)
return _wrap_all_tensors_to_functional(res, level=interpreter.level())
return ctx.wrap_tensors(res)


# pyre-ignore: Missing parameter annotation [2]: Parameter `obj` must have a type other than `Any`.Pyre
Expand Down