forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ios.sh
More file actions
executable file
·123 lines (95 loc) · 3.4 KB
/
Copy pathtest_ios.sh
File metadata and controls
executable file
·123 lines (95 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# Usage:
# ./test_ios.sh [output]
# Arguments:
# output - The directory where the repository will be cloned and built.
# Default is 'executorch'.
set -e
OUTPUT="${1:-executorch}"
EXIT_STATUS=0
APP_PATH="executorch-examples/mv3/apple/ExecuTorchDemo/ExecuTorchDemo"
MODEL_NAME="mv3"
SIMULATOR_NAME="executorch"
finish() {
EXIT_STATUS=$?
if xcrun simctl list | grep -q "$SIMULATOR_NAME"; then
say "Deleting Simulator"
xcrun simctl delete "$SIMULATOR_NAME"
fi
if [ -d "$OUTPUT" ]; then
popd > /dev/null
say "Deleting Output Directory"
rm -rf "$OUTPUT"
fi
if [ $EXIT_STATUS -eq 0 ]; then
say "SUCCEEDED"
else
say "FAILED"
fi
exit $EXIT_STATUS
}
trap finish EXIT
say() {
echo -e "\033[1m\n\t** $1 **\n\033[0m"
}
say "Activating a Virtual Environment"
python3 -m venv .venv && source .venv/bin/activate && pip install --upgrade pip
say "Installing Requirements"
./install_executorch.sh
say "Cloning the Demo App"
git clone --depth 1 https://github.com/meta-pytorch/executorch-examples.git
say "Installing CoreML Backend Requirements"
./backends/apple/coreml/scripts/install_requirements.sh
say "Exporting Models"
python3 -m examples.portable.scripts.export --model_name="$MODEL_NAME"
python3 -m examples.apple.coreml.scripts.export --model_name="$MODEL_NAME"
python3 -m examples.xnnpack.aot_compiler --model_name="$MODEL_NAME" --delegate
# No generic examples/ entry point takes a model name and lowers it to MLX, so do
# it here. Assert MLX claimed the graph before writing: the partitioner only warns
# when it delegates nothing. This needs the MLX backend built, which the installer
# does only on Apple Silicon with the Metal compiler present.
python3 - "$MODEL_NAME" <<'PY'
import sys
import torch
from executorch.backends.mlx import MLXPartitioner
from executorch.examples.models import MODEL_NAME_TO_MODEL
from executorch.examples.models.model_factory import EagerModelFactory
from executorch.exir import EdgeCompileConfig, to_edge_transform_and_lower
model_name = sys.argv[1]
model, example_inputs, _, _ = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL[model_name]
)
program = to_edge_transform_and_lower(
torch.export.export(model.eval(), example_inputs),
partitioner=[MLXPartitioner()],
compile_config=EdgeCompileConfig(_skip_dim_order=True),
).to_executorch()
segments = sum(
delegate.id == "MLXBackend"
for plan in program.executorch_program.execution_plan
for delegate in plan.delegates
)
if segments == 0:
raise SystemExit(f"error: {model_name} produced no MLX delegate")
path = f"{model_name}_mlx.pte"
with open(path, "wb") as file:
program.write_to_file(file)
print(f"{path}: {segments} MLX delegate segment(s)")
PY
mkdir -p "$APP_PATH/Resources/Models/MobileNet/"
mv $MODEL_NAME*.pte "$APP_PATH/Resources/Models/MobileNet/"
say "Downloading Labels"
curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt \
-o "$APP_PATH/Resources/Models/MobileNet/imagenet_classes.txt"
say "Creating Simulator"
xcrun simctl create "$SIMULATOR_NAME" "iPhone 15"
say "Running Tests"
xcodebuild test \
-project "$APP_PATH.xcodeproj" \
-scheme MobileNetClassifierTest \
-destination name="$SIMULATOR_NAME"