Skip to content

Commit 8f68674

Browse files
committed
Move portable/util.py into extension/export_util
Pull Request resolved: #4141 `portable/util.py` is used by multiple example models including llm models. Since we are moving llm models' export libraries into `extension/llm/export`, it makes sense to move `portable/util.py` into extension as well. This change does that. It moves the test into `examples/models` which seems to be a better place for these unit tests since they test the export flow for different models and also rely on some code under `examples/models` like `EagerModelFactory`. It also fixes the import hack inside `executorch/examples/models/llama2/builder.py`. Differential Revision: [D59306348](https://our.internmc.facebook.com/intern/diff/D59306348/) ghstack-source-id: 232553687
1 parent 998fc08 commit 8f68674

File tree

14 files changed

+17
-20
lines changed

14 files changed

+17
-20
lines changed

examples/apple/mps/scripts/mps_example.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from executorch.exir.backend.backend_api import to_backend
2424
from executorch.exir.backend.backend_details import CompileSpec
2525
from executorch.exir.capture._config import ExecutorchBackendConfig
26+
from executorch.extension.export_util.utils import export_to_edge, save_pte_program
2627
from executorch.sdk import BundledProgram, generate_etrecord
2728
from executorch.sdk.bundled_program.config import MethodTestCase, MethodTestSuite
2829
from executorch.sdk.bundled_program.serialize import (
@@ -32,8 +33,6 @@
3233
from ....models import MODEL_NAME_TO_MODEL
3334
from ....models.model_factory import EagerModelFactory
3435

35-
from ....portable.utils import export_to_edge, save_pte_program
36-
3736
FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
3837
logging.basicConfig(level=logging.INFO, format=FORMAT)
3938

examples/arm/aot_arm_compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
get_symmetric_quantization_config,
1919
)
2020
from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig
21+
from executorch.extension.export_util.utils import export_to_edge, save_pte_program
2122

2223
# Quantize model if required using the standard export quantizaion flow.
2324
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
2425

2526
from ..models import MODEL_NAME_TO_MODEL
2627
from ..models.model_factory import EagerModelFactory
27-
from ..portable.utils import export_to_edge, save_pte_program
2828

2929
FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
3030
logging.basicConfig(level=logging.WARNING, format=FORMAT)

examples/models/llama2/TARGETS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ runtime.python_library(
8686
"//executorch/examples/models:model_base",
8787
"//executorch/examples/models:models",
8888
"//executorch/examples/models/llama2/custom_ops:custom_ops_aot_py",
89-
"//executorch/examples/portable:utils",
9089
"//executorch/exir:lib",
9190
"//executorch/extension/llm/export:export_lib",
91+
"//executorch/extension/export_util:export_util",
9292
# one definition has to be included in the user of the libarary
9393
# depending on what library the client wants to use
9494
# "//executorch/extension/pybindings:aten_lib",

examples/models/llama2/builder.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
from typing import Any, Callable, List, Optional
1414

1515
import torch
16-
17-
try:
18-
from ...portable.utils import export_to_edge, save_pte_program
19-
except ImportError:
20-
# Workaround to bypass the different paths between executorch pip package and directly python call
21-
# TODO: remove this try catch workaround and have a standard wa to import portable.utils
22-
# pyre-ignore: Undefined import [21]: Could not find a module corresponding to import `examples.portable.utils`.
23-
from examples.portable.utils import export_to_edge, save_pte_program
2416
from executorch.backends.transforms.duplicate_dynamic_quant_chain import (
2517
DuplicateDynamicQuantChainPass,
2618
)
@@ -33,6 +25,8 @@
3325
from executorch.exir.passes import MemoryPlanningPass
3426
from executorch.exir.passes.quant_fusion_pass import QuantFusionPass
3527
from executorch.exir.passes.sym_shape_eval_pass import ConstraintBasedSymShapeEvalPass
28+
29+
from executorch.extension.export_util.utils import export_to_edge, save_pte_program
3630
from torch._export import capture_pre_autograd_graph
3731
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
3832
from torch.ao.quantization.quantizer import Quantizer
File renamed without changes.

examples/portable/test/test_export.py renamed to examples/models/test/test_export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from executorch.examples.models import MODEL_NAME_TO_MODEL
1111
from executorch.examples.models.model_factory import EagerModelFactory
1212

13+
from executorch.extension.export_util.utils import export_to_edge
14+
1315
from executorch.extension.pybindings.portable_lib import ( # @manual
1416
_load_for_executorch_from_buffer,
1517
)
1618

17-
from ..utils import export_to_edge
18-
1919

2020
class ExportTest(unittest.TestCase):
2121
def collect_executorch_and_eager_outputs(

examples/portable/scripts/export.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
import torch
1313

1414
from executorch.exir.capture import EdgeCompileConfig, ExecutorchBackendConfig
15+
from executorch.extension.export_util.utils import (
16+
export_to_edge,
17+
export_to_exec_prog,
18+
save_pte_program,
19+
)
1520

1621
from ...models import MODEL_NAME_TO_MODEL
1722
from ...models.model_factory import EagerModelFactory
18-
from ..utils import export_to_edge, export_to_exec_prog, save_pte_program
1923

2024

2125
FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"

examples/qualcomm/scripts/export_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
)
1818
from executorch.examples.models import MODEL_NAME_TO_MODEL
1919
from executorch.examples.models.model_factory import EagerModelFactory
20-
from executorch.examples.portable.utils import save_pte_program
2120
from executorch.exir.backend.backend_api import to_backend, validation_disabled
2221
from executorch.exir.capture._config import ExecutorchBackendConfig
22+
from executorch.extension.export_util.utils import save_pte_program
2323
from executorch.sdk import generate_etrecord
2424

2525
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e

examples/sdk/scripts/export_bundled_program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import torch
1414

1515
from executorch.exir import ExecutorchProgramManager
16+
from executorch.extension.export_util.utils import export_to_exec_prog
1617
from executorch.sdk import BundledProgram
1718
from executorch.sdk.bundled_program.config import (
1819
MethodInputType,
@@ -25,7 +26,6 @@
2526

2627
from ...models import MODEL_NAME_TO_MODEL
2728
from ...models.model_factory import EagerModelFactory
28-
from ...portable.utils import export_to_exec_prog
2929

3030

3131
def save_bundled_program(

examples/xnnpack/aot_compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import torch
1414
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
1515
from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig
16+
from executorch.extension.export_util.utils import export_to_edge, save_pte_program
1617
from executorch.sdk import generate_etrecord
1718

1819
from ..models import MODEL_NAME_TO_MODEL
1920
from ..models.model_factory import EagerModelFactory
20-
from ..portable.utils import export_to_edge, save_pte_program
2121
from . import MODEL_NAME_TO_OPTIONS
2222
from .quantization.utils import quantize
2323

examples/xnnpack/quantization/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import torch
1313
from executorch.exir import EdgeCompileConfig
1414
from executorch.exir.capture._config import ExecutorchBackendConfig
15+
from executorch.extension.export_util.utils import export_to_edge, save_pte_program
1516
from torch.ao.ns.fx.utils import compute_sqnr
1617
from torch.ao.quantization import ( # @manual
1718
default_per_channel_symmetric_qnnpack_qconfig,
@@ -30,7 +31,6 @@
3031

3132
from ...models import MODEL_NAME_TO_MODEL
3233
from ...models.model_factory import EagerModelFactory
33-
from ...portable.utils import export_to_edge, save_pte_program
3434

3535
from .. import MODEL_NAME_TO_OPTIONS
3636
from .utils import quantize

examples/xnnpack/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def define_common_targets():
2828
deps = [
2929
":models",
3030
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
31-
"//executorch/examples/portable:utils",
31+
"//executorch/extension/export_util:export_util",
3232
"//executorch/examples/xnnpack/quantization:quant_utils",
3333
"//executorch/exir:lib",
3434
"//executorch/exir/backend:backend_api",
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)