Skip to content
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
24 changes: 13 additions & 11 deletions examples/xnnpack/aot_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
import torch
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
from executorch.devtools import generate_etrecord
from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig
from executorch.extension.export_util.utils import export_to_edge, save_pte_program
from executorch.exir import (
EdgeCompileConfig,
ExecutorchBackendConfig,
to_edge_transform_and_lower,
)
from executorch.extension.export_util.utils import save_pte_program

from ..models import MODEL_NAME_TO_MODEL
from ..models.model_factory import EagerModelFactory
Expand Down Expand Up @@ -81,29 +85,27 @@

model = model.eval()
# pre-autograd export. eventually this will become torch.export
model = torch.export.export_for_training(model, example_inputs).module()
ep = torch.export.export_for_training(model, example_inputs)
model = ep.module()

if args.quantize:
logging.info("Quantizing Model...")
# TODO(T165162973): This pass shall eventually be folded into quantizer
model = quantize(model, example_inputs)

edge = export_to_edge(
model,
example_inputs,
edge_compile_config=EdgeCompileConfig(
edge = to_edge_transform_and_lower(
ep,
partitioner=[XnnpackPartitioner()],
compile_config=EdgeCompileConfig(
_check_ir_validity=False if args.quantize else True,
_skip_dim_order=True, # TODO(T182187531): enable dim order in xnnpack
),
)
logging.info(f"Exported graph:\n{edge.exported_program().graph}")
logging.info(f"Exported and lowered graph:\n{edge.exported_program().graph}")

# this is needed for the ETRecord as lowering modifies the graph in-place
edge_copy = copy.deepcopy(edge)

edge = edge.to_backend(XnnpackPartitioner())
logging.info(f"Lowered graph:\n{edge.exported_program().graph}")

exec_prog = edge.to_executorch(
config=ExecutorchBackendConfig(extract_delegate_segments=False)
)
Expand Down
Loading