Skip to content

Commit f476f50

Browse files
neuropilot-captainMediaTek-aineuropilot-captain
authored
Add MediaTek backend CI (#7120)
- Adding CI for MediaTek backend - Add test to workflow --------- Co-authored-by: Poyuan Jeng <[email protected]> Co-authored-by: neuropilot-captain <[email protected]>
1 parent f7cc72f commit f476f50

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

.ci/scripts/build-mediatek-sdk.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 -eux
9+
10+
build_neuron_backend() {
11+
echo "Start building neuron backend."
12+
export ANDROID_NDK=/opt/ndk
13+
export MEDIATEK_SDK_ROOT=/tmp/neuropilot
14+
export NEURON_BUFFER_ALLOCATOR_LIB=${MEDIATEK_SDK_ROOT}/libneuron_buffer_allocator.so
15+
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)"
16+
17+
18+
cd ${EXECUTORCH_ROOT}
19+
./backends/mediatek/scripts/mtk_build.sh
20+
}
21+
22+
build_neuron_backend

.ci/scripts/setup-mediatek-deps.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 -eux
9+
10+
MEDIATEK_INSTALLATION_DIR=/tmp/neuropilot
11+
EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)"
12+
13+
install_neuropilot() {
14+
echo "Start installing neuropilot."
15+
mkdir -p "${MEDIATEK_INSTALLATION_DIR}"
16+
17+
curl -Lo /tmp/neuropilot-express.tar.gz "https://s3.ap-southeast-1.amazonaws.com/mediatek.neuropilot.com/06302508-4c94-4bf2-9789-b0ee44e83e27.gz"
18+
echo "Finishing downloading neuropilot sdk."
19+
tar zxvf /tmp/neuropilot-express.tar.gz --strip-components=1 --directory "${MEDIATEK_INSTALLATION_DIR}"
20+
echo "Finishing unzip neuropilot sdk."
21+
22+
# Copy NP header
23+
cp ${MEDIATEK_INSTALLATION_DIR}/api/NeuronAdapter.h ${EXECUTORCH_ROOT}/backends/mediatek/runtime/include/api/
24+
25+
# Print the content for manual verification
26+
ls -lah "${MEDIATEK_INSTALLATION_DIR}"
27+
}
28+
29+
setup_neuropilot() {
30+
pip3 install -r ${EXECUTORCH_ROOT}/backends/mediatek/requirements.txt
31+
pip3 install ${MEDIATEK_INSTALLATION_DIR}/mtk_neuron-8.2.19-py3-none-linux_x86_64.whl
32+
pip3 install ${MEDIATEK_INSTALLATION_DIR}/mtk_converter-8.13.0_public_packages/mtk_converter-8.13.0+public-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
33+
}
34+
35+
setup_calibration_data() {
36+
curl -Lo /tmp/imagenette2-160.tgz https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-160.tgz
37+
tar zxvf /tmp/imagenette2-160.tgz --strip-components=1 --directory "${MEDIATEK_INSTALLATION_DIR}"
38+
}
39+
40+
install_neuropilot
41+
setup_neuropilot
42+
setup_calibration_data

.ci/scripts/test_model.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,24 @@ test_model_with_mps() {
244244
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit)
245245
}
246246

247+
test_model_with_mediatek() {
248+
if [[ "${MODEL_NAME}" == "dl3" ]]; then
249+
EXPORT_SCRIPT=deeplab_v3
250+
elif [[ "${MODEL_NAME}" == "mv3" ]]; then
251+
EXPORT_SCRIPT=mobilenet_v3
252+
elif [[ "${MODEL_NAME}" == "mv2" ]]; then
253+
EXPORT_SCRIPT=mobilenet_v2
254+
elif [[ "${MODEL_NAME}" == "ic4" ]]; then
255+
EXPORT_SCRIPT=inception_v4
256+
elif [[ "${MODEL_NAME}" == "ic3" ]]; then
257+
EXPORT_SCRIPT=inception_v3
258+
fi
259+
260+
PYTHONPATH=examples/mediatek/ "${PYTHON_EXECUTABLE}" -m examples.mediatek.model_export_scripts.${EXPORT_SCRIPT} -d /tmp/neuropilot/train -a ${EXPORT_SCRIPT}
261+
EXPORTED_MODEL=$(find "./${EXPORT_SCRIPT}" -type f -name "*.pte" -print -quit)
262+
}
263+
264+
247265
if [[ "${BACKEND}" == "portable" ]]; then
248266
echo "Testing ${MODEL_NAME} with portable kernels..."
249267
test_model
@@ -281,6 +299,12 @@ elif [[ "${BACKEND}" == *"xnnpack"* ]]; then
281299
if [[ $? -eq 0 ]]; then
282300
prepare_artifacts_upload
283301
fi
302+
elif [[ "${BACKEND}" == "mediatek" ]]; then
303+
echo "Testing ${MODEL_NAME} with mediatek..."
304+
test_model_with_mediatek
305+
if [[ $? -eq 0 ]]; then
306+
prepare_artifacts_upload
307+
fi
284308
else
285309
set +e
286310
if [[ "${BACKEND}" == *"quantization"* ]]; then

.github/workflows/pull.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,12 @@ jobs:
705705
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
706706
conda activate "${CONDA_ENV}"
707707
708+
source .ci/scripts/utils.sh
709+
install_executorch "--use-pt-pinned-commit"
710+
711+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-mediatek-deps.sh
712+
PYTHON_EXECUTABLE=python bash .ci/scripts/build-mediatek-sdk.sh
713+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "mv3" "buck2" "mediatek"
708714
# placeholder for mediatek to add more tests
709715
710716
test-openvino-linux:

0 commit comments

Comments
 (0)