Skip to content

Commit e404ce1

Browse files
authored
Merge branch 'main' into vela-6d-io
2 parents b713aa2 + 389918b commit e404ce1

File tree

15 files changed

+99
-76
lines changed

15 files changed

+99
-76
lines changed

backends/apple/mps/serialization/mps_graph_serialize.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3+
# Copyright 2025 Arm Limited and/or its affiliates.
34
#
45
# This source code is licensed under the BSD-style license found in the
56
# LICENSE file in the root directory of this source tree.
67

8+
import importlib.resources as _resources
79
import json
810
import os
911
import tempfile
1012

11-
import pkg_resources
13+
import executorch.backends.apple.mps.serialization as serialization_package
1214
from executorch.backends.apple.mps.serialization.mps_graph_schema import MPSGraph
1315
from executorch.exir._serialize._dataclass import _DataclassEncoder
1416
from executorch.exir._serialize._flatbuffer import _flatc_compile
@@ -19,7 +21,9 @@ def convert_to_flatbuffer(mps_graph: MPSGraph) -> bytes:
1921
with tempfile.TemporaryDirectory() as d:
2022
schema_path = os.path.join(d, "schema.fbs")
2123
with open(schema_path, "wb") as schema_file:
22-
schema_file.write(pkg_resources.resource_string(__name__, "schema.fbs"))
24+
schema_file.write(
25+
_resources.read_binary(serialization_package, "schema.fbs")
26+
)
2327
json_path = os.path.join(d, "schema.json")
2428
with open(json_path, "wb") as json_file:
2529
json_file.write(mps_graph_json.encode("ascii"))

backends/arm/test/ops/test_sum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_sum_dim_intlist_tosa_INT(test_data: input_t1):
6060
aten_op,
6161
exir_op=[],
6262
)
63+
pipeline.dump_artifact("export")
6364
pipeline.run()
6465

6566

backends/qualcomm/serialization/qc_schema_serialize.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Copyright (c) Qualcomm Innovation Center, Inc.
2+
# Copyright 2025 Arm Limited and/or its affiliates.
23
# All rights reserved
34
#
45
# This source code is licensed under the BSD-style license found in the
56
# LICENSE file in the root directory of this source tree.
67

8+
import importlib.resources as _resources
79
import json
810
import os
911
import tempfile
1012

11-
import pkg_resources
13+
import executorch.backends.qualcomm.serialization as serialization_package
1214
from executorch.backends.qualcomm.serialization.qc_schema import QnnExecuTorchOptions
1315
from executorch.exir._serialize._dataclass import _DataclassEncoder, _json_to_dataclass
1416
from executorch.exir._serialize._flatbuffer import _flatc_compile, _flatc_decompile
@@ -19,7 +21,9 @@ def _convert_to_flatbuffer(obj, schema: str):
1921
with tempfile.TemporaryDirectory() as d:
2022
schema_path = os.path.join(d, f"{schema}.fbs")
2123
with open(schema_path, "wb") as schema_file:
22-
schema_file.write(pkg_resources.resource_string(__name__, f"{schema}.fbs"))
24+
schema_file.write(
25+
_resources.read_binary(serialization_package, f"{schema}.fbs")
26+
)
2327
json_path = os.path.join(d, f"{schema}.json")
2428
with open(json_path, "wb") as json_file:
2529
json_file.write(obj_json.encode("ascii"))
@@ -36,7 +40,9 @@ def _convert_to_object(flatbuffers: bytes, obj_type, schema: str):
3640
schema_path = os.path.join(d, f"{schema}.fbs")
3741
bin_path = os.path.join(d, f"{schema}.bin")
3842
with open(schema_path, "wb") as schema_file:
39-
schema_file.write(pkg_resources.resource_string(__name__, f"{schema}.fbs"))
43+
schema_file.write(
44+
_resources.read_binary(serialization_package, f"{schema}.fbs")
45+
)
4046
with open(bin_path, "wb") as bin_file:
4147
bin_file.write(flatbuffers)
4248

backends/vulkan/serialization/vulkan_graph_serialize.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3+
# Copyright 2025 Arm Limited and/or its affiliates.
34
#
45
# pyre-strict
56
#
67
# This source code is licensed under the BSD-style license found in the
78
# LICENSE file in the root directory of this source tree.
89

