Skip to content

Make Internal model and Resnet work with rexportable flow #40

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
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions backends/xnnpack/test/test_xnnpack_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

from executorch.exir.passes.spec_prop_pass import SpecPropPass
from executorch.exir.serialize import serialize_to_flatbuffer
from executorch.exir.tracer import _default_decomposition_table

# pyre-ignore[21]: Could not find module `executorch.extension.pybindings.portable`.
from executorch.extension.pybindings.portable import ( # @manual
Expand Down Expand Up @@ -312,19 +313,22 @@ def quantize_and_test_model_with_quantizer(
):
module.eval()
# program capture
capture_config = exir.CaptureConfig(
pt2_mode=True, enable_functionalization=True
m = torch._export.capture_pre_autograd_graph(
module, example_inputs, decomp_table=_default_decomposition_table()
)
captured_program = exir.capture(module, example_inputs, config=capture_config)
m = captured_program.exported_program.graph_module

quantizer = XNNPACKQuantizer()
quantization_config = get_symmetric_quantization_config()
quantizer.set_global(quantization_config)
prepared = prepare_pt2e(m, quantizer)
converted = convert_pt2e(prepared)

captured_program.exported_program.graph_module = converted
captured_program = exir.capture(
converted,
example_inputs,
config=exir.CaptureConfig(enable_aot=True, _unlift=True),
)

edge_program = captured_program.to_edge(get_xnnpack_edge_compile_config())
delegated_module = self.lower_module_and_test_output(
module=edge_program,
Expand Down
12 changes: 0 additions & 12 deletions exir/capture/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ python_library(
deps = [
":capture",
":config",
":unlift",
],
)

Expand All @@ -19,7 +18,6 @@ python_library(
],
deps = [
":config",
":unlift",
"//caffe2:torch",
"//executorch/exir:error",
"//executorch/exir:tracer",
Expand All @@ -40,13 +38,3 @@ python_library(
"//executorch/exir/passes:lib",
],
)

python_library(
name = "unlift",
srcs = [
"_unlift.py",
],
deps = [
"//caffe2:torch",
],
)
2 changes: 0 additions & 2 deletions exir/capture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
EdgeCompileConfig,
ExecutorchBackendConfig,
)
from executorch.exir.capture._unlift import unlift_exported_program_lifted_states

__all__ = [
"capture",
"capture_multiple",
"CaptureConfig",
"EdgeCompileConfig",
"ExecutorchBackendConfig",
"unlift_exported_program_lifted_states",
]
3 changes: 1 addition & 2 deletions exir/capture/_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import torch
import torch._export
from executorch.exir.capture._config import CaptureConfig
from executorch.exir.capture._unlift import unlift_exported_program_lifted_states
from executorch.exir.error import ExportError, ExportErrorType, InternalError
from executorch.exir.program import ExirExportedProgram, MultiMethodExirExportedProgram
from executorch.exir.tracer import (
Expand Down Expand Up @@ -75,7 +74,7 @@ def capture(
ep = ep.transform(ReplaceViewOpsWithViewCopyOpsPass())
if not config._unlift:
return ExirExportedProgram(ep, False)
graph_module = unlift_exported_program_lifted_states(ep)
graph_module = ep.module()

elif config.enable_dynamic_shape:
graph_module, _ = dynamo_trace(
Expand Down
5 changes: 3 additions & 2 deletions exir/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ def call_delegate_autograd(lowered_module, *args):
def fake_requires_grad(var):
if var is not None:
var = var.detach()
var.requires_grad = True
return err_fn(var)
if torch.is_floating_point(var) or torch.is_complex(var):
var.requires_grad = True
return var

return pytree.tree_map(fake_requires_grad, res)

Expand Down