Skip to content

Commit de478c4

Browse files
committed
Arm backend: Load quantized_ops_aot_lib with arm quantizer module.
Instead of defining a new function for loading the quantized_aot_lib, and portable_lib, simply import the module to reuse the logic which is implemented in the __init__ file. By doing this when importing the arm quantizer, we are sure that this lib is loaded when running quantized networks. Signed-off-by: Adrian Lundell <[email protected]> Change-Id: I5ef585981a09d332d15f7001fb97536b1a56def7
1 parent 4488e8a commit de478c4

File tree

3 files changed

+14
-43
lines changed

3 files changed

+14
-43
lines changed

backends/arm/quantizer/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@
1313

1414
# Used in tests
1515
from .arm_quantizer_utils import is_annotated # noqa
16+
17+
# Load quantized ops library.
18+
try:
19+
import executorch.extension.pybindings.portable_lib
20+
import executorch.kernels.quantized # noqa
21+
except:
22+
import logging
23+
24+
logging.info(
25+
"Failed to load portable_lib and quantized_aot_lib. To run quantized kernels AOT, either build "
26+
"Executorch with pybindings, or load your own custom built op library using torch.ops.load_library."
27+
)
28+
del logging

backends/arm/test/conftest.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6-
import glob
76
import logging
87
import os
9-
import platform
108
import random
119
import shutil
1210
import sys
@@ -81,8 +79,7 @@ def try_addoption(*args, **kwargs):
8179

8280

8381
def pytest_sessionstart(session):
84-
if not session.config.option.collectonly:
85-
_load_libquantized_ops_aot_lib()
82+
pass
8683

8784

8885
def pytest_sessionfinish(session, exitstatus):
@@ -172,36 +169,3 @@ def get_option(option: str) -> Any | None:
172169
if option in pytest._test_options: # type: ignore[attr-defined]
173170
return pytest._test_options[option] # type: ignore[attr-defined]
174171
return None
175-
176-
177-
def _load_lib(lib_name_pattern: str):
178-
"""
179-
Find and load a library by name in build_folder.
180-
"""
181-
182-
library_paths = glob.glob(lib_name_pattern, recursive=True)
183-
if len(library_paths) > 0:
184-
import torch
185-
186-
torch.ops.load_library(library_paths[0])
187-
else:
188-
raise RuntimeError(
189-
f"Did not find any library matching {lib_name_pattern}. Have you installed executorch properly?"
190-
)
191-
192-
193-
def _load_libquantized_ops_aot_lib():
194-
"""
195-
Find and load the libquantized_ops_aot_lib shared library.
196-
"""
197-
198-
so_ext = {
199-
"Darwin": "dylib",
200-
"Linux": "so",
201-
"Windows": "dll",
202-
}.get(platform.system(), None)
203-
204-
executorch_path = os.path.join(os.path.dirname(__file__), "..", "..", "..")
205-
206-
_load_lib(f"{executorch_path}/**/_portable_lib.cpython-310*{so_ext}")
207-
_load_lib(f"{executorch_path}/**/libquantized_ops_aot_lib.{so_ext}")

examples/arm/aot_arm_compiler.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
get_symmetric_quantization_config,
3030
TOSAQuantizer,
3131
)
32-
from executorch.backends.arm.test.conftest import _load_libquantized_ops_aot_lib
3332
from executorch.backends.arm.tosa_partitioner import TOSAPartitioner
3433
from executorch.backends.arm.tosa_specification import TosaSpecification
3534

@@ -510,11 +509,6 @@ def get_args():
510509
if args.debug:
511510
logging.basicConfig(level=logging.DEBUG, format=FORMAT, force=True)
512511

513-
# Load quantized ops library.
514-
if args.quantize:
515-
logging.info("Loading lib_quantized_custom_op_lib")
516-
_load_libquantized_ops_aot_lib()
517-
518512
# if we have custom ops, register them before processing the model
519513
if args.so_library is not None:
520514
logging.info(f"Loading custom ops from {args.so_library}")

0 commit comments

Comments
 (0)