910
import ctypes
11+
import importlib.resources as _resources
1012
import json
1113
import os
1214
import tempfile
13-
1415
from dataclasses import dataclass
1516
from typing import ClassVar, List
1617

17-
import pkg_resources
18+
import executorch.backends.vulkan.serialization as serialization_package
19+
1820
import torch
1921

2022
from executorch.backends.vulkan.serialization.vulkan_graph_schema import (
2123
VkBytes,
2224
VkGraph,
2325
)
2426
from executorch.exir._serialize._dataclass import _DataclassEncoder, _json_to_dataclass
25-
2627
from executorch.exir._serialize._flatbuffer import _flatc_compile, _flatc_decompile
2728

2829

@@ -32,7 +33,9 @@ def convert_to_flatbuffer(vk_graph: VkGraph) -> bytes:
3233
with tempfile.TemporaryDirectory() as d:
3334
schema_path = os.path.join(d, "schema.fbs")
3435
with open(schema_path, "wb") as schema_file:
35-
schema_file.write(pkg_resources.resource_string(__name__, "schema.fbs"))
36+
schema_file.write(
37+
_resources.read_binary(serialization_package, "schema.fbs")
38+
)
3639
json_path = os.path.join(d, "schema.json")
3740
with open(json_path, "wb") as json_file:
3841
json_file.write(vk_graph_json.encode("ascii"))
@@ -48,7 +51,9 @@ def flatbuffer_to_vk_graph(flatbuffers: bytes) -> VkGraph:
4851
with tempfile.TemporaryDirectory() as d:
4952
schema_path = os.path.join(d, "schema.fbs")
5053
with open(schema_path, "wb") as schema_file:
51-
schema_file.write(pkg_resources.resource_string(__name__, "schema.fbs"))
54+
schema_file.write(
55+
_resources.read_binary(serialization_package, "schema.fbs")
56+
)
5257

5358
bin_path = os.path.join(d, "schema.bin")
5459
with open(bin_path, "wb") as bin_file:

backends/xnnpack/serialization/xnnpack_graph_serialize.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3+
# Copyright 2025 Arm Limited and/or its affiliates.
34
#
45
# This source code is licensed under the BSD-style license found in the
56
# LICENSE file in the root directory of this source tree.
67

8+
import importlib.resources as _resources
79
import json
8-
910
import logging
1011
import os
1112
import tempfile
12-
1313
from dataclasses import dataclass, fields, is_dataclass
1414
from typing import ClassVar, Literal, Optional
1515

16-
import pkg_resources
16+
import executorch.backends.xnnpack.serialization as serialization_package
1717
from executorch.backends.xnnpack.serialization.xnnpack_graph_schema import XNNGraph
1818
from executorch.exir._serialize._dataclass import _DataclassEncoder
19-
2019
from executorch.exir._serialize._flatbuffer import _flatc_compile
2120

2221
logger = logging.getLogger(__name__)
@@ -317,7 +316,9 @@ def convert_to_flatbuffer(xnnpack_graph: XNNGraph) -> bytes:
317316
with tempfile.TemporaryDirectory() as d:
318317
schema_path = os.path.join(d, "schema.fbs")
319318
with open(schema_path, "wb") as schema_file:
320-
schema_file.write(pkg_resources.resource_string(__name__, "schema.fbs"))
319+
schema_file.write(
320+
_resources.read_binary(serialization_package, "schema.fbs")
321+
)
321322
json_path = os.path.join(d, "schema.json")
322323
with open(json_path, "wb") as json_file:
323324
json_file.write(xnnpack_graph_json.encode("ascii"))

devtools/bundled_program/serialize/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3+
# Copyright 2025 Arm Limited and/or its affiliates.
34
#
45
# This source code is licensed under the BSD-style license found in the
56
# LICENSE file in the root directory of this source tree.
@@ -8,16 +9,15 @@
89

910
# TODO(T138924864): Refactor to unify the serialization for bundled program and executorch program.
1011

12+
import importlib.resources as _resources
1113
import json
1214
import os
1315
import tempfile
1416

