Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .ci/scripts/build-mediatek-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

set -eux

build_neuron_backend() {
echo "Start building neuron backend."
export ANDROID_NDK=/opt/ndk
export MEDIATEK_SDK_ROOT=/tmp/neuropilot
export NEURON_BUFFER_ALLOCATOR_LIB=${MEDIATEK_SDK_ROOT}/libneuron_buffer_allocator.so
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)"


cd ${EXECUTORCH_ROOT}
./backends/mediatek/scripts/mtk_build.sh
}

build_neuron_backend
46 changes: 46 additions & 0 deletions .ci/scripts/setup-mediatek-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

set -eux

MEDIATEK_INSTALLATION_DIR=/tmp/neuropilot
EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)"

install_neuropilot() {
echo "Start installing neuropilot."
mkdir -p "${MEDIATEK_INSTALLATION_DIR}"

curl -Lo /tmp/neuropilot-express-sdk-8.0.4-build20241016.tar.gz "https://s3.ap-southeast-1.amazonaws.com/mediatek.neuropilot.com/8c1ff4e4-4256-47ed-9e24-67818b4cc4b9.gz"
echo "Finishing downloading neuropilot sdk."
tar zxvf /tmp/neuropilot-express-sdk-8.0.4-build20241016.tar.gz --strip-components=1 --directory "${MEDIATEK_INSTALLATION_DIR}"
echo "Finishing unzip neuropilot sdk."

# Print the content for manual verification
ls -lah "${MEDIATEK_INSTALLATION_DIR}"
}

install_android() {
cp ${EXECUTORCH_ROOT}/.ci/docker/common/install_android.sh install_android.sh
ANDROID_NDK_VERSION=r27b ./install_android.sh
rm install_android.sh
}

setup_neuropilot() {
pip3 install -r ${EXECUTORCH_ROOT}/backends/mediatek/requirements.txt
pip3 install ${MEDIATEK_INSTALLATION_DIR}/mtk_neuron-8.2.13-py3-none-linux_x86_64.whl
pip3 install ${MEDIATEK_INSTALLATION_DIR}/mtk_converter-8.9.1_public_packages/mtk_converter-8.9.1+public-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
}

setup_calibration_data() {
curl -Lo /tmp/imagenette2-160.tgz https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-160.tgz
tar zxvf /tmp/imagenette2-160.tgz --strip-components=1 --directory "${MEDIATEK_INSTALLATION_DIR}"
}

install_android
install_neuropilot
setup_neuropilot
setup_calibration_data
24 changes: 24 additions & 0 deletions .ci/scripts/test_model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@ test_model_with_mps() {
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit)
}

test_model_with_mediatek() {
if [[ "${MODEL_NAME}" == "dl3" ]]; then
EXPORT_SCRIPT=deeplab_v3
elif [[ "${MODEL_NAME}" == "mv3" ]]; then
EXPORT_SCRIPT=mobilenet_v3
elif [[ "${MODEL_NAME}" == "mv2" ]]; then
EXPORT_SCRIPT=mobilenet_v2
elif [[ "${MODEL_NAME}" == "ic4" ]]; then
EXPORT_SCRIPT=inception_v4
elif [[ "${MODEL_NAME}" == "ic3" ]]; then
EXPORT_SCRIPT=inception_v3
fi

"${PYTHON_EXECUTABLE}" -m examples.mediatek.model_export_scripts.${EXPORT_SCRIPT} -d /tmp/neuropilot/train -a ${EXPORT_SCRIPT}
EXPORTED_MODEL=$(find "./${EXPORT_SCRIPT}" -type f -name "*.pte" -print -quit)
}


if [[ "${BACKEND}" == "portable" ]]; then
echo "Testing ${MODEL_NAME} with portable kernels..."
test_model
Expand Down Expand Up @@ -286,6 +304,12 @@ elif [[ "${BACKEND}" == *"xnnpack"* ]]; then
if [[ $? -eq 0 ]]; then
prepare_artifacts_upload
fi
elif [[ "${BACKEND}" == "mediatek" ]]; then
echo "Testing ${MODEL_NAME} with mediatek..."
test_model_with_mediatek
if [[ $? -eq 0 ]]; then
prepare_artifacts_upload
fi
else
set +e
if [[ "${BACKEND}" == *"quantization"* ]]; then
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,6 @@ jobs:
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
conda activate "${CONDA_ENV}"

# placeholder for mediatek to add more tests
bash .ci/scripts/setup-mediatek-deps.sh
bash .ci/scripts/build-mediatek-sdk.sh
bash .ci/scripts/test_model.sh "mv3" "buck2" "mediatek"
Loading