Skip to content

Commit 31fad7a

Browse files
committed
Update tutorial
1 parent 847a4c2 commit 31fad7a

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

docs/source/build-run-coreml.md

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Building and Running ExecuTorch with Core ML Backend
22

3-
Core ML delegate uses Core ML apis to enable running neural networks via Apple's hardware acceleration. For more about coreml you can read [here](https://developer.apple.com/documentation/coreml). In this tutorial we will walk through steps of lowering a PyTorch model to Core ML delegate
3+
Core ML delegate uses Core ML APIs to enable running neural networks via Apple's hardware acceleration. For more about coreml you can read [here](https://developer.apple.com/documentation/coreml). In this tutorial, we will walk through the steps of lowering a PyTorch model to Core ML delegate
44

55

66
::::{grid} 2
@@ -67,22 +67,53 @@ python3 -m examples.apple.coreml.scripts.export --model_name mv3
6767

6868
### Runtime:
6969

70-
**Running the Core ML delegated Program**:
70+
**Running a Core ML delegated Program**:
7171
1. Build the runner.
7272
```bash
7373
cd executorch
7474

75-
# Generates ./coreml_executor_runner.
75+
# Builds `coreml_executor_runner`.
7676
./examples/apple/coreml/scripts/build_executor_runner.sh
7777
```
78-
2. Run the exported program.
78+
2. Run the CoreML delegated program.
7979
```bash
8080
cd executorch
8181

82-
# Runs the exported mv3 model on the Core ML backend.
82+
# Runs the exported mv3 model using the Core ML backend.
8383
./coreml_executor_runner --model_path mv3_coreml_all.pte
8484
```
8585

86+
**Profiling a Core ML delegated Program**:
87+
88+
Profiling is supported on [macOS](https://developer.apple.com/macos) >= 14.4.
89+
90+
1. [Optional] Generate an [ETRecord](./sdk-etrecord.rst) when exporting your model.
91+
```bash
92+
cd executorch
93+
94+
# Generates `mv3_coreml_all.pte` and `mv3_coreml_etrecord.bin` files.
95+
python3 -m examples.apple.coreml.scripts.export --model_name mv3 --generate_etrecord
96+
```
97+
98+
2. Build the runner.
99+
```bash
100+
# Builds `coreml_executor_runner`.
101+
./examples/apple/coreml/scripts/build_executor_runner.sh
102+
```
103+
3. Run and generate an [ETDump](./sdk-etdump.md).
104+
```bash
105+
cd executorch
106+
107+
# Generate the ETDump file.
108+
./coreml_executor_runner --model_path mv3_coreml_all.pte --profile_model --etdump_path etdump.etdp
109+
```
110+
111+
4. Create an instance of the [Inspector API](./sdk-inspector.rst) by passing in the [ETDump](./sdk-etdump.md) you have sourced from the runtime along with the optionally generated [ETRecord](./sdk-etrecord.rst) from step 1 or execute the following command in your terminal to display the profiling data table.
112+
```bash
113+
python examples/apple/coreml/scripts/inspector_cli.py --etdump_path etdump.etdp --etrecord_path mv3_coreml.bin
114+
```
115+
116+
86117
## Deploying and running on a device
87118

88119
**Running the Core ML delegated Program in the Demo iOS App**:
@@ -92,37 +123,35 @@ cd executorch
92123

93124
3. Complete the [Final Steps](demo-apps-ios.md#final-steps) section of the tutorial to build and run the demo app.
94125

95-
<br>**Running the Core ML delegated Program in your own App**
96-
1. Build **Core ML** delegate. The following will create a `executorch.xcframework` in the `cmake-out` directory.
126+
<br>**Running the Core ML delegated Program in your App**
127+
1. Build frameworks, running the following will create a `executorch.xcframework` and `coreml_backend.xcframework` in the `cmake-out` directory.
97128
```bash
98129
cd executorch
99130
./build/build_apple_frameworks.sh --Release --coreml
100131
```
101132
2. Create a new [Xcode project](https://developer.apple.com/documentation/xcode/creating-an-xcode-project-for-an-app#) or open an existing project.
102133

103-
3. Drag the `executorch.xcframework` generated from Step 2 to Frameworks.
134+
3. Drag the `executorch.xcframework` and `coreml_backend.xcframework` generated from Step 2 to Frameworks.
104135

105136
4. Go to the project's [Build Phases](https://developer.apple.com/documentation/xcode/customizing-the-build-phases-of-a-target) - Link Binaries With Libraries, click the + sign, and add the following frameworks:
106137
```
107-
- executorch.xcframework
108-
- coreml_backend.xcframework
109-
- Accelerate.framework
110-
- CoreML.framework
111-
- libsqlite3.tbd
138+
executorch.xcframework
139+
coreml_backend.xcframework
140+
Accelerate.framework
141+
CoreML.framework
142+
libsqlite3.tbd
112143
```
113144
5. Add the exported program to the [Copy Bundle Phase](https://developer.apple.com/documentation/xcode/customizing-the-build-phases-of-a-target#Copy-files-to-the-finished-product) of your Xcode target.
114145

115-
6. Please follow the [running a model](running-a-model-cpp-tutorial.md) tutorial to integrate the code for loading a ExecuTorch program.
146+
6. Please follow the [running a model](./running-a-model-cpp-tutorial.md) tutorial to integrate the code for loading an ExecuTorch program.
116147

117148
7. Update the code to load the program from the Application's bundle.
118149
``` objective-c
119150
using namespace torch::executor;
120151

121152
NSURL *model_url = [NBundle.mainBundle URLForResource:@"mv3_coreml_all" extension:@"pte"];
122153

123-
Result<util::FileDataLoader> loader =
124-
util::FileDataLoader::from(model_url.path.UTF8String);
125-
154+
Result<util::FileDataLoader> loader = util::FileDataLoader::from(model_url.path.UTF8String);
126155
```
127156
128157
8. Use [Xcode](https://developer.apple.com/documentation/xcode/building-and-running-an-app#Build-run-and-debug-your-app) to deploy the application on the device.

0 commit comments

Comments
 (0)