Skip to content

Commit e0235f0

Browse files
authored
Create the foundation for testing CoreML export for wheels (#9381)
### Summary As part of #9019, this will allow us to test CoreML support for wheels. #### Why are we only selectively running the executor test? Our `macos-*-stable` runners do not have xcode, which is required to build and run these tests. Only GitHub's `macos-*-xlarge` runners have xcode. We currently run these CoreML tests on [trunk](https://github.com/pytorch/executorch/blob/7c6d2f332861907391450974a481b6d8e04732ed/.github/workflows/trunk.yml#L444-L477), which would be way too expensive to use GitHub's runner given the frequency. So let's limit the runner tests to just the wheel jobs. I will work with Test Infra to get Xcode into our runners. ### Test plan * Wheel tests shouldn't change * Test locally ```bash $ GITHUB_WORKSPACE=$(dirname $(pwd)) REPOSITORY=$(basename $(pwd)) python .ci/scripts/wheel/test_macos.py ```
1 parent a5d64cf commit e0235f0

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

.ci/scripts/test_model.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,14 @@ test_model_with_qnn() {
209209
EXPORTED_MODEL=$(find "./${EXPORT_SCRIPT}" -type f -name "${MODEL_NAME}*.pte" -print -quit)
210210
}
211211

212+
# Run CoreML tests.
213+
#
214+
# @param should_test If true, build and test the model using the coreml_executor_runner.
212215
test_model_with_coreml() {
213-
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
214-
echo "coreml doesn't support buck2."
216+
local should_test="$1"
217+
218+
if [[ "${BUILD_TOOL}" != "cmake" ]]; then
219+
echo "coreml only supports cmake."
215220
exit 1
216221
fi
217222

@@ -229,6 +234,14 @@ test_model_with_coreml() {
229234
echo "No .pte file found"
230235
exit 1
231236
fi
237+
238+
# Run the model
239+
if [ "${should_test}" = true ]; then
240+
echo "Testing exported model with coreml_executor_runner..."
241+
local out_dir=$(mktemp -d)
242+
COREML_EXECUTOR_RUNNER_OUT_DIR="${out_dir}" examples/apple/coreml/scripts/build_executor_runner.sh
243+
"${out_dir}/coreml_executor_runner" --model_path "${EXPORTED_MODEL}"
244+
fi
232245
}
233246

234247
test_model_with_mps() {
@@ -247,7 +260,11 @@ elif [[ "${BACKEND}" == *"qnn"* ]]; then
247260
fi
248261
elif [[ "${BACKEND}" == *"coreml"* ]]; then
249262
echo "Testing ${MODEL_NAME} with coreml..."
250-
test_model_with_coreml
263+
should_test_coreml=false
264+
if [[ "${BACKEND}" == *"test"* ]]; then
265+
should_test_coreml=true
266+
fi
267+
test_model_with_coreml "${should_test_coreml}"
251268
if [[ $? -eq 0 ]]; then
252269
prepare_artifacts_upload
253270
fi

.ci/scripts/wheel/test_macos.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
test_base.ModelTest(
1515
model=Model.Mv3,
1616
backend=Backend.XnnpackQuantizationDelegation,
17-
)
17+
),
18+
# Enable this once CoreML is suppported out-of-the-box
19+
# https://github.com/pytorch/executorch/issues/9019
20+
# test_base.ModelTest(
21+
# model=Model.Mv3,
22+
# backend=Backend.CoreMlTest,
23+
# )
1824
]
1925
)

examples/apple/coreml/scripts/build_executor_runner.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@ XCODE_WORKSPACE_DIR_PATH="$EXAMPLES_COREML_DIR_PATH/executor_runner"
7777
XCODE_BUILD_DIR_PATH="$EXAMPLES_COREML_DIR_PATH/xcode-build"
7878

7979
xcodebuild build -workspace "$XCODE_WORKSPACE_DIR_PATH/coreml_executor_runner.xcworkspace" -scheme coreml_executor_runner BUILD_DIR="$XCODE_BUILD_DIR_PATH"
80-
cp -f "$XCODE_BUILD_DIR_PATH/DEBUG/coreml_executor_runner" "$PWD"
80+
81+
if [[ -z "${COREML_EXECUTOR_RUNNER_OUT_DIR:-}" ]]; then
82+
COREML_EXECUTOR_RUNNER_OUT_DIR=$(pwd)
83+
elif [[ ! -d "${COREML_EXECUTOR_RUNNER_OUT_DIR}" ]]; then
84+
mkdir -p "${COREML_EXECUTOR_RUNNER_OUT_DIR}"
85+
fi
86+
cp -f "$XCODE_BUILD_DIR_PATH/DEBUG/coreml_executor_runner" "${COREML_EXECUTOR_RUNNER_OUT_DIR}"
87+
echo "created ${COREML_EXECUTOR_RUNNER_OUT_DIR}/coreml_executor_runner"

examples/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __str__(self) -> str:
4444

4545
class Backend(str, Enum):
4646
XnnpackQuantizationDelegation = "xnnpack-quantization-delegation"
47+
CoreMlTest = "coreml-test"
4748

4849
def __str__(self) -> str:
4950
return self.value

0 commit comments

Comments
 (0)