Skip to content

Commit f034244

Browse files
authored
Merge branch 'main' into add_inception_v3_test
2 parents d45a7b1 + 48e0bfb commit f034244

33 files changed

+2210
-179
lines changed

.ci/scripts/test_yolo12.sh

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -ex
9+
# shellcheck source=/dev/null
10+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
11+
12+
while [[ $# -gt 0 ]]; do
13+
case "$1" in
14+
-model)
15+
MODEL_NAME="$2" # stories110M
16+
shift 2
17+
;;
18+
-mode)
19+
MODE="$2" # portable or xnnpack+custom or xnnpack+custom+qe
20+
shift 2
21+
;;
22+
-pt2e_quantize)
23+
PT2E_QUANTIZE="$2"
24+
shift 2
25+
;;
26+
-upload)
27+
UPLOAD_DIR="$2"
28+
shift 2
29+
;;
30+
-video_path)
31+
VIDEO_PATH="$2" # portable or xnnpack+custom or xnnpack+custom+qe
32+
shift 2
33+
;;
34+
*)
35+
echo "Unknown option: $1"
36+
usage
37+
;;
38+
esac
39+
done
40+
41+
# Default mode to xnnpack+custom if not set
42+
MODE=${MODE:-"openvino"}
43+
44+
# Default UPLOAD_DIR to empty string if not set
45+
UPLOAD_DIR="${UPLOAD_DIR:-}"
46+
47+
# Default PT2E_QUANTIZE to empty string if not set
48+
PT2E_QUANTIZE="${PT2E_QUANTIZE:-}"
49+
50+
# Default CMake Build Type to release mode
51+
CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release}
52+
53+
if [[ $# -lt 5 ]]; then # Assuming 4 mandatory args
54+
echo "Expecting atleast 5 positional arguments"
55+
echo "Usage: [...]"
56+
fi
57+
if [[ -z "${MODEL_NAME:-}" ]]; then
58+
echo "Missing model name, exiting..."
59+
exit 1
60+
fi
61+
62+
63+
if [[ -z "${MODE:-}" ]]; then
64+
echo "Missing mode, choose openvino or xnnpack, exiting..."
65+
exit 1
66+
fi
67+
68+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
69+
PYTHON_EXECUTABLE=python3
70+
fi
71+
72+
TARGET_LIBS=""
73+
74+
if [[ "${MODE}" =~ .*openvino.* ]]; then
75+
OPENVINO=ON
76+
TARGET_LIBS="$TARGET_LIBS openvino_backend "
77+
78+
git clone https://github.com/openvinotoolkit/openvino.git
79+
cd openvino && git b16b776ac119dafda51f69a80f1e6b7376d02c3b
80+
git submodule update --init --recursive
81+
sudo ./install_build_dependencies.sh
82+
mkdir build && cd build
83+
cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON=ON
84+
make -j$(nproc)
85+
86+
cd ..
87+
cmake --install build --prefix dist
88+
89+
source dist/setupvars.sh
90+
cd ../backends/openvino
91+
pip install -r requirements.txt
92+
cd ../../
93+
else
94+
OPENVINO=OFF
95+
fi
96+
97+
if [[ "${MODE}" =~ .*xnnpack.* ]]; then
98+
XNNPACK=ON
99+
TARGET_LIBS="$TARGET_LIBS xnnpack_backend "
100+
else
101+
XNNPACK=OFF
102+
fi
103+
104+
which "${PYTHON_EXECUTABLE}"
105+
106+
107+
DIR="examples/models/yolo12"
108+
$PYTHON_EXECUTABLE -m pip install -r ${DIR}/requirements.txt
109+
110+
cmake_install_executorch_libraries() {
111+
rm -rf cmake-out
112+
build_dir=cmake-out
113+
mkdir $build_dir
114+
115+
116+
retry cmake -DCMAKE_INSTALL_PREFIX="${build_dir}" \
117+
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
118+
-DEXECUTORCH_BUILD_OPENVINO="$OPENVINO" \
119+
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
120+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
121+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
122+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
123+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
124+
-B"${build_dir}"
125+
126+
# Build the project
127+
cmake --build ${build_dir} --target install --config ${CMAKE_BUILD_TYPE} -j$(nproc)
128+
129+
export CMAKE_ARGS="
130+
-DEXECUTORCH_BUILD_OPENVINO="$OPENVINO" \
131+
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
132+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
133+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
134+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
135+
-DEXECUTORCH_ENABLE_LOGGING=ON \
136+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
137+
-DEXECUTORCH_BUILD_PYBIND=ON"
138+
139+
echo $TARGET_LIBS
140+
export CMAKE_BUILD_ARGS="--target $TARGET_LIBS"
141+
pip install . --no-build-isolation
142+
}
143+
144+
cmake_build_demo() {
145+
echo "Building yolo12 runner"
146+
retry cmake \
147+
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
148+
-DUSE_OPENVINO_BACKEND="$OPENVINO" \
149+
-DUSE_XNNPACK_BACKEND="$XNNPACK" \
150+
-Bcmake-out/${DIR} \
151+
${DIR}
152+
cmake --build cmake-out/${DIR} -j9 --config "$CMAKE_BUILD_TYPE"
153+
154+
}
155+
156+
cleanup_files() {
157+
rm $EXPORTED_MODEL_NAME
158+
}
159+
160+
prepare_artifacts_upload() {
161+
if [ -n "${UPLOAD_DIR}" ]; then
162+
echo "Preparing for uploading generated artifacs"
163+
zip -j model.zip "${EXPORTED_MODEL_NAME}"
164+
mkdir -p "${UPLOAD_DIR}"
165+
mv model.zip "${UPLOAD_DIR}"
166+
mv result.txt "${UPLOAD_DIR}"
167+
168+
fi
169+
}
170+
171+
172+
# Export model.
173+
EXPORTED_MODEL_NAME="${MODEL_NAME}_fp32_${MODE}.pte"
174+
echo "Exporting ${EXPORTED_MODEL_NAME}"
175+
EXPORT_ARGS="--model_name=${MODEL_NAME} --backend=${MODE}"
176+
177+
# Add dynamically linked library location
178+
cmake_install_executorch_libraries
179+
180+
$PYTHON_EXECUTABLE -m examples.models.yolo12.export_and_validate ${EXPORT_ARGS}
181+
182+
183+
RUNTIME_ARGS="--model_path=${EXPORTED_MODEL_NAME} --input_path=${VIDEO_PATH}"
184+
# Check build tool.
185+
cmake_build_demo
186+
# Run yolo12 runner
187+
NOW=$(date +"%H:%M:%S")
188+
echo "Starting to run yolo12 runner at ${NOW}"
189+
# shellcheck source=/dev/null
190+
cmake-out/examples/models/yolo12/Yolo12DetectionDemo ${RUNTIME_ARGS} > result.txt
191+
NOW=$(date +"%H:%M:%S")
192+
echo "Finished at ${NOW}"
193+
194+
RESULT=$(cat result.txt)
195+
196+
prepare_artifacts_upload
197+
cleanup_files

backends/arm/_passes/match_arg_ranks_pass.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def __init__(self, exported_program):
5151
exir_ops.edge.aten.gt.Tensor,
5252
exir_ops.edge.aten.ge.Tensor,
5353
exir_ops.edge.aten.lt.Tensor,
54+
exir_ops.edge.aten.le.Tensor,
5455
exir_ops.edge.aten.pow.Tensor_Tensor,
5556
exir_ops.edge.aten.where.self,
5657
]

backends/arm/_passes/replace_scalar_with_tensor_pass.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
exir_ops.edge.aten.gt.Scalar: exir_ops.edge.aten.gt.Tensor,
3333
exir_ops.edge.aten.ge.Scalar: exir_ops.edge.aten.ge.Tensor,
3434
exir_ops.edge.aten.lt.Scalar: exir_ops.edge.aten.lt.Tensor,
35+
exir_ops.edge.aten.le.Scalar: exir_ops.edge.aten.le.Tensor,
3536
exir_ops.edge.aten.ne.Scalar: exir_ops.edge.aten.ne.Tensor,
3637
torch.ops.aten.add.Scalar: torch.ops.aten.add.Tensor,
3738
torch.ops.aten.sub.Scalar: torch.ops.aten.sub.Tensor,
@@ -43,6 +44,7 @@
4344
torch.ops.aten.gt.Scalar: torch.ops.aten.gt.Tensor,
4445
torch.ops.aten.ge.Scalar: torch.ops.aten.ge.Tensor,
4546
torch.ops.aten.lt.Scalar: torch.ops.aten.lt.Tensor,
47+
torch.ops.aten.le.Scalar: torch.ops.aten.le.Tensor,
4648
torch.ops.aten.ne.Scalar: torch.ops.aten.ne.Tensor,
4749
}
4850

backends/arm/operator_support/ethos_u55_support.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class EthosU55NotSupported(OperatorSupportBase):
138138
exir_ops.edge.aten.gt.Tensor,
139139
exir_ops.edge.aten.gt.Scalar,
140140
exir_ops.edge.aten.le.Tensor,
141+
exir_ops.edge.aten.le.Scalar,
141142
exir_ops.edge.aten.lt.Tensor,
142143
exir_ops.edge.aten.lt.Scalar,
143144
exir_ops.edge.aten.ne.Tensor,

backends/arm/operator_support/tosa_supported_operators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def is_node_supported(
189189
exir_ops.edge.aten.gt.Tensor,
190190
exir_ops.edge.aten.gt.Scalar,
191191
exir_ops.edge.aten.le.Tensor,
192+
exir_ops.edge.aten.le.Scalar,
192193
exir_ops.edge.aten.lt.Tensor,
193194
exir_ops.edge.aten.lt.Scalar,
194195
exir_ops.edge.aten.mul.Tensor,

0 commit comments

Comments
 (0)