Skip to content

Commit 07bc3e4

Browse files
Guang Yangpytorchbot
authored andcommitted
Cover MPS models in the CI (#6036)
Summary: Pull Request resolved: #6036 Reviewed By: kirklandsign Differential Revision: D64126006 Pulled By: guangy10 fbshipit-source-id: c5aa5a69b9371391f8c300d8f0ee3409ffc76a1f (cherry picked from commit 554eebe)
1 parent dc496bb commit 07bc3e4

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

.ci/scripts/test_model.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ test_model_with_coreml() {
191191
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit)
192192
}
193193

194+
test_model_with_mps() {
195+
"${PYTHON_EXECUTABLE}" -m examples.apple.mps.scripts.mps_example --model_name="${MODEL_NAME}" --use_fp16
196+
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit)
197+
}
198+
194199
if [[ "${BACKEND}" == "portable" ]]; then
195200
echo "Testing ${MODEL_NAME} with portable kernels..."
196201
test_model
@@ -206,6 +211,12 @@ elif [[ "${BACKEND}" == "coreml" ]]; then
206211
if [[ $? -eq 0 ]]; then
207212
prepare_artifacts_upload
208213
fi
214+
elif [[ "${BACKEND}" == "mps" ]]; then
215+
echo "Testing ${MODEL_NAME} with mps..."
216+
test_model_with_mps
217+
if [[ $? -eq 0 ]]; then
218+
prepare_artifacts_upload
219+
fi
209220
elif [[ "${BACKEND}" == "xnnpack" ]]; then
210221
echo "Testing ${MODEL_NAME} with xnnpack..."
211222
WITH_QUANTIZATION=true

.github/workflows/apple-perf.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ jobs:
169169
DELEGATE_CONFIG="xnnpack+custom+qe"
170170
elif [[ ${{ matrix.delegate }} == "coreml" ]]; then
171171
DELEGATE_CONFIG="coreml"
172+
elif [[ ${{ matrix.delegate }} == "mps" ]]; then
173+
DELEGATE_CONFIG="mps"
172174
fi
173175
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
174176
bash .ci/scripts/test_llama.sh "${{ matrix.model }}" "${BUILD_MODE}" "${DTYPE}" "${DELEGATE_CONFIG}" "${ARTIFACTS_DIR_NAME}"

.github/workflows/trunk.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ jobs:
322322
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
323323
PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh ${{ matrix.model }} "cmake" "qnn"
324324
325-
test-coreml-model:
326-
name: test-coreml-model
327-
uses: pytorch/test-infra/.github/workflows/macos_job.yml@release/2.5
325+
test-apple-model:
326+
name: test-apple-model
327+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
328328
strategy:
329329
fail-fast: false
330330
with:
@@ -335,20 +335,25 @@ jobs:
335335
timeout: 90
336336
script: |
337337
BUILD_TOOL=cmake
338-
BACKEND=coreml
339338
340339
bash .ci/scripts/setup-conda.sh
341340
342341
# Setup MacOS dependencies as there is no Docker support on MacOS atm
343342
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
344343
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash backends/apple/coreml/scripts/install_requirements.sh
345344
echo "Finishing installing coreml."
345+
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash backends/apple/mps/install_requirements.sh
346+
echo "Finishing installing mps."
346347
347348
# Build and test coreml model
348349
MODELS=(mv3 ic4 resnet50 edsr mobilebert w2l)
349350
for MODEL_NAME in "${MODELS[@]}"; do
350351
echo "::group::Exporting coreml model: $MODEL_NAME"
351-
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}"
352+
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "coreml"
353+
echo "::endgroup::"
354+
355+
echo "::group::Exporting mps model: $MODEL_NAME"
356+
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "mps"
352357
echo "::endgroup::"
353358
done
354359

examples/apple/mps/scripts/mps_example.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,15 @@ def get_model_config(args):
195195
edge_compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
196196
).to_executorch(config=ExecutorchBackendConfig(extract_delegate_segments=False))
197197

198-
model_name = f"{args.model_name}_mps"
198+
dtype = "float16" if args.use_fp16 else "float32"
199+
model_name = f"{args.model_name}_mps_{dtype}"
199200

200201
if args.bundled:
201202
expected_output = model(*example_inputs)
202203
bundled_program_buffer = get_bundled_program(
203204
executorch_program, example_inputs, expected_output
204205
)
205-
model_name = f"{model_name}_bundled"
206-
extension = "fp16"
207-
if not args.use_fp16:
208-
extension = "fp32"
209-
model_name = f"{model_name}_{extension}.pte"
206+
model_name = f"{model_name}_bundled.pte"
210207

211208
if args.generate_etrecord:
212209
etrecord_path = "etrecord.bin"

0 commit comments

Comments
 (0)