Skip to content

Commit a5a7287

Browse files
author
Guang Yang
committed
Cover MPS models in the CI
1 parent 0d1250a commit a5a7287

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ jobs:
312312
PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh ${{ matrix.model }} "cmake" "qnn"
313313
314314
test-coreml-model:
315-
name: test-coreml-model
315+
name: test-coreml-and-mps-model
316316
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
317317
strategy:
318318
fail-fast: false
@@ -324,20 +324,25 @@ jobs:
324324
timeout: 90
325325
script: |
326326
BUILD_TOOL=cmake
327-
BACKEND=coreml
328327
329328
bash .ci/scripts/setup-conda.sh
330329
331330
# Setup MacOS dependencies as there is no Docker support on MacOS atm
332331
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
333332
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash backends/apple/coreml/scripts/install_requirements.sh
334333
echo "Finishing installing coreml."
334+
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash backends/apple/mps/install_requirements.sh
335+
echo "Finishing installing mps."
335336
336337
# Build and test coreml model
337-
MODELS=(mv3 ic4 resnet50 edsr mobilebert w2l)
338+
MODELS=(mv3 ic4 resnet50 edsr mobilebert w2l vit)
338339
for MODEL_NAME in "${MODELS[@]}"; do
339340
echo "::group::Exporting coreml model: $MODEL_NAME"
340-
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}"
341+
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "coreml"
342+
echo "::endgroup::"
343+
344+
echo "::group::Exporting mps model: $MODEL_NAME"
345+
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "mps"
341346
echo "::endgroup::"
342347
done
343348

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 = "fp16" if args.use_fp16 else "fp32"
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)