diff --git a/.ci/scripts/test_model.sh b/.ci/scripts/test_model.sh index 5940affc109..51e81e62a9f 100755 --- a/.ci/scripts/test_model.sh +++ b/.ci/scripts/test_model.sh @@ -209,9 +209,14 @@ test_model_with_qnn() { EXPORTED_MODEL=$(find "./${EXPORT_SCRIPT}" -type f -name "${MODEL_NAME}*.pte" -print -quit) } +# Run CoreML tests. +# +# @param should_test If true, build and test the model using the coreml_executor_runner. test_model_with_coreml() { - if [[ "${BUILD_TOOL}" == "buck2" ]]; then - echo "coreml doesn't support buck2." + local should_test="$1" + + if [[ "${BUILD_TOOL}" != "cmake" ]]; then + echo "coreml only supports cmake." exit 1 fi @@ -229,6 +234,14 @@ test_model_with_coreml() { echo "No .pte file found" exit 1 fi + + # Run the model + if [ "${should_test}" = true ]; then + echo "Testing exported model with coreml_executor_runner..." + local out_dir=$(mktemp -d) + COREML_EXECUTOR_RUNNER_OUT_DIR="${out_dir}" examples/apple/coreml/scripts/build_executor_runner.sh + "${out_dir}/coreml_executor_runner" --model_path "${EXPORTED_MODEL}" + fi } test_model_with_mps() { @@ -247,7 +260,11 @@ elif [[ "${BACKEND}" == *"qnn"* ]]; then fi elif [[ "${BACKEND}" == *"coreml"* ]]; then echo "Testing ${MODEL_NAME} with coreml..." - test_model_with_coreml + should_test_coreml=false + if [[ "${BACKEND}" == *"test"* ]]; then + should_test_coreml=true + fi + test_model_with_coreml "${should_test_coreml}" if [[ $? -eq 0 ]]; then prepare_artifacts_upload fi diff --git a/.ci/scripts/wheel/test_macos.py b/.ci/scripts/wheel/test_macos.py index 5e8db90c863..cd4bce6c136 100644 --- a/.ci/scripts/wheel/test_macos.py +++ b/.ci/scripts/wheel/test_macos.py @@ -14,6 +14,12 @@ test_base.ModelTest( model=Model.Mv3, backend=Backend.XnnpackQuantizationDelegation, - ) + ), + # Enable this once CoreML is suppported out-of-the-box + # https://github.com/pytorch/executorch/issues/9019 + # test_base.ModelTest( + # model=Model.Mv3, + # backend=Backend.CoreMlTest, + # ) ] ) diff --git a/examples/apple/coreml/scripts/build_executor_runner.sh b/examples/apple/coreml/scripts/build_executor_runner.sh index 9d20f289bf6..b4f3a848e45 100755 --- a/examples/apple/coreml/scripts/build_executor_runner.sh +++ b/examples/apple/coreml/scripts/build_executor_runner.sh @@ -78,4 +78,11 @@ XCODE_WORKSPACE_DIR_PATH="$EXAMPLES_COREML_DIR_PATH/executor_runner" XCODE_BUILD_DIR_PATH="$EXAMPLES_COREML_DIR_PATH/xcode-build" xcodebuild build -workspace "$XCODE_WORKSPACE_DIR_PATH/coreml_executor_runner.xcworkspace" -scheme coreml_executor_runner BUILD_DIR="$XCODE_BUILD_DIR_PATH" -cp -f "$XCODE_BUILD_DIR_PATH/DEBUG/coreml_executor_runner" "$PWD" + +if [[ -z "${COREML_EXECUTOR_RUNNER_OUT_DIR:-}" ]]; then + COREML_EXECUTOR_RUNNER_OUT_DIR=$(pwd) +elif [[ ! -d "${COREML_EXECUTOR_RUNNER_OUT_DIR}" ]]; then + mkdir -p "${COREML_EXECUTOR_RUNNER_OUT_DIR}" +fi +cp -f "$XCODE_BUILD_DIR_PATH/DEBUG/coreml_executor_runner" "${COREML_EXECUTOR_RUNNER_OUT_DIR}" +echo "created ${COREML_EXECUTOR_RUNNER_OUT_DIR}/coreml_executor_runner" diff --git a/examples/models/__init__.py b/examples/models/__init__.py index c913d3f02d9..80ba6801a6c 100644 --- a/examples/models/__init__.py +++ b/examples/models/__init__.py @@ -44,6 +44,7 @@ def __str__(self) -> str: class Backend(str, Enum): XnnpackQuantizationDelegation = "xnnpack-quantization-delegation" + CoreMlTest = "coreml-test" def __str__(self) -> str: return self.value