Skip to content

Commit 31f2a11

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Run quantized example models (#118)
Summary: Pull Request resolved: #118 Run quantized example models in `test_quantize.sh`, for both cmake and buck2. Reviewed By: digantdesai, guangy10 Differential Revision: D48634756 fbshipit-source-id: e7aa3a0065142cb37b2592947aed19a4d4e84967
1 parent 8683882 commit 31f2a11

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ endif()
280280
# Generate lib to register quantized ops
281281
if(REGISTER_QUANTIZED_OPS)
282282
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/quantized)
283+
list(APPEND _libs quantized_ops_lib)
283284
endif()
284285

285286
# ios can only build library but not binary

examples/executor_runner/targets.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def define_common_targets():
2727
)
2828

2929
register_custom_op = native.read_config("executorch", "register_custom_op", "0")
30-
30+
register_quantized_ops = native.read_config("executorch", "register_quantized_ops", "0")
3131
if register_custom_op == "1":
32-
custom_ops_lib = ["//executorch/examples/custom_ops:lib_1"]
32+
custom_ops_lib.append("//executorch/examples/custom_ops:lib_1")
3333
elif register_custom_op == "2":
34-
custom_ops_lib = ["//executorch/examples/custom_ops:lib_2"]
35-
else:
36-
custom_ops_lib = []
34+
custom_ops_lib.append("//executorch/examples/custom_ops:lib_2")
35+
if register_quantized_ops == "1":
36+
custom_ops_lib.append("//executorch/kernels/quantized:generated_lib")
3737

3838
# Test driver for models, uses all portable kernels and a demo backend. This
3939
# is intended to have minimal dependencies. If you want a runner that links

examples/quantization/test_quantize.sh

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

88
# Test the end-to-end quantization flow.
99

10-
set -e
10+
set -eu
1111

1212
get_shared_lib_ext() {
1313
UNAME=$(uname)
@@ -30,6 +30,14 @@ test_buck2_quantization() {
3030

3131
echo "Run example.py"
3232
${PYTHON_EXECUTABLE} -m "examples.quantization.example" --so_library="$SO_LIB" --model_name="$1"
33+
34+
echo 'Running executor_runner'
35+
buck2 run //examples/executor_runner:executor_runner \
36+
--config=executorch.register_quantized_ops=1 -- --model_path="./$1.pte"
37+
# should give correct result
38+
39+
echo "Removing $1.pte"
40+
rm "./$1.pte"
3341
}
3442

3543
test_cmake_quantization() {
@@ -52,6 +60,13 @@ test_cmake_quantization() {
5260

5361
echo "Run example.py, shared library $SO_LIB"
5462
${PYTHON_EXECUTABLE} -m "examples.quantization.example" --so_library="$SO_LIB" --model_name="$1"
63+
64+
echo 'Running executor_runner'
65+
cmake-out/executor_runner --model_path="./$1.pte"
66+
# should give correct result
67+
68+
echo "Removing $1.pte"
69+
rm "./$1.pte"
5570
}
5671

5772
if [[ -z $PYTHON_EXECUTABLE ]];

kernels/quantized/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ gen_custom_ops_aot_lib("quantized_ops_aot_lib" "${_quantized_sources}")
5252

5353
# Build a library for _quantized_kernels_srcs
5454
#
55-
# quantized_kernels: Pure-C++ kernel library for quantized ops
56-
gen_operators_lib("quantized_kernels" "${_quantized_kernels__srcs}")
55+
# quantized_ops_lib: Register quantized ops kernels into Executorch runtime
56+
gen_operators_lib("quantized_ops_lib" "${_quantized_kernels__srcs}")

0 commit comments

Comments
 (0)