Skip to content

Commit d61d5b7

Browse files
huydhnfacebook-github-bot
authored andcommitted
Add XNNPACK with and without quantization tests to CI (#123)
Summary: TSIA. After #122, we can now add XNNPACK tests to CI. Note that `xnn_executor_runner` is only available via buck2 here, its cmake support will come in the next PR. Pull Request resolved: #123 Test Plan: Spot check for `add` example which supports both XNNPACK and quantization. Both are tested: Linux: https://github.com/pytorch/executorch/actions/runs/5970562477/job/16198874573?pr=123 MacOS: https://github.com/pytorch/executorch/actions/runs/5970562477/job/16198877840?pr=123 Reviewed By: guangy10, kirklandsign Differential Revision: D48670404 Pulled By: huydhn fbshipit-source-id: 51974887cce141d9abccf3581f5003dfb23fe53d
1 parent 036b933 commit d61d5b7

File tree

4 files changed

+62
-20
lines changed

4 files changed

+62
-20
lines changed

.ci/scripts/gather_test_models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,18 @@ def export_models_for_ci() -> None:
4141
quantization = (
4242
name in MODEL_NAME_TO_OPTIONS and MODEL_NAME_TO_OPTIONS[name].quantization
4343
)
44+
xnnpack_delegation = (
45+
name in MODEL_NAME_TO_OPTIONS
46+
and MODEL_NAME_TO_OPTIONS[name].xnnpack_delegation
47+
)
4448
for build_tool in BUILD_TOOLS:
4549
models["include"].append(
46-
{"build-tool": build_tool, "model": name, "quantization": quantization}
50+
{
51+
"build-tool": build_tool,
52+
"model": name,
53+
"quantization": quantization,
54+
"xnnpack_delegation": xnnpack_delegation,
55+
}
4756
)
4857
set_output("models", json.dumps(models))
4958

.ci/scripts/test.sh

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,71 @@ if [[ -z "${QUANTIZATION:-}" ]]; then
2727
QUANTIZATION=false
2828
fi
2929

30+
XNNPACK_DELEGATION=$4
31+
if [[ -z "${XNNPACK_DELEGATION:-}" ]]; then
32+
XNNPACK_DELEGATION=false
33+
fi
34+
35+
which "${PYTHON_EXECUTABLE}"
36+
# Just set this variable here, it's cheap even if we use buck2
37+
CMAKE_OUTPUT_DIR=cmake-out
38+
3039
test_model() {
31-
python -m examples.export.export_example --model_name="${MODEL_NAME}"
40+
"${PYTHON_EXECUTABLE}" -m examples.export.export_example --model_name="${MODEL_NAME}"
3241

3342
# Run test model
3443
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
3544
buck2 run //examples/executor_runner:executor_runner -- --model_path "./${MODEL_NAME}.pte"
3645
elif [[ "${BUILD_TOOL}" == "cmake" ]]; then
37-
CMAKE_OUTPUT_DIR=cmake-out
3846
./${CMAKE_OUTPUT_DIR}/executor_runner --model_path "./${MODEL_NAME}.pte"
3947
else
4048
echo "Invalid build tool ${BUILD_TOOL}. Only buck2 and cmake are supported atm"
4149
exit 1
4250
fi
4351
}
4452

45-
which python
46-
47-
echo "Testing ${MODEL_NAME} with ${BUILD_TOOL}..."
48-
# Test the select model
49-
test_model
53+
test_model_with_xnnpack() {
54+
WITH_QUANTIZATION=$1
55+
if [[ ${WITH_QUANTIZATION} == true ]]; then
56+
SUFFIX="q8"
57+
"${PYTHON_EXECUTABLE}" -m examples.backend.xnnpack_examples --model_name="${MODEL_NAME}" --delegate --quantize
58+
else
59+
SUFFIX="fp32"
60+
"${PYTHON_EXECUTABLE}" -m examples.backend.xnnpack_examples --model_name="${MODEL_NAME}" --delegate
61+
fi
5062

51-
if [[ "${QUANTIZATION}" == true ]]; then
63+
OUTPUT_MODEL_PATH="${MODEL_NAME}_xnnpack_${SUFFIX}.pte"
64+
# Run test model
5265
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
53-
bash examples/quantization/test_quantize.sh buck2 "${MODEL_NAME}"
66+
buck2 run //examples/backend:xnn_executor_runner -- --model_path "${OUTPUT_MODEL_PATH}"
5467
elif [[ "${BUILD_TOOL}" == "cmake" ]]; then
55-
CMAKE_OUTPUT_DIR=cmake-out
56-
bash examples/quantization/test_quantize.sh cmake "${MODEL_NAME}"
68+
# TODO: Add cmake support for xnn_executor_runner
69+
echo "XNNPACK doesn't support cmake yet, skipping..."
5770
else
5871
echo "Invalid build tool ${BUILD_TOOL}. Only buck2 and cmake are supported atm"
5972
exit 1
6073
fi
74+
}
75+
76+
echo "Testing ${MODEL_NAME} (fp32, quantized, xnnpack) with ${BUILD_TOOL}..."
77+
# Test the select model without XNNPACK or quantization
78+
test_model
79+
80+
# Test quantization
81+
if [[ "${QUANTIZATION}" == true ]]; then
82+
bash examples/quantization/test_quantize.sh "${BUILD_TOOL}" "${MODEL_NAME}"
6183
else
6284
echo "The model ${MODEL_NAME} doesn't support quantization yet"
6385
fi
86+
87+
# Test XNNPACK without quantization
88+
if [[ "${XNNPACK_DELEGATION}" == true ]]; then
89+
test_model_with_xnnpack false
90+
else
91+
echo "The model ${MODEL_NAME} doesn't support XNNPACK yet"
92+
fi
93+
94+
# Test XNNPACK with quantization
95+
if [[ "${XNNPACK_DELEGATION}" == true ]] && [[ "${QUANTIZATION}" == true ]]; then
96+
test_model_with_xnnpack true
97+
fi

.github/workflows/pull.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ jobs:
5656
MODEL_NAME=${{ matrix.model }}
5757
BUILD_TOOL=${{ matrix.build-tool }}
5858
QUANTIZATION=${{ matrix.quantization }}
59+
XNNPACK_DELEGATION=${{ matrix.xnnpack_delegation }}
5960
6061
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
6162
# Build and test Executorch
62-
PYTHON_EXECUTABLE=python bash .ci/scripts/test.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${QUANTIZATION}"
63+
PYTHON_EXECUTABLE=python bash .ci/scripts/test.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${QUANTIZATION}" "${XNNPACK_DELEGATION}"
6364
6465
test-models-macos:
6566
name: test-models-macos
@@ -79,11 +80,12 @@ jobs:
7980
MODEL_NAME=${{ matrix.model }}
8081
BUILD_TOOL=${{ matrix.build-tool }}
8182
QUANTIZATION=${{ matrix.quantization }}
83+
XNNPACK_DELEGATION=${{ matrix.xnnpack_delegation }}
8284
8385
# Setup MacOS dependencies as there is no Docker support on MacOS atm
8486
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
8587
# Build and test Executorch
86-
PYTHON_EXECUTABLE=python bash .ci/scripts/test.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${QUANTIZATION}"
88+
PYTHON_EXECUTABLE=python bash .ci/scripts/test.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${QUANTIZATION}" "${XNNPACK_DELEGATION}"
8789
popd
8890
8991
test-custom-ops-linux:

exir/backend/utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ def is_same_node(
3030
and all(
3131
is_same_node(arg_left, arg_right)
3232
for arg_left, arg_right in zip(
33-
node_left.all_input_nodes, node_right.all_input_nodes, strict=True
33+
node_left.all_input_nodes, node_right.all_input_nodes
3434
)
3535
)
3636
):
3737
return False
3838
else:
3939
if len(list(node_left)) != len(list(node_right)):
4040
return False
41-
for n_left, n_right in zip(node_left, node_right, strict=True):
41+
for n_left, n_right in zip(node_left, node_right):
4242
# pyre-fixme[6]: For 1st argument expected `Iterable[Node]` but got `Node`.
4343
# pyre-fixme[6]: For 2nd argument expected `Iterable[Node]` but got `Node`.
4444
if not is_same_node(n_left, n_right):
@@ -55,9 +55,7 @@ def is_identical_graph(
5555
# is not the same.
5656
if len(list(graph_left.graph.nodes)) != len(list(graph_right.graph.nodes)):
5757
return False
58-
for node_left, node_right in zip(
59-
graph_left.graph.nodes, graph_right.graph.nodes, strict=True
60-
):
58+
for node_left, node_right in zip(graph_left.graph.nodes, graph_right.graph.nodes):
6159
if not (is_same_node(node_left, node_right)):
6260
return False
6361
return True
@@ -90,7 +88,6 @@ def replace_quantized_partition_with_op(
9088
partition: SourcePartition,
9189
replacement_op: torch._ops.OpOverloadPacket,
9290
) -> Tuple[torch.fx.Node, List[torch.fx.Node], List[torch.fx.Node]]:
93-
9491
"""
9592
Replaces partition with the op specified by replacement_op. It's also expected that
9693
the nodes contained in partition are sourced from a quantized module as this function

0 commit comments

Comments
 (0)