Convert ONNX models to Apple Core ML — .mlpackage (ML Program) and .mlmodel (NeuralNetwork) — built on coremltools' MIL builder, with numerical-parity verification.
Project description
onnx2coreml
Convert ONNX models to Apple Core ML — .mlpackage (ML Program / MIL, primary) and
.mlmodel (NeuralNetwork, secondary) — built on coremltools' MIL builder, with
numerical-parity verification against ONNX Runtime.
- ML Program first for modern on-device performance (fp16 and Apple Neural Engine), with full NeuralNetwork support for older-OS reach.
- Maintainable as Core ML evolves: all coremltools coupling is isolated behind two facades, so spec/format changes touch two files, not the operator lowerings.
- Verified, not assumed: every operator has numerical-parity tests run against the live Core ML runtime on macOS.
Status: v1.0.0. Design:
docs/specs/.
Install
uv pip install -e ".[dev,verify,test]" # development
# or, once published: uv pip install onnx2coreml
Requires Python 3.11–3.13 and macOS for prediction/verification (model building works anywhere coremltools installs).
Quickstart
import onnx2coreml as o2c
# ML Program (.mlpackage) — the default, fp16, iOS17+
mlmodel = o2c.convert("model.onnx", format="mlpackage", minimum_deployment_target="iOS17")
mlmodel.save("model.mlpackage")
# NeuralNetwork (.mlmodel)
o2c.convert("model.onnx", format="mlmodel").save("model.mlmodel")
# Check coverage before converting
report = o2c.analyze("model.onnx")
print(report.convertible, report.unsupported)
# Numerical parity vs ONNX Runtime
print(o2c.verify("model.onnx", "model.mlpackage"))
convert() returns a coremltools MLModel. Options: format,
minimum_deployment_target, compute_precision (fp16/fp32), compute_units,
fuse, verify.
CLI
onnx2coreml convert model.onnx -o model.mlpackage --format mlpackage --verify
onnx2coreml inspect model.onnx # op histogram + per-format convertibility
onnx2coreml verify model.onnx model.mlpackage
onnx2coreml schema # version, supported op count, error codes
All subcommands accept --json.
Supported operators (105 ops)
| Family | Operators |
|---|---|
| Elementwise / math | Add, Sub, Mul, Div, Pow, Sqrt, Exp, Log, Abs, Erf, Reciprocal, Neg, Floor, Ceil, Round, Sign, Sin, Cos, Tan, Asin, Acos, Atan, Sinh, Cosh, Atanh, Min, Max, Clip, Mod, Equal, Greater, Less, GreaterOrEqual, LessOrEqual, And, Or, Xor, Not, IsNaN, Where |
| Activations | Relu, LeakyRelu, PRelu, Sigmoid, Tanh, Gelu, Softmax, LogSoftmax, Softplus, Elu, HardSigmoid, HardSwish |
| Convolution / pooling | Conv, ConvTranspose, MaxPool, AveragePool, GlobalAveragePool, GlobalMaxPool |
| Normalization | BatchNormalization, LayerNormalization, InstanceNormalization, GroupNormalization |
| Linear | MatMul, Gemm, Inverse (com.microsoft) |
| Shape / movement | Reshape, Transpose, Flatten, Squeeze, Unsqueeze, Concat, Split, Pad, Cast, Identity, DepthToSpace, GridSample, Resize, Upsample |
| Indexing / gather-scatter | Gather, GatherND, GatherElements, ScatterND, ScatterElements, NonZero, Slice, Expand, Tile, Shape, ConstantOfShape |
| Reduction | ReduceMean, ReduceSum, ReduceMax, ReduceMin, ReduceProd, ReduceL1, ReduceL2, ReduceLogSum, ReduceLogSumExp, ReduceSumSquare, ArgMax, ArgMin, TopK |
| Recurrent | LSTM |
| Attention | ScaledDotProductAttention (produced by the attention fusion pass) |
onnx2coreml inspect <model> reports exactly which ops a given model needs and whether
each is covered. Unsupported ops raise a single aggregated UnsupportedOpError; register
a custom lowering with Converter().register("OpType") as an escape hatch.
How it works
ONNX → load → passes (opset/shape/fold/cleanup) → fusion (attention→SDPA) →
coverage-gate → lower to MIL (mb.*) → coremltools backend → .mlpackage / .mlmodel → verify
See docs/specs/2026-06-15-onnx2coreml-design.md for the full design and AGENTS.md for
the developer guide.
Known limitations (v1.0.0)
- Fixed input shapes.
- A full all-axes reduction with
keepdims=0yields shape(1,)(Core ML has no rank-0 scalar). - Resize
linear+half_pixelvia explicit sizes is.mlpackage-only (the NeuralNetwork backend lacks the sampling mode); the scales path covers it on both formats.
License
BSD-3-Clause.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file onnx2coreml-1.0.0.tar.gz.
File metadata
- Download URL: onnx2coreml-1.0.0.tar.gz
- Upload date:
- Size: 70.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5567dc0a12ff9cfbcbe6637101522cfdc2f85036f333501b4875ecab601ad128
|
|
| MD5 |
8879c926ddfde693b7778a1c85ed5555
|
|
| BLAKE2b-256 |
5678cbe0dc1e3f8018fb73f841aa75199d958c3d767d632662a913a8dc9abe56
|
Provenance
The following attestation bundles were made for onnx2coreml-1.0.0.tar.gz:
Publisher:
publish.yml on devin-lai/onnx2coreml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onnx2coreml-1.0.0.tar.gz -
Subject digest:
5567dc0a12ff9cfbcbe6637101522cfdc2f85036f333501b4875ecab601ad128 - Sigstore transparency entry: 1824717387
- Sigstore integration time:
-
Permalink:
devin-lai/onnx2coreml@49e02736e7c34bbd2fb98097eb703b8bc7b8acaf -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/devin-lai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@49e02736e7c34bbd2fb98097eb703b8bc7b8acaf -
Trigger Event:
push
-
Statement type:
File details
Details for the file onnx2coreml-1.0.0-py3-none-any.whl.
File metadata
- Download URL: onnx2coreml-1.0.0-py3-none-any.whl
- Upload date:
- Size: 66.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30a77ccb5fd0a588e7edf9e0976406bd7fe18333ce8d3d977189ff4258329400
|
|
| MD5 |
ab0197c79c0b34940faaec8d11335e64
|
|
| BLAKE2b-256 |
9662d25c3ff113af1596ab935dbc66e318ca1213be07c4f55651db8349012c05
|
Provenance
The following attestation bundles were made for onnx2coreml-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on devin-lai/onnx2coreml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onnx2coreml-1.0.0-py3-none-any.whl -
Subject digest:
30a77ccb5fd0a588e7edf9e0976406bd7fe18333ce8d3d977189ff4258329400 - Sigstore transparency entry: 1824717778
- Sigstore integration time:
-
Permalink:
devin-lai/onnx2coreml@49e02736e7c34bbd2fb98097eb703b8bc7b8acaf -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/devin-lai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@49e02736e7c34bbd2fb98097eb703b8bc7b8acaf -
Trigger Event:
push
-
Statement type: