Skip to content

Commit bf477e4

Browse files
kirklandsignfacebook-github-bot
authored andcommitted
Fix wheel build and smoke test (#4429)
Summary: Pull Request resolved: #4429 Test Plan: 1. Label `ciflow/binaries` to build wheel 2. CI and OSS CI. This makes sure that smoke test can pass, and a portable model can export and run E2E. Python 3.9 is not supported for now. 3. Run these helps validate unittest failure for quantized ops ``` pip uninstall executorch -y rm dist/*.whl source build/packaging/env_var_script_m1.sh # or Linux python setup.py bdist_wheel pip install dist/*.whl ``` Then in Python, try ``` from executorch.extension.pybindings import portable_lib from executorch.exir.dialects._ops import ops import executorch.kernels.quantized ops.edge.quantized_decomposed.add.default.to_out_variant().name() ``` Reviewed By: larryliu0820 Differential Revision: D60694247 Pulled By: kirklandsign fbshipit-source-id: 4da77493c0e7a868f86b583c9c33d54d08c3e48b
1 parent 05a7d52 commit bf477e4

File tree

8 files changed

+73
-5
lines changed

8 files changed

+73
-5
lines changed

CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,6 @@ if(EXECUTORCH_BUILD_PYBIND)
680680
executorch
681681
extension_data_loader
682682
portable_ops_lib
683-
quantized_ops_aot_lib
684683
util
685684
torch
686685
)
@@ -701,7 +700,6 @@ if(EXECUTORCH_BUILD_PYBIND)
701700

702701
if(EXECUTORCH_BUILD_KERNELS_QUANTIZED)
703702
target_link_options_shared_lib(quantized_ops_lib)
704-
list(APPEND _dep_libs quantized_kernels quantized_ops_lib)
705703
endif()
706704

707705
# compile options for pybind
@@ -755,6 +753,25 @@ if(EXECUTORCH_BUILD_PYBIND)
755753
# the torch libs are in `site-packages/torch/lib`.
756754
BUILD_RPATH "@loader_path/../../../torch/lib"
757755
INSTALL_RPATH "@loader_path/../../../torch/lib"
756+
# Assume <executorch> is the root `site-packages/executorch`
757+
# Need to add <executorch>/extension/llm/custom_ops for
758+
# libcustom_ops_aot_lib.dylib
759+
BUILD_RPATH "@loader_path/../../extension/llm/custom_ops"
760+
INSTALL_RPATH "@loader_path/../../extension/llm/custom_ops"
761+
# Need to add <executorch>/kernels/quantized for
762+
# libquantized_ops_aot_lib.dylib
763+
BUILD_RPATH "@loader_path/../../kernels/quantized"
764+
INSTALL_RPATH "@loader_path/../../kernels/quantized"
765+
)
766+
else()
767+
set_target_properties(
768+
portable_lib
769+
PROPERTIES # Assume <executorch> is the root `site-packages/executorch`
770+
# Need to add <executorch>/extension/llm/custom_ops for
771+
# libcustom_ops_aot_lib
772+
# Need to add <executorch>/kernels/quantized for
773+
# libquantized_ops_aot_lib
774+
BUILD_RPATH "$ORIGIN:$ORIGIN/../../extension/llm/custom_ops:$ORIGIN/../../kernels/quantized"
758775
)
759776
endif()
760777

build/Codegen.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function(gen_custom_ops_aot_lib)
151151

152152
target_link_options_shared_lib(${GEN_LIB_NAME})
153153
if(EXECUTORCH_BUILD_PYBIND AND APPLE)
154-
target_link_libraries(${GEN_LIB_NAME} PRIVATE executorch_no_prim_ops_shared)
154+
target_link_libraries(${GEN_LIB_NAME} PRIVATE executorch_no_prim_ops)
155155
target_link_options(${GEN_LIB_NAME} PRIVATE -undefined dynamic_lookup)
156156
else()
157157
target_link_libraries(${GEN_LIB_NAME} PRIVATE executorch_no_prim_ops)