1517
import executorch.devtools.bundled_program.schema as bp_schema
1618

17-
# @manual=fbsource//third-party/pypi/setuptools:setuptools
18-
import pkg_resources
19+
import executorch.devtools.bundled_program.serialize as serialization_package
1920
from executorch.devtools.bundled_program.core import BundledProgram
20-
2121
from executorch.exir._serialize._dataclass import _DataclassEncoder, _json_to_dataclass
2222
from executorch.exir._serialize._flatbuffer import _flatc_compile, _flatc_decompile
2323

@@ -30,7 +30,7 @@ def write_schema(d: str, schema_name: str) -> None:
3030
schema_path = os.path.join(d, "{}.fbs".format(schema_name))
3131
with open(schema_path, "wb") as schema_file:
3232
schema_file.write(
33-
pkg_resources.resource_string(__name__, "{}.fbs".format(schema_name))
33+
_resources.read_binary(serialization_package, f"{schema_name}.fbs")
3434
)
3535

3636

devtools/etdump/serialize.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3+
# Copyright 2025 Arm Limited and/or its affiliates.
34
#
45
# This source code is licensed under the BSD-style license found in the
56
# LICENSE file in the root directory of this source tree.
67

78
# pyre-strict
89

10+
import importlib.resources as _resources
911
import json
1012
import os
1113
import tempfile
1214

13-
import pkg_resources
15+
import executorch.devtools.etdump as etdump_package
1416
from executorch.devtools.etdump.schema_flatcc import ETDumpFlatCC
15-
1617
from executorch.exir._serialize._dataclass import _DataclassEncoder, _json_to_dataclass
17-
1818
from executorch.exir._serialize._flatbuffer import _flatc_compile, _flatc_decompile
1919

2020
# The prefix of schema files used for etdump
@@ -25,9 +25,7 @@
2525
def _write_schema(d: str, schema_name: str) -> None:
2626
schema_path = os.path.join(d, "{}.fbs".format(schema_name))
2727
with open(schema_path, "wb") as schema_file:
28-
schema_file.write(
29-
pkg_resources.resource_string(__name__, "{}.fbs".format(schema_name))
30-
)
28+
schema_file.write(_resources.read_binary(etdump_package, f"{schema_name}.fbs"))
3129

3230

3331
def _serialize_from_etdump_to_json(etdump: ETDumpFlatCC) -> str:

examples/arm/aot_arm_compiler.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,8 @@ def get_args():
602602
)
603603
parser.add_argument(
604604
"--enable_qdq_fusion_pass",
605-
action="store",
606-
default=False,
607-
help="Skip the QuantizedOpFusionPass fusion step (default: False)",
605+
action="store_true",
606+
help="Enable the QuantizedOpFusionPass fusion step",
608607
)
609608
args = parser.parse_args()
610609

@@ -806,7 +805,7 @@ def transform_for_cortex_m_backend(edge, args):
806805
passes = [ReplaceQuantNodesPass()]
807806

808807
# Conditionally add the QuantizedOpFusionPass
809-
if args.enable_qdq_fusion_pass.lower() == "true":
808+
if args.enable_qdq_fusion_pass:
810809
passes.append(QuantizedOpFusionPass())
811810

812811
# Apply the passes

examples/arm/run.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function help() {
7070
echo " --pte_placement=<elf|ADDR> Ethos-U: Control if runtime has PTE baked into the elf or if its placed in memory outside of the elf, defaults to ${pte_placement}"
7171
echo " --et_build_root=<FOLDER> Executorch build output root folder to use, defaults to ${et_build_root}"
7272
echo " --scratch-dir=<FOLDER> Path to your Ethos-U scrach dir if you not using default ${ethos_u_scratch_dir}"
73-
echo " --qdq_fusion_op=<true/false> Enable/Disable QDQ fusion op"
73+
echo " --qdq_fusion_op Enable QDQ fusion op"
7474
exit 0
7575
}
7676

