You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This subtree contains the Core ML Delegate implementation for ExecuTorch.
5
-
Core ML is an optimized framework for running machine learning models on Apple devices. The delegate is the mechanism for leveraging the Core ML framework to accelerate operators when running on Apple devices.
4
+
Core ML is an optimized framework for running machine learning models on Apple devices. The delegate is the mechanism for leveraging the Core ML framework to accelerate operators when running on Apple devices. To learn how to use the CoreML delegate, see the [documentation](https://github.com/pytorch/executorch/blob/main/docs/source/backends-coreml.md).
6
5
7
6
## Layout
8
7
-`compiler/` : Lowers a module to Core ML backend.
@@ -19,110 +18,6 @@ Core ML is an optimized framework for running machine learning models on Apple d
19
18
-`workspace` : Xcode workspace for the runtime.
20
19
-`third-party/`: External dependencies.
21
20
22
-
## Partition and Delegation
23
-
24
-
To delegate a Program to the **Core ML** backend, the client must call `to_backend` with the **CoreMLPartitioner**.
25
-
26
-
```python
27
-
import torch
28
-
import executorch.exir
29
-
30
-
from executorch.backends.apple.coreml.compiler import CoreMLBackend
31
-
from executorch.backends.apple.coreml.partition import CoreMLPartitioner
32
-
33
-
classModel(torch.nn.Module):
34
-
def__init__(self):
35
-
super().__init__()
36
-
37
-
defforward(self, x):
38
-
return torch.sin(x)
39
-
40
-
source_model = Model()
41
-
example_inputs = (torch.ones(1), )
42
-
43
-
# Export the source model to Edge IR representation
The module will be fully or partially delegated to **Core ML**, depending on whether all or part of ops are supported by the **Core ML** backend. User may force skip certain ops by `CoreMLPartitioner(skip_ops_for_coreml_delegation=...)`
57
-
58
-
The `to_backend` implementation is a thin wrapper over [coremltools](https://apple.github.io/coremltools/docs-guides/), `coremltools` is responsible for converting an **ExportedProgram** to a **MLModel**. The converted **MLModel** data is saved, flattened, and returned as bytes to **ExecuTorch**.
59
-
60
-
## Quantization
61
-
62
-
To quantize a Program in a Core ML favored way, the client may utilize **CoreMLQuantizer**.
63
-
64
-
```python
65
-
import torch
66
-
import executorch.exir
67
-
68
-
from torch.export import export_for_training
69
-
from torch.ao.quantization.quantize_pt2e import (
70
-
convert_pt2e,
71
-
prepare_pt2e,
72
-
prepare_qat_pt2e,
73
-
)
74
-
75
-
from executorch.backends.apple.coreml.quantizer import CoreMLQuantizer
76
-
from coremltools.optimize.torch.quantization.quantization_config import (
The `converted_graph` is the quantized torch model, and can be delegated to **Core ML** similarly through **CoreMLPartitioner**
119
-
120
-
## Runtime
121
-
122
-
To execute a Core ML delegated program, the application must link to the `coremldelegate` library. Once linked there are no additional steps required, ExecuTorch when running the program would call the Core ML runtime to execute the Core ML delegated part of the program.
123
-
124
-
Please follow the instructions described in the [Core ML setup](/backends/apple/coreml/setup.md) to link the `coremldelegate` library.
125
-
126
21
## Help & Improvements
127
22
If you have problems or questions or have suggestions for ways to make
128
23
implementation and testing better, please create an issue on [github](https://www.github.com/pytorch/executorch/issues).
0 commit comments