build/packaging/post_build_script.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77

88
set -eux
99

10-
echo "This script is run after building ExecuTorch binaries"
10+
# This script is run after building ExecuTorch binaries
11+
12+
# Rename pip-out directory, to avoid using shared libraries in pip-out during
13+
# smoke test.
14+
mv pip-out BACKUP-pip-out

kernels/quantized/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
try:
8+
from pathlib import Path
9+
10+
libs = list(Path(__file__).parent.resolve().glob("**/libquantized_ops_aot_lib.*"))
11+
del Path
12+
assert len(libs) == 1, f"Expected 1 library but got {len(libs)}"
13+
import torch as _torch
14+
15+
_torch.ops.load_library(libs[0])
16+
del _torch
17+
except:
18+
import logging
19+
20+
logging.info("libquantized_ops_aot_lib is not loaded")
21+
del logging

kernels/quantized/targets.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,15 @@ def define_common_targets():
8888
],
8989
define_static_targets = True,
9090
)
91+
92+
runtime.python_library(
93+
name = "quantized_ops_lib",
94+
srcs = ["__init__.py"],
95+
deps = [
96+
"//caffe2:torch",
97+
],
98+
visibility = [
99+
"//executorch/kernels/quantized/...",
100+
"@EXECUTORCH_CLIENTS",
101+
],
102+
)

kernels/quantized/test/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ python_unittest(
1515
"//caffe2:torch",
1616
"//executorch/exir/dialects:lib",
1717
"//executorch/exir/passes:quant_fusion_pass",
18+
"//executorch/kernels/quantized:quantized_ops_lib",
1819
],
1920
)

kernels/quantized/test/test_out_variants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import unittest
99

10+
import executorch.kernels.quantized # noqa[F401] 'executorch.kernels.quantized' imported but unused
11+
1012
import torch
1113
import torch.ao.quantization.fx._decomposed # noqa[F401] 'torch.ao.quantization.fx._decomposed' imported but unused
1214
from executorch.exir.dialects._ops import ops

setup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,11 @@ def run(self):
489489
cmake_args += [
490490
"-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON", # add llama sdpa ops to pybindings.
491491
"-DEXECUTORCH_BUILD_KERNELS_CUSTOM_AOT=ON",
492+
"-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON", # add quantized ops to pybindings.
493+
"-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON",
492494
]
493495
build_args += ["--target", "custom_ops_aot_lib"]
496+
build_args += ["--target", "quantized_ops_aot_lib"]
494497
# Allow adding extra cmake args through the environment. Used by some
495498
# tests and demos to expand the set of targets included in the pip
496499
# package.
@@ -570,7 +573,14 @@ def get_ext_modules() -> List[Extension]:
570573
# Install the prebuilt library for custom ops used in llama.
571574
BuiltFile(
572575
"extension/llm/custom_ops/libcustom_ops_aot_lib.*",
573-
"executorch/extension/llm/custom_ops",
576+
"executorch/extension/llm/custom_ops/",
577+
)
578+
)
579+
ext_modules.append(
580+
# Install the prebuilt library for quantized ops required by custom ops.
581+
BuiltFile(
582+
"kernels/quantized/libquantized_ops_aot_lib.*",
583+
"executorch/kernels/quantized/",
574584
)
575585
)
576586

@@ -594,6 +604,7 @@ def get_ext_modules() -> List[Extension]:
594604
"executorch/examples/models": "examples/models",
595605
"executorch/exir": "exir",
596606
"executorch/extension": "extension",
607+
"executorch/kernels/quantized": "kernels/quantized",
597608
"executorch/schema": "schema",
598609
"executorch/sdk": "sdk",
599610
"executorch/sdk/bundled_program": "sdk/bundled_program",

0 commit comments

Comments
 (0)