@@ -98,7 +98,7 @@ for arg in "$@"; do
9898
--pte_placement=*) pte_placement="${arg#*=}";;
9999
--et_build_root=*) et_build_root="${arg#*=}";;
100100
--scratch-dir=*) ethos_u_scratch_dir="${arg#*=}" ; scratch_dir_set=true ;;
101-
--qdq_fusion_op=*) qdq_fusion_op="${arg#*=}";;
101+
--qdq_fusion_op) qdq_fusion_op=true;;
102102
*)
103103
;;
104104
esac
@@ -200,6 +200,7 @@ devtools_flag=""
200200
bundleio_flag=""
201201
etrecord_flag=""
202202
et_dump_flag=""
203+
qdq_fusion_op_flag=""
203204
if [ "$build_with_etdump" = true ] ; then
204205
et_dump_flag="--etdump"
205206
etrecord_flag="--etrecord"
@@ -210,6 +211,10 @@ if [ "$bundleio" = true ] ; then
210211
bundleio_flag="--bundleio"
211212
fi
212213

214+
if [ "$qdq_fusion_op" = true ] ; then
215+
qdq_fusion_op_flag="--enable_qdq_fusion_pass"
216+
fi
217+
213218
backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag $et_dump_flag --toolchain="${toolchain}"
214219

215220
if [[ -z "$model_name" ]]; then
@@ -278,7 +283,7 @@ for i in "${!test_model[@]}"; do
278283
model_compiler_flags="${model_compiler_flags} --model_input=${model_input}"
279284
fi
280285

281-
ARM_AOT_CMD="python3 -m examples.arm.aot_arm_compiler --model_name=${model} --target=${target} ${model_compiler_flags} --intermediate=${output_folder} --output=${pte_file} --system_config=${system_config} --memory_mode=${memory_mode} $bundleio_flag ${etrecord_flag} --config=${config} --enable_qdq_fusion_pass=${qdq_fusion_op}"
286+
ARM_AOT_CMD="python3 -m examples.arm.aot_arm_compiler --model_name=${model} --target=${target} ${model_compiler_flags} --intermediate=${output_folder} --output=${pte_file} --system_config=${system_config} --memory_mode=${memory_mode} $bundleio_flag ${etrecord_flag} --config=${config} $qdq_fusion_op_flag"
282287
echo "CALL ${ARM_AOT_CMD}" >&2
283288
${ARM_AOT_CMD} 1>&2
284289

examples/models/checkpoint.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3+
# Copyright 2025 Arm Limited and/or its affiliates.
34
#
45
# This source code is licensed under the BSD-style license found in the
56
# LICENSE file in the root directory of this source tree.
@@ -16,7 +17,7 @@ def get_default_model_resource_dir(model_file_path: str) -> Path:
1617
"""
1718
Get the default path to resouce files (which contain files such as the
1819
checkpoint and param files), either:
19-
1. Uses the path from pkg_resources, only works with buck2
20+
1. Uses the path from importlib.resources, only works with buck2
2021
2. Uses default path located in examples/models/llama/params
2122
2223
Expected to be called from with a `model.py` file located in a
@@ -33,22 +34,22 @@ def get_default_model_resource_dir(model_file_path: str) -> Path:
3334
"""
3435

3536
try:
36-
import pkg_resources
37+
import importlib.resources as _resources
3738

38-
# 1st way: If we can import this path, we are running with buck2 and all resources can be accessed with pkg_resources.
39+
# 1st way: If we can import this path, we are running with buck2 and all resources can be accessed with importlib.resources.
3940
# pyre-ignore
4041
from executorch.examples.models.llama import params # noqa
4142

4243
# Get the model name from the cwd, assuming that this module is called from a path such as
4344
# examples/models/<model_name>/model.py.
4445
model_name = Path(model_file_path).parent.name
45-
resource_dir = Path(
46-
pkg_resources.resource_filename(
47-
f"executorch.examples.models.{model_name}", "params"
48-
)
49-
)
50-
except:
51-
# 2nd way.
46+
model_dir = _resources.files(f"executorch.examples.models.{model_name}")
47+
with _resources.as_file(model_dir) as model_path:
48+
resource_dir = model_path / "params"
49+
assert resource_dir.exists()
50+
51+
except Exception:
52+
# 2nd way:
5253
resource_dir = Path(model_file_path).absolute().parent / "params"
5354

5455
return resource_dir

0 commit comments

Comments
 (0)