Skip to content

Commit 43ed468

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Properly register quantized out ops into AOT export flow (#3449)
Summary: Currently are registering all ops specified in quantized.yaml into AOT, that causes double registration problem because some of them are already registered in https://github.com/pytorch/executorch/blob/main/exir/passes/_quant_patterns_and_replacements.py#L185-L188 This PR changes the way we do selective build for these quantized ops, by listing out individual ops that we want to register. We also updated the current CI job to be able to error out when this registration doesn't work. Pull Request resolved: #3449 Reviewed By: mergennachin Differential Revision: D56844556 Pulled By: larryliu0820 fbshipit-source-id: 7b77aa7e019543cbdcce02b6f6662acf31dbb3f4
1 parent 5d2a17b commit 43ed468

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

.github/workflows/pull.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ jobs:
208208
209209
BUILD_TOOL=${{ matrix.build-tool }}
210210
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
211-
PYTHON_EXECUTABLE=python bash .ci/scripts/test_quantized_aot_lib.sh
211+
PYTHON_EXECUTABLE=python bash examples/xnnpack/quantization/test_quantize.sh "${BUILD_TOOL}" mv2
212212
213213
test-pybind-build-linux:
214214
name: test-pybind-build-linux

codegen/tools/gen_oplist.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,12 @@ def gen_oplist(
210210
source_name = None
211211
et_kernel_metadata = {}
212212
if root_ops:
213-
op_set.update(set(filter(lambda x: len(x) > 0, root_ops.split(","))))
213+
# decide delimiter
214+
delimiter = "," if "," in root_ops else " "
215+
print(root_ops)
216+
op_set.update(
217+
set(filter(lambda x: len(x) > 0, map(str.strip, root_ops.split(delimiter))))
218+
)
214219
et_kernel_metadata = merge_et_kernel_metadata(
215220
et_kernel_metadata, {op: ["default"] for op in op_set}
216221
)

examples/xnnpack/quantization/test_quantize.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ test_cmake_quantization() {
5050
(rm -rf cmake-out \
5151
&& mkdir cmake-out \
5252
&& cd cmake-out \
53-
&& retry cmake -DBUCK2="$BUCK" \
53+
&& retry cmake \
5454
-DCMAKE_BUILD_TYPE=Release \
5555
-DEXECUTORCH_BUILD_XNNPACK="$EXECUTORCH_BUILD_XNNPACK" \
56+
-DEXECUTORCH_BUILD_QUANTIZED=ON \
57+
-DEXECUTORCH_BUILD_QUANTIZED_OPS_AOT=ON \
5658
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
5759
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
5860

kernels/quantized/CMakeLists.txt

+15-3
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,27 @@ message("Generated files ${gen_command_sources}")
5555
# dependency of the other(s). This is not allowed by the Xcode "new build
5656
# system".
5757
if(NOT CMAKE_GENERATOR STREQUAL "Xcode" AND EXECUTORCH_BUILD_QUANTIZED_OPS_AOT)
58-
gen_selected_ops(LIB_NAME "quantized_ops_aot_lib" OPS_SCHEMA_YAML
59-
"${_yaml_file}")
58+
set(_quantized_aot_ops
59+
"quantized_decomposed::add.out"
60+
"quantized_decomposed::choose_qparams.Tensor_out"
61+
"quantized_decomposed::dequantize_per_channel.out"
62+
"quantized_decomposed::dequantize_per_tensor.out"
63+
"quantized_decomposed::dequantize_per_tensor.Tensor_out"
64+
"quantized_decomposed::mixed_linear.out"
65+
"quantized_decomposed::mixed_mm.out"
66+
"quantized_decomposed::quantize_per_channel.out"
67+
"quantized_decomposed::quantize_per_tensor.out"
68+
"quantized_decomposed::quantize_per_tensor.Tensor_out")
69+
gen_selected_ops(LIB_NAME "quantized_ops_aot_lib" ROOT_OPS
70+
${_quantized_aot_ops})
6071
# Expect gen_selected_ops output file to be
61-
# quantized_aot_ops_lib/selected_operators.yaml
72+
# quantized_ops_aot_lib/selected_operators.yaml
6273
generate_bindings_for_kernels(LIB_NAME "quantized_ops_aot_lib"
6374
CUSTOM_OPS_YAML "${_yaml_file}")
6475
# Build a AOT library to register quantized ops into PyTorch. This is a hack.
6576
set(_quantized_sources
6677
${_quantized_kernels__srcs}
78+
${EXECUTORCH_ROOT}/kernels/portable/cpu/util/reduce_util.cpp
6779
${EXECUTORCH_ROOT}/runtime/core/exec_aten/util/tensor_util_aten.cpp)
6880
gen_custom_ops_aot_lib(LIB_NAME "quantized_ops_aot_lib" KERNEL_SOURCES
6981
"${_quantized_sources}")

0 commit comments

Comments
 (0)