Skip to content

Commit 3d66097

Browse files
committed
Enable MPS AOT for macOS by default
1 parent e84c319 commit 3d66097

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

.ci/scripts/test_model.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,17 @@ test_model_with_coreml() {
244244
}
245245

246246
test_model_with_mps() {
247-
"${PYTHON_EXECUTABLE}" -m examples.apple.mps.scripts.mps_example --model_name="${MODEL_NAME}" --use_fp16
247+
"${PYTHON_EXECUTABLE}" -m examples.apple.mps.scripts.mps_example --model_name="${MODEL_NAME}" --use_fp16 --bundled
248248
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit)
249+
250+
if [ -z "${EXPORTED_MODEL}" ]; then
251+
echo "[error] failed to export model: no .pte file found"
252+
exit 1
253+
fi
254+
255+
echo "Testing exported model with mps_executor_runner..."
256+
./examples/apple/mps/scripts/build_mps_executor_runner.sh
257+
./cmake-out/examples/apple/mps/mps_executor_runner -bundled_program=True -model_path="${EXPORTED_MODEL}"
249258
}
250259

251260
if [[ "${BACKEND}" == "portable" ]]; then

.ci/scripts/wheel/test_macos.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@
1919
model=Model.Mv3,
2020
backend=Backend.CoreMlExportAndTest,
2121
),
22+
test_base.ModelTest(
23+
model=Model.Mv3,
24+
backend=Backend.AppleMPS,
25+
),
2226
]
2327
)

examples/apple/mps/scripts/build_mps_executor_runner.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/usr/bin/env bash
22
# Copyright (c) 2024 Apple Inc. All rights reserved.
33
# Provided subject to the LICENSE file in the top level directory.
4+
#
5+
# Copyright (c) Meta Platforms, Inc. and affiliates.
6+
# All rights reserved.
7+
#
8+
# This source code is licensed under the BSD-style license found in the
9+
# LICENSE file in the root directory of this source tree.
10+
411

512
set -e
613

@@ -44,19 +51,18 @@ cmake -DBUCK2="$BUCK" \
4451
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
4552
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
4653
-DEXECUTORCH_BUILD_MPS=ON \
47-
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
54+
-DEXECUTORCH_ENABLE_LOGGING=ON \
4855
-Bcmake-out .
49-
cmake --build cmake-out -j9 --target install --config "$MODE"
56+
cmake --build cmake-out -j$(sysctl -n hw.ncpu) --target install --config "$MODE"
5057
CMAKE_PREFIX_PATH="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
5158
# build mps_executor_runner
5259
rm -rf cmake-out/examples/apple/mps
5360
cmake \
5461
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
5562
-DCMAKE_BUILD_TYPE="$MODE" \
56-
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
5763
-Bcmake-out/examples/apple/mps \
5864
examples/apple/mps
5965

60-
cmake --build cmake-out/examples/apple/mps -j9 --config "$MODE"
66+
cmake --build cmake-out/examples/apple/mps -j$(sysctl -n hw.ncpu) --config "$MODE"
6167

6268
echo "Build succeeded!"

examples/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Backend(str, Enum):
4646
XnnpackQuantizationDelegation = "xnnpack-quantization-delegation"
4747
CoreMlExportOnly = "coreml"
4848
CoreMlExportAndTest = "coreml-test" # AOT export + test with runner
49+
AppleMPS = "mps"
4950

5051
def __str__(self) -> str:
5152
return self.value

tools/cmake/preset/pybind.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set_overridable_option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ON)
2222

2323
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
2424
set_overridable_option(EXECUTORCH_BUILD_COREML ON)
25+
set_overridable_option(EXECUTORCH_BUILD_MPS ON)
2526
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
2627
set_overridable_option(EXECUTORCH_BUILD_COREML ON)
2728
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "WIN32")

0 commit comments

Comments
 (0)