Skip to content

Commit 753e0a1

Browse files
committed
Enable MPS AOT for macOS by default
1 parent 9f74777 commit 753e0a1

File tree

8 files changed

+48
-28
lines changed

8 files changed

+48
-28
lines changed

.ci/scripts/test_model.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ test_model_with_coreml() {
219219
DTYPE=float16
220220

221221
"${PYTHON_EXECUTABLE}" -m examples.apple.coreml.scripts.export --model_name="${MODEL_NAME}" --compute_precision "${DTYPE}" --use_partitioner
222-
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit)
222+
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*coreml*.pte" -print -quit)
223223

224224
if [ -n "$EXPORTED_MODEL" ]; then
225225
EXPORTED_MODEL_WITH_DTYPE="${EXPORTED_MODEL%.pte}_${DTYPE}.pte"
@@ -244,8 +244,18 @@ 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
248-
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit)
247+
"${PYTHON_EXECUTABLE}" -m examples.apple.mps.scripts.mps_example --model_name="${MODEL_NAME}" --bundled --use_fp16
248+
EXPORTED_MODEL="$(pwd)/${MODEL_NAME}_mps_float16_bundled.pte"
249+
250+
if [[ ! -f "${EXPORTED_MODEL}" ]]; then
251+
echo "[error] exported model not found: ${EXPORTED_MODEL}"
252+
exit 1
253+
fi
254+
255+
echo "Testing exported model with mps_executor_runner..."
256+
local out_dir=$(mktemp -d)
257+
examples/apple/mps/scripts/build_mps_executor_runner.sh --output="${out_dir}"
258+
"${out_dir}/examples/apple/mps/mps_executor_runner" --bundled_program --model_path "${EXPORTED_MODEL}"
249259
}
250260

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

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ jobs:
486486
strategy:
487487
fail-fast: false
488488
with:
489-
runner: macos-m1-stable
489+
runner: macos-latest-xlarge
490490
python-version: '3.11'
491491
submodules: 'recursive'
492492
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pip-out/
2525
*.bin
2626
*.model
2727
*.pte
28+
*.etdp
2829
!test_bpe_tokenizer.bin
2930
!test_tiktoken_tokenizer.model
3031

examples/apple/mps/executor_runner/mps_executor_runner.mm renamed to examples/apple/mps/executor_runner/mps_executor_runner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <chrono>
3737
using namespace std::chrono;
3838

39-
static uint8_t method_allocator_pool[4 * 1024U * 1024U]; // 4 MB
39+
static uint8_t method_allocator_pool[16 * 1024U * 1024U]; // 16 MB
4040

4141
DEFINE_string(model_path, "model.ff", "Model serialized in flatbuffer format.");
4242
DEFINE_string(

examples/apple/mps/executor_runner/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def define_common_targets():
1717
runtime.cxx_binary(
1818
name = "mps_executor_runner",
1919
srcs = [
20-
"mps_executor_runner.mm",
20+
"mps_executor_runner.cpp",
2121
],
2222
deps = [
2323
"//executorch/backends/apple/mps:mps_schema",

examples/apple/mps/scripts/build_mps_executor_runner.sh

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
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.
410

5-
set -e
11+
12+
set -eux
613

714
MODE="Release"
815
OUTPUT="cmake-out"
@@ -38,25 +45,26 @@ done
3845

3946
rm -rf "$OUTPUT"
4047

41-
cmake -DBUCK2="$BUCK" \
42-
-DCMAKE_INSTALL_PREFIX=cmake-out \
43-
-DCMAKE_BUILD_TYPE="$MODE" \
44-
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
45-
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
46-
-DEXECUTORCH_BUILD_MPS=ON \
47-
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
48-
-Bcmake-out .
49-
cmake --build cmake-out -j9 --target install --config "$MODE"
50-
CMAKE_PREFIX_PATH="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
51-
# build mps_executor_runner
52-
rm -rf cmake-out/examples/apple/mps
53-
cmake \
54-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
55-
-DCMAKE_BUILD_TYPE="$MODE" \
56-
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
57-
-Bcmake-out/examples/apple/mps \
58-
examples/apple/mps
59-
60-
cmake --build cmake-out/examples/apple/mps -j9 --config "$MODE"
48+
cmake -DCMAKE_INSTALL_PREFIX=${OUTPUT} \
49+
-DCMAKE_BUILD_TYPE=${MODE} \
50+
-DEXECUTORCH_ENABLE_LOGGING=ON \
51+
-B ${OUTPUT} \
52+
--preset macos
53+
54+
cmake --build ${OUTPUT} \
55+
-j $(sysctl -n hw.ncpu) \
56+
--config ${MODE} \
57+
--target install
58+
59+
cmake -DCMAKE_PREFIX_PATH="${OUTPUT}/lib/cmake/ExecuTorch;${OUTPUT}/third-party/gflags" \
60+
-DCMAKE_BUILD_TYPE="$MODE" \
61+
-DCMAKE_OSX_DEPLOYMENT_TARGET="12.0" \
62+
-B "${OUTPUT}/examples/apple/mps" \
63+
-S examples/apple/mps
64+
65+
cmake --build "${OUTPUT}/examples/apple/mps" \
66+
-j $(sysctl -n hw.ncpu) \
67+
--config ${MODE} \
68+
--target mps_executor_runner
6169

6270
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

0 commit comments

Comments
 (0)