Skip to content

Commit a9ef570

Browse files
Update install_requirements.sh to coremltools 9.0 (#15839)
As titled Co-authored-by: Scott Roy <[email protected]>
1 parent 5118de4 commit a9ef570

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed

.ci/scripts/utils.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ install_pip_dependencies() {
4646

4747
install_domains() {
4848
echo "Install torchvision and torchaudio"
49-
pip install --no-use-pep517 --user "git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
50-
pip install --no-use-pep517 --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
49+
pip install --no-build-isolation --user "git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
50+
pip install --no-build-isolation --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
5151
}
5252

5353
install_pytorch_and_domains() {

backends/apple/coreml/scripts/build_tests.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ rm -rf "$CMAKE_EXECUTORCH_BUILD_DIR_PATH"
3030

3131
cmake "$EXECUTORCH_ROOT_PATH" -B"$CMAKE_EXECUTORCH_BUILD_DIR_PATH" \
3232
-DCMAKE_TOOLCHAIN_FILE="$IOS_TOOLCHAIN_PATH" \
33-
-DPLATFORM=MAC_UNIVERSAL \
33+
-DPLATFORM=MAC_ARM64 \
34+
-DCMAKE_OSX_ARCHITECTURES=arm64 \
3435
-DDEPLOYMENT_TARGET=13.0 \
3536
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
3637
-DEXECUTORCH_BUILD_XNNPACK=OFF
@@ -44,7 +45,8 @@ rm -rf "$CMAKE_PROTOBUF_BUILD_DIR_PATH"
4445

4546
cmake "$PROTOBUF_DIR_PATH/cmake" -B"$CMAKE_PROTOBUF_BUILD_DIR_PATH" \
4647
-DCMAKE_TOOLCHAIN_FILE="$IOS_TOOLCHAIN_PATH" \
47-
-DPLATFORM=MAC_UNIVERSAL \
48+
-DPLATFORM=MAC_ARM64 \
49+
-DCMAKE_OSX_ARCHITECTURES=arm64 \
4850
-DDEPLOYMENT_TARGET=13.0 \
4951
-Dprotobuf_BUILD_TESTS=OFF \
5052
-Dprotobuf_BUILD_EXAMPLES=OFF \
@@ -55,7 +57,8 @@ cmake --build "$CMAKE_PROTOBUF_BUILD_DIR_PATH" -j9 -t libprotobuf-lite
5557

5658
# Copy required libraries
5759
echo "ExecuTorch: Copying libraries"
58-
mkdir "$LIBRARIES_DIR_PATH"
60+
rm -rf $LIBRARIES_DIR_PATH
61+
mkdir -p "$LIBRARIES_DIR_PATH"
5962
cp -f "$CMAKE_EXECUTORCH_BUILD_DIR_PATH/libexecutorch.a" "$LIBRARIES_DIR_PATH"
6063
cp -f "$CMAKE_EXECUTORCH_BUILD_DIR_PATH/libexecutorch_core.a" "$LIBRARIES_DIR_PATH"
6164
cp -f "$CMAKE_PROTOBUF_BUILD_DIR_PATH/libprotobuf-lite.a" "$LIBRARIES_DIR_PATH"

backends/apple/coreml/scripts/generate_test_models.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ COREML_DIR_PATH="$EXECUTORCH_ROOT_PATH/backends/apple/coreml"
1515

1616
cd "$EXECUTORCH_ROOT_PATH"
1717

18-
mkdir "$COREML_DIR_PATH/runtime/test/models/"
18+
rm -rf "$COREML_DIR_PATH/runtime/test/models/"
19+
mkdir -p "$COREML_DIR_PATH/runtime/test/models/"
20+
1921
#Generate models
2022
cd "$EXECUTORCH_ROOT_PATH"
2123

backends/apple/coreml/scripts/install_requirements.sh

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8+
set -euo pipefail
9+
810
SCRIPT_DIR_PATH="$(
911
cd -- "$(dirname "$0")" >/dev/null 2>&1
1012
pwd -P
1113
)"
1214

1315
# TODO(jathu): remove the need to fetch coremltools to build deps for coreml_executor_runner.
1416
# Keep this version in sync with: pyproject.toml
15-
COREMLTOOLS_VERSION="9.0b1"
17+
COREMLTOOLS_VERSION="9.0"
1618

17-
red=`tput setaf 1`
18-
green=`tput setaf 2`
19+
# Safe colors (no TERM noise in CI)
20+
if command -v tput >/dev/null 2>&1 && [ -t 1 ] && [ -n "${TERM:-}" ]; then
21+
red="$(tput setaf 1)"
22+
green="$(tput setaf 2)"
23+
reset="$(tput sgr0)"
24+
else
25+
red=""; green=""; reset=""
26+
fi
1927

2028
EXECUTORCH_ROOT_PATH=$(realpath "$SCRIPT_DIR_PATH/../../../../")
2129
COREML_DIR_PATH="$EXECUTORCH_ROOT_PATH/backends/apple/coreml"
@@ -25,30 +33,79 @@ PROTOBUF_FILES_DIR_PATH="$COREMLTOOLS_DIR_PATH/build/mlmodel/format/"
2533
cd "$EXECUTORCH_ROOT_PATH"
2634

2735
rm -rf "$COREML_DIR_PATH/third-party"
28-
mkdir "$COREML_DIR_PATH/third-party"
36+
mkdir -p "$COREML_DIR_PATH/third-party"
2937

30-
echo "${green}ExecuTorch: Cloning coremltools."
31-
git clone --depth 1 --branch "${COREMLTOOLS_VERSION}" "https://github.com/apple/coremltools.git" $COREMLTOOLS_DIR_PATH
32-
cd $COREMLTOOLS_DIR_PATH
38+
echo "${green}ExecuTorch: Cloning coremltools.${reset}"
39+
git clone --depth 1 --branch "${COREMLTOOLS_VERSION}" "https://github.com/apple/coremltools.git" "$COREMLTOOLS_DIR_PATH"
40+
cd "$COREMLTOOLS_DIR_PATH"
3341

3442
STATUS=$?
3543
if [ $STATUS -ne 0 ]; then
36-
echo "${red}ExecuTorch: Failed to clone coremltools."
44+
echo "${red}ExecuTorch: Failed to clone coremltools.${reset}"
3745
exit 1
3846
fi
3947

40-
echo "${green}ExecuTorch: Installing coremltools dependencies."
41-
pip install -r "$COREMLTOOLS_DIR_PATH/reqs/build.pip"
48+
# ---------------------------------------------------------------------
49+
# Host toolchain / SDK setup JUST for coremltools build
50+
# ---------------------------------------------------------------------
51+
HOST_SDKROOT="${SDKROOT:-}"
52+
HOST_CC="${CC:-}"
53+
HOST_CXX="${CXX:-}"
54+
HOST_CFLAGS="${CFLAGS:-}"
55+
HOST_CXXFLAGS="${CXXFLAGS:-}"
56+
57+
if [[ "$(uname)" == "Darwin" ]]; then
58+
# Only pick macOS SDK if nothing else is specified
59+
if [[ -z "$HOST_SDKROOT" ]]; then
60+
HOST_SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
61+
fi
62+
if [[ -z "$HOST_CC" ]]; then
63+
HOST_CC="$(xcrun --find clang)"
64+
fi
65+
if [[ -z "$HOST_CXX" ]]; then
66+
HOST_CXX="$(xcrun --find clang++)"
67+
fi
68+
# Only add -isysroot if caller didn't already set CFLAGS/CXXFLAGS
69+
if [[ -z "$HOST_CFLAGS" && -n "$HOST_SDKROOT" ]]; then
70+
HOST_CFLAGS="-isysroot ${HOST_SDKROOT}"
71+
fi
72+
if [[ -z "$HOST_CXXFLAGS" && -n "$HOST_SDKROOT" ]]; then
73+
HOST_CXXFLAGS="-isysroot ${HOST_SDKROOT}"
74+
fi
75+
fi
76+
77+
echo "${green}ExecuTorch: Installing coremltools dependencies.${reset}"
78+
SDKROOT="$HOST_SDKROOT" \
79+
CC="$HOST_CC" \
80+
CXX="$HOST_CXX" \
81+
CFLAGS="$HOST_CFLAGS" \
82+
CXXFLAGS="$HOST_CXXFLAGS" \
83+
python -m pip install -r "$COREMLTOOLS_DIR_PATH/reqs/build.pip"
4284
STATUS=$?
4385
if [ $STATUS -ne 0 ]; then
44-
echo "${red}ExecuTorch: Failed to install coremltools dependencies."
86+
echo "${red}ExecuTorch: Failed to install coremltools dependencies.${reset}"
4587
exit 1
4688
fi
4789

48-
mkdir "$COREMLTOOLS_DIR_PATH/build"
90+
mkdir -p "$COREMLTOOLS_DIR_PATH/build"
91+
92+
echo "${green}ExecuTorch: Configuring coremltools CMake build.${reset}"
93+
SDKROOT="$HOST_SDKROOT" \
94+
CC="$HOST_CC" \
95+
CXX="$HOST_CXX" \
96+
CFLAGS="$HOST_CFLAGS" \
97+
CXXFLAGS="$HOST_CXXFLAGS" \
4998
cmake -S "$COREMLTOOLS_DIR_PATH" -B "$COREMLTOOLS_DIR_PATH/build"
99+
100+
echo "${green}ExecuTorch: Building mlmodel target.${reset}"
101+
SDKROOT="$HOST_SDKROOT" \
102+
CC="$HOST_CC" \
103+
CXX="$HOST_CXX" \
104+
CFLAGS="$HOST_CFLAGS" \
105+
CXXFLAGS="$HOST_CXXFLAGS" \
50106
cmake --build "$COREMLTOOLS_DIR_PATH/build" --parallel --target mlmodel
51107

52-
echo "${green}ExecuTorch: Copying protobuf files."
108+
echo "${green}ExecuTorch: Copying protobuf files.${reset}"
109+
rm -rf "$COREML_DIR_PATH/runtime/sdk/format/"
53110
mkdir -p "$COREML_DIR_PATH/runtime/sdk/format/"
54111
cp -rf "$PROTOBUF_FILES_DIR_PATH" "$COREML_DIR_PATH/runtime/sdk/format/"

0 commit comments

Comments
 (0)