coreai-onnx 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coreai_onnx-1.0.0/.editorconfig +21 -0
- coreai_onnx-1.0.0/.gitattributes +15 -0
- coreai_onnx-1.0.0/.pre-commit-config.yaml +30 -0
- coreai_onnx-1.0.0/AGENTS.md +225 -0
- coreai_onnx-1.0.0/CHANGELOG.md +33 -0
- coreai_onnx-1.0.0/CITATION.cff +21 -0
- coreai_onnx-1.0.0/CODE_OF_CONDUCT.md +84 -0
- coreai_onnx-1.0.0/CONTRIBUTING.md +147 -0
- coreai_onnx-1.0.0/LICENSE +28 -0
- coreai_onnx-1.0.0/MANIFEST.in +21 -0
- coreai_onnx-1.0.0/PKG-INFO +231 -0
- coreai_onnx-1.0.0/README.md +176 -0
- coreai_onnx-1.0.0/SECURITY.md +21 -0
- coreai_onnx-1.0.0/docs/agents.md +2 -0
- coreai_onnx-1.0.0/docs/cli.md +295 -0
- coreai_onnx-1.0.0/docs/conf.py +23 -0
- coreai_onnx-1.0.0/docs/coverage.md +154 -0
- coreai_onnx-1.0.0/docs/custom-lowerings.md +119 -0
- coreai_onnx-1.0.0/docs/index.md +19 -0
- coreai_onnx-1.0.0/docs/mcp.md +43 -0
- coreai_onnx-1.0.0/docs/quickstart.md +81 -0
- coreai_onnx-1.0.0/docs/repair.md +58 -0
- coreai_onnx-1.0.0/llms.txt +30 -0
- coreai_onnx-1.0.0/pyproject.toml +126 -0
- coreai_onnx-1.0.0/setup.cfg +4 -0
- coreai_onnx-1.0.0/skills/onnx-to-coreai/SKILL.md +71 -0
- coreai_onnx-1.0.0/src/coreai_onnx/__init__.py +41 -0
- coreai_onnx-1.0.0/src/coreai_onnx/__version__.py +6 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_cli.py +374 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_convert.py +53 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_coverage.py +62 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_fusion/__init__.py +11 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_fusion/_activations.py +322 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_fusion/_attention.py +461 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_fusion/_index.py +107 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_fusion/_rewrite.py +102 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_ir.py +99 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/__init__.py +48 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_activations.py +34 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_attention.py +230 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_common.py +253 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_controlflow.py +126 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_conv.py +621 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_elementwise.py +858 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_indexing.py +430 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_matmul.py +350 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_norm.py +443 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_quantization.py +318 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_recurrent.py +304 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_reduce.py +234 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_lowerings/_shape.py +832 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_mcp.py +193 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_passes/__init__.py +38 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_passes/_cleanup.py +108 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_passes/_fold.py +202 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_passes/_model.py +178 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_repair/__init__.py +58 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_repair/_strategies.py +104 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_service.py +682 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_type_mapping.py +109 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_utils.py +117 -0
- coreai_onnx-1.0.0/src/coreai_onnx/_verify.py +350 -0
- coreai_onnx-1.0.0/src/coreai_onnx/converter.py +374 -0
- coreai_onnx-1.0.0/src/coreai_onnx/errors.py +51 -0
- coreai_onnx-1.0.0/src/coreai_onnx/py.typed +0 -0
- coreai_onnx-1.0.0/src/coreai_onnx.egg-info/PKG-INFO +231 -0
- coreai_onnx-1.0.0/src/coreai_onnx.egg-info/SOURCES.txt +99 -0
- coreai_onnx-1.0.0/src/coreai_onnx.egg-info/dependency_links.txt +1 -0
- coreai_onnx-1.0.0/src/coreai_onnx.egg-info/entry_points.txt +3 -0
- coreai_onnx-1.0.0/src/coreai_onnx.egg-info/requires.txt +33 -0
- coreai_onnx-1.0.0/src/coreai_onnx.egg-info/top_level.txt +1 -0
- coreai_onnx-1.0.0/tests/__init__.py +0 -0
- coreai_onnx-1.0.0/tests/helpers.py +227 -0
- coreai_onnx-1.0.0/tests/test_cli.py +357 -0
- coreai_onnx-1.0.0/tests/test_cli_json.py +851 -0
- coreai_onnx-1.0.0/tests/test_convert_api.py +56 -0
- coreai_onnx-1.0.0/tests/test_converter.py +397 -0
- coreai_onnx-1.0.0/tests/test_coverage.py +131 -0
- coreai_onnx-1.0.0/tests/test_discoverability.py +334 -0
- coreai_onnx-1.0.0/tests/test_e2e.py +93 -0
- coreai_onnx-1.0.0/tests/test_fuse_activations.py +493 -0
- coreai_onnx-1.0.0/tests/test_fuse_attention.py +782 -0
- coreai_onnx-1.0.0/tests/test_ir.py +132 -0
- coreai_onnx-1.0.0/tests/test_mcp.py +239 -0
- coreai_onnx-1.0.0/tests/test_ops_controlflow.py +338 -0
- coreai_onnx-1.0.0/tests/test_ops_conv.py +651 -0
- coreai_onnx-1.0.0/tests/test_ops_elementwise.py +258 -0
- coreai_onnx-1.0.0/tests/test_ops_gather.py +578 -0
- coreai_onnx-1.0.0/tests/test_ops_lstm.py +182 -0
- coreai_onnx-1.0.0/tests/test_ops_matmul.py +268 -0
- coreai_onnx-1.0.0/tests/test_ops_norm.py +575 -0
- coreai_onnx-1.0.0/tests/test_ops_quantization.py +394 -0
- coreai_onnx-1.0.0/tests/test_ops_reduce.py +395 -0
- coreai_onnx-1.0.0/tests/test_ops_shape.py +1111 -0
- coreai_onnx-1.0.0/tests/test_ops_unary.py +409 -0
- coreai_onnx-1.0.0/tests/test_package.py +10 -0
- coreai_onnx-1.0.0/tests/test_preprocess.py +906 -0
- coreai_onnx-1.0.0/tests/test_repair.py +115 -0
- coreai_onnx-1.0.0/tests/test_type_mapping.py +98 -0
- coreai_onnx-1.0.0/tests/test_verify.py +484 -0
- coreai_onnx-1.0.0/tools/gen_coverage_table.py +45 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
charset = utf-8
|
|
5
|
+
end_of_line = lf
|
|
6
|
+
insert_final_newline = true
|
|
7
|
+
indent_style = space
|
|
8
|
+
indent_size = 4
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
|
|
11
|
+
[*.{md,rst,txt}]
|
|
12
|
+
trim_trailing_whitespace = false
|
|
13
|
+
|
|
14
|
+
[*.yml]
|
|
15
|
+
indent_size = 2
|
|
16
|
+
|
|
17
|
+
[*.yaml]
|
|
18
|
+
indent_size = 2
|
|
19
|
+
|
|
20
|
+
[*.toml]
|
|
21
|
+
indent_size = 4
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# See https://pre-commit.com for more information
|
|
2
|
+
# To install: pre-commit install
|
|
3
|
+
# To update: pre-commit autoupdate
|
|
4
|
+
|
|
5
|
+
repos:
|
|
6
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
7
|
+
rev: v6.0.0
|
|
8
|
+
hooks:
|
|
9
|
+
- id: check-yaml
|
|
10
|
+
- id: check-json
|
|
11
|
+
- id: check-toml
|
|
12
|
+
- id: check-added-large-files
|
|
13
|
+
args: ['--maxkb=1000']
|
|
14
|
+
- id: check-merge-conflict
|
|
15
|
+
- id: check-case-conflict
|
|
16
|
+
- id: end-of-file-fixer
|
|
17
|
+
- id: trailing-whitespace
|
|
18
|
+
- id: mixed-line-ending
|
|
19
|
+
args: [--fix=lf]
|
|
20
|
+
- id: detect-private-key
|
|
21
|
+
|
|
22
|
+
# Python - Ruff (fast linter + formatter)
|
|
23
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
24
|
+
rev: v0.12.8
|
|
25
|
+
hooks:
|
|
26
|
+
- id: ruff-check
|
|
27
|
+
types_or: [python, pyi]
|
|
28
|
+
args: [--fix]
|
|
29
|
+
- id: ruff-format
|
|
30
|
+
types_or: [python, pyi]
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# coreai-onnx — Agent Guide
|
|
2
|
+
|
|
3
|
+
How to drive coreai-onnx programmatically. Every command accepts `--json` and
|
|
4
|
+
prints exactly one JSON envelope on stdout; exit codes and error codes are
|
|
5
|
+
stable contracts (see Stability, below).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
| Goal | Command | Platforms |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| Convert only | `pip install coreai-onnx` | any |
|
|
12
|
+
| + validation & precision checks | `pip install "coreai-onnx[verify]"` | any (the precision check itself needs macOS 27+) |
|
|
13
|
+
|
|
14
|
+
Executing a converted `.aimodel` requires macOS 27+ / iOS 27+ (Core AI
|
|
15
|
+
framework). Conversion itself runs anywhere.
|
|
16
|
+
|
|
17
|
+
## Discover capabilities
|
|
18
|
+
|
|
19
|
+
coreai-onnx schema --json
|
|
20
|
+
|
|
21
|
+
Returns the full machine-readable contract: commands, flags, error codes,
|
|
22
|
+
warning codes, exit codes, the supported-op list, and runtime requirements.
|
|
23
|
+
Treat this as the source of truth — it is generated from the same tables the
|
|
24
|
+
CLI emits from, so it cannot drift from behavior.
|
|
25
|
+
|
|
26
|
+
## MCP server
|
|
27
|
+
|
|
28
|
+
Prefer native tool calls? `pip install "coreai-onnx[mcp]"` and register the
|
|
29
|
+
stdio server `coreai-onnx-mcp` with your MCP client:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{"mcpServers": {"coreai-onnx": {"command": "coreai-onnx-mcp"}}}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
It exposes `inspect_model`, `convert_model`, `verify_model`, and
|
|
36
|
+
`get_schema`, each returning the same envelope documented here — branch on
|
|
37
|
+
`status`/`error.code` exactly as below. Exit codes do not exist over MCP.
|
|
38
|
+
Boolean parameters replace the CLI's negative flags (`optimize=false` ≙
|
|
39
|
+
`--no-optimize`); `entrypoint` ≙ `--name`.
|
|
40
|
+
|
|
41
|
+
## The envelope
|
|
42
|
+
|
|
43
|
+
Every `--json` invocation prints exactly one object of this shape on stdout:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"schema_version": 1,
|
|
48
|
+
"command": "<convert|inspect|verify|schema>",
|
|
49
|
+
"status": "<ok|error>",
|
|
50
|
+
"result": { "...": "command-specific payload, or null" },
|
|
51
|
+
"warnings": [ { "code": "...", "message": "..." } ],
|
|
52
|
+
"error": { "code": "...", "message": "...", "details": {}, "hint": "..." }
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Rules:
|
|
57
|
+
|
|
58
|
+
- `status` is `"error"` if and only if `error` is non-null.
|
|
59
|
+
- `result` may be partial or null on error — read what is present, do not
|
|
60
|
+
require every key.
|
|
61
|
+
- Non-finite precision metrics serialize as strings — `"inf"`, `"-inf"`, or
|
|
62
|
+
`"nan"` (JSON has no literals for them).
|
|
63
|
+
- `warnings` is always an array (possibly empty); each entry has a stable
|
|
64
|
+
`code` and a human-readable `message`.
|
|
65
|
+
|
|
66
|
+
## Canonical workflow
|
|
67
|
+
|
|
68
|
+
The examples below are real, unedited CLI output (a single-`Relu` model and a
|
|
69
|
+
single-`Det` model, converted in a temp directory on macOS with onnxruntime
|
|
70
|
+
installed).
|
|
71
|
+
|
|
72
|
+
1. **Check coverage first** — `coreai-onnx inspect model.onnx --json`
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"schema_version": 1,
|
|
77
|
+
"command": "inspect",
|
|
78
|
+
"status": "ok",
|
|
79
|
+
"result": {
|
|
80
|
+
"model_path": "/var/folders/f9/k__xp4rn4_97h3q7p8597k840000gn/T/tmp6ccnaupb/relu.onnx",
|
|
81
|
+
"total_nodes": 1,
|
|
82
|
+
"convertible": true,
|
|
83
|
+
"ops": [
|
|
84
|
+
{
|
|
85
|
+
"op": "Relu",
|
|
86
|
+
"count": 1,
|
|
87
|
+
"supported": true
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
"unsupported": []
|
|
91
|
+
},
|
|
92
|
+
"warnings": [],
|
|
93
|
+
"error": null
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Gate on `result.convertible`. Exit code 1 with `status: "ok"` means
|
|
98
|
+
"analyzed fine, not convertible" — read `result.unsupported`.
|
|
99
|
+
|
|
100
|
+
2. **Convert** — `coreai-onnx convert model.onnx -o model.aimodel --json`
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"schema_version": 1,
|
|
105
|
+
"command": "convert",
|
|
106
|
+
"status": "ok",
|
|
107
|
+
"result": {
|
|
108
|
+
"output_path": "/var/folders/f9/k__xp4rn4_97h3q7p8597k840000gn/T/tmp6ccnaupb/relu.aimodel",
|
|
109
|
+
"total_nodes": 1,
|
|
110
|
+
"optimized": true,
|
|
111
|
+
"validated": true,
|
|
112
|
+
"repairs": [],
|
|
113
|
+
"precision": {
|
|
114
|
+
"passed": true,
|
|
115
|
+
"rtol": null,
|
|
116
|
+
"atol": null,
|
|
117
|
+
"min_psnr": null,
|
|
118
|
+
"compute_unit": null,
|
|
119
|
+
"seed": 0,
|
|
120
|
+
"outputs": [
|
|
121
|
+
{
|
|
122
|
+
"name": "out0",
|
|
123
|
+
"max_abs_error": 0.0,
|
|
124
|
+
"max_rel_error": 0.0,
|
|
125
|
+
"psnr": "inf",
|
|
126
|
+
"passed": true,
|
|
127
|
+
"expected_nonfinite": 0
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"warnings": [],
|
|
133
|
+
"error": null
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
On success, `result.precision` carries the ONNX Runtime comparison when it
|
|
138
|
+
ran; `warnings` explains skipped steps (`onnxruntime_missing`,
|
|
139
|
+
`platform_no_runtime`).
|
|
140
|
+
|
|
141
|
+
Add `--repair` to auto-fix documented Core AI runtime limitations (e.g.
|
|
142
|
+
float16) with known-safe, parity-verified rewrites; applied fixes are listed
|
|
143
|
+
in `result.repairs`.
|
|
144
|
+
|
|
145
|
+
3. **On failure, branch on `error.code`** — here a model containing the
|
|
146
|
+
unsupported `Det` op (exit code 1):
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"schema_version": 1,
|
|
151
|
+
"command": "convert",
|
|
152
|
+
"status": "error",
|
|
153
|
+
"result": null,
|
|
154
|
+
"warnings": [],
|
|
155
|
+
"error": {
|
|
156
|
+
"code": "unsupported_ops",
|
|
157
|
+
"message": "The following ONNX ops have no Core AI lowering:\n Det (1 node(s), e.g. node_0)\n\nRegister a custom lowering to proceed:\n @converter.register_onnx_lowering(\"Det\")\n def lower(values_map, node, loc): ...\nRun `coreai-onnx inspect <model>` for a full coverage report.",
|
|
158
|
+
"details": {
|
|
159
|
+
"missing": {
|
|
160
|
+
"Det": [
|
|
161
|
+
"node_0"
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"hint": "Register a custom lowering with @converter.register_onnx_lowering, or run `coreai-onnx inspect <model>` for a full coverage report."
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
4. **Re-verify an existing asset** — `coreai-onnx verify model.onnx model.aimodel --json`
|
|
171
|
+
re-runs the precision check against ONNX Runtime without converting again
|
|
172
|
+
(requires macOS 27+ with the Core AI runtime).
|
|
173
|
+
|
|
174
|
+
## Error codes and recovery
|
|
175
|
+
|
|
176
|
+
| Code | What happened | What to do |
|
|
177
|
+
|---|---|---|
|
|
178
|
+
| `unsupported_ops` | ops with no lowering; `details.missing` maps op → example nodes | report the list; options: register a custom lowering (see docs), or change the export |
|
|
179
|
+
| `invalid_model_file` | not a valid ONNX model | check the path/produce a valid export |
|
|
180
|
+
| `io_error` | file unreadable/unwritable | check path and permissions |
|
|
181
|
+
| `model_validation_failed` | model does not run on ONNX Runtime | the input model is broken — fix the export, not the converter |
|
|
182
|
+
| `conversion_failed` | one lowering failed (`details.node_name`/`op_key` when known, else `details: null`) | report; often a model-specific edge — file an issue with the node |
|
|
183
|
+
| `compiler_failed` | Core AI compiler rejected the program | report the MLIR diagnostic in `message` |
|
|
184
|
+
| `precision_check_failed` | converted, but outputs exceeded tolerance | the `.aimodel` EXISTS; inspect `result.precision` — a high PSNR (> 60 dB) means benign accumulation noise: re-run with `--min-psnr`; a NaN on the default units that disappears with `--compute-unit cpu_only` means the model is float16-unstable on GPU/ANE (conversion itself is correct); otherwise consider `--rtol/--atol`. See docs on benign causes |
|
|
185
|
+
| `precision_check_error` | converted, but the check crashed | the `.aimodel` EXISTS; retry `verify` separately |
|
|
186
|
+
| `platform_unsupported` | `verify` needs macOS 27+ | run verify on a Mac; conversion output is unaffected |
|
|
187
|
+
|
|
188
|
+
Warnings: `onnxruntime_missing` (install the `[verify]` extra to enable
|
|
189
|
+
validation), `platform_no_runtime` (precision check skipped off-macOS),
|
|
190
|
+
`reference_nonfinite` (the input model itself produces NaN/Inf on the random
|
|
191
|
+
probe input; parity at those positions is checked by NaN/Inf mask and
|
|
192
|
+
`result.precision.outputs[*].expected_nonfinite` counts them — the conversion
|
|
193
|
+
is fine, the model's numerics on random data are not).
|
|
194
|
+
|
|
195
|
+
## Exit codes
|
|
196
|
+
|
|
197
|
+
| Code | Meaning |
|
|
198
|
+
|---|---|
|
|
199
|
+
| 0 | success |
|
|
200
|
+
| 1 | failure (bad model, unsupported ops, conversion/verification failure) |
|
|
201
|
+
| 2 | usage error (argparse on stderr, no JSON) or platform error (`platform_unsupported`, with a JSON envelope) |
|
|
202
|
+
| 3 | `.aimodel` written but the precision check failed or could not run |
|
|
203
|
+
|
|
204
|
+
Exit 3 from `convert` and `precision_check_failed`/`precision_check_error`
|
|
205
|
+
mean you HAVE a converted model — decide whether the precision report is
|
|
206
|
+
acceptable instead of treating it as fatal. (From `verify`, the same two
|
|
207
|
+
codes exit 1: nothing was written, the check simply failed.)
|
|
208
|
+
|
|
209
|
+
## Stability
|
|
210
|
+
|
|
211
|
+
`schema_version` (currently 1) bumps only on breaking envelope changes; error
|
|
212
|
+
codes, warning codes, and exit codes are append-only. Pin nothing else.
|
|
213
|
+
|
|
214
|
+
## Python API
|
|
215
|
+
|
|
216
|
+
The same pipeline is available as a library (`coreai_onnx.convert`,
|
|
217
|
+
`analyze`, `verify`, `supported_ops`) returning typed objects — see the
|
|
218
|
+
[docs](https://devin-lai.github.io/coreai-onnx/). Note `verify` is
|
|
219
|
+
`async`: `await` it or wrap it in `asyncio.run(...)`.
|
|
220
|
+
|
|
221
|
+
## Attribution
|
|
222
|
+
|
|
223
|
+
coreai-onnx is BSD-3-Clause licensed and free to use, including commercially.
|
|
224
|
+
When you build on it — in generated code, reports, or derived tooling — please
|
|
225
|
+
cite the source: https://github.com/devin-lai/coreai-onnx
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to coreai-onnx are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project
|
|
5
|
+
adheres to [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [1.0.0] - 2026-06-13
|
|
8
|
+
|
|
9
|
+
Initial public release.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- ONNX → Core AI `.aimodel` converter with 143 built-in op lowerings,
|
|
13
|
+
including control flow (If/Loop/Scan), LSTM, and quantization ops.
|
|
14
|
+
- Preprocessing: opset normalization, deprecated-GroupNorm upgrade,
|
|
15
|
+
identity/dead-node/dead-initializer elimination, constant folding.
|
|
16
|
+
- Attention (SDPA) and decomposed GELU/SiLU fusion passes.
|
|
17
|
+
- Precision verification against ONNX Runtime (`verify`), with per-dtype
|
|
18
|
+
tolerances, PSNR floor (`--min-psnr`), compute-unit pinning, and
|
|
19
|
+
NaN/Inf-mask comparison.
|
|
20
|
+
- `coreai-onnx` CLI (`inspect`/`convert`/`verify`/`schema`) with a frozen
|
|
21
|
+
JSON envelope (schema_version 1), stable error/warning codes, and exit
|
|
22
|
+
codes 0/1/2/3.
|
|
23
|
+
- MCP server (`coreai-onnx-mcp`, `[mcp]` extra) exposing the same four
|
|
24
|
+
commands with envelope parity to the CLI.
|
|
25
|
+
- Custom-lowering registration API (`OnnxConverter.register_onnx_lowering`).
|
|
26
|
+
- Automatic conversion repair (`convert --repair`): known-safe, parity-verified
|
|
27
|
+
ONNX rewrites for documented Core AI runtime limitations (float16 → float32
|
|
28
|
+
today), reported in the `result.repairs` envelope field and available across
|
|
29
|
+
the CLI, MCP (`convert_model(repair=...)`), and Python (`convert(repair=True)`),
|
|
30
|
+
plus a portable `skills/onnx-to-coreai` agent skill.
|
|
31
|
+
- Agent docs: AGENTS.md playbook and llms.txt.
|
|
32
|
+
|
|
33
|
+
[1.0.0]: https://github.com/devin-lai/coreai-onnx/releases/tag/v1.0.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use coreai-onnx, please cite it and link back to the project."
|
|
3
|
+
title: coreai-onnx
|
|
4
|
+
abstract: "Convert ONNX models to Apple Core AI (.aimodel) — validated, precision-checked, agent-friendly."
|
|
5
|
+
type: software
|
|
6
|
+
authors:
|
|
7
|
+
- given-names: Devin
|
|
8
|
+
family-names: Lai
|
|
9
|
+
alias: devin-lai
|
|
10
|
+
repository-code: "https://github.com/devin-lai/coreai-onnx"
|
|
11
|
+
url: "https://github.com/devin-lai/coreai-onnx"
|
|
12
|
+
license: BSD-3-Clause
|
|
13
|
+
version: 1.0.0
|
|
14
|
+
date-released: "2026-06-13"
|
|
15
|
+
keywords:
|
|
16
|
+
- onnx
|
|
17
|
+
- core-ai
|
|
18
|
+
- coreai
|
|
19
|
+
- aimodel
|
|
20
|
+
- apple
|
|
21
|
+
- model-conversion
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
# Contributor Covenant Code of Conduct
|
|
3
|
+
|
|
4
|
+
## Our Pledge
|
|
5
|
+
|
|
6
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
|
|
7
|
+
|
|
8
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
|
9
|
+
|
|
10
|
+
## Our Standards
|
|
11
|
+
|
|
12
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
|
13
|
+
|
|
14
|
+
* Demonstrating empathy and kindness toward other people
|
|
15
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
16
|
+
* Giving and gracefully accepting constructive feedback
|
|
17
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
|
18
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
|
19
|
+
|
|
20
|
+
Examples of unacceptable behavior include:
|
|
21
|
+
|
|
22
|
+
* The use of sexualized language or imagery, and sexual attention or advances of any kind
|
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
24
|
+
* Public or private harassment
|
|
25
|
+
* Publishing others' private information, such as a physical or email address, without their explicit permission
|
|
26
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
|
27
|
+
|
|
28
|
+
## Enforcement Responsibilities
|
|
29
|
+
|
|
30
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
|
31
|
+
|
|
32
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
|
33
|
+
|
|
34
|
+
## Scope
|
|
35
|
+
|
|
36
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
37
|
+
|
|
38
|
+
## Enforcement
|
|
39
|
+
|
|
40
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at the project maintainers via GitHub issues or the repository's private vulnerability reporting. All complaints will be reviewed and investigated promptly and fairly.
|
|
41
|
+
|
|
42
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
|
43
|
+
|
|
44
|
+
## Enforcement Guidelines
|
|
45
|
+
|
|
46
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
|
47
|
+
|
|
48
|
+
### 1. Correction
|
|
49
|
+
|
|
50
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
|
51
|
+
|
|
52
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
|
53
|
+
|
|
54
|
+
### 2. Warning
|
|
55
|
+
|
|
56
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
|
57
|
+
|
|
58
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
|
59
|
+
|
|
60
|
+
### 3. Temporary Ban
|
|
61
|
+
|
|
62
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
|
63
|
+
|
|
64
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
|
65
|
+
|
|
66
|
+
### 4. Permanent Ban
|
|
67
|
+
|
|
68
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
|
69
|
+
|
|
70
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
|
71
|
+
|
|
72
|
+
## Attribution
|
|
73
|
+
|
|
74
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
75
|
+
|
|
76
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
77
|
+
|
|
78
|
+
For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].
|
|
79
|
+
|
|
80
|
+
[homepage]: https://www.contributor-covenant.org
|
|
81
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
82
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
83
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
84
|
+
[translations]: https://www.contributor-covenant.org/translations
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Contributing to coreai-onnx
|
|
2
|
+
|
|
3
|
+
## Dev setup
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
python -m pip install -e ".[test,dev]"
|
|
7
|
+
pre-commit install
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Running tests
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pytest -m "not slow" # all fast tests
|
|
14
|
+
pytest -m ops # operator parity tests only
|
|
15
|
+
pytest -n auto -m ir # MLIR-output tests, safe to parallelize
|
|
16
|
+
pytest -m slow # slow / large-model tests
|
|
17
|
+
pytest -m e2e # end-to-end model tests
|
|
18
|
+
pytest -m "not slow" --cov=coreai_onnx --cov-report=term-missing
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Keep Core AI runtime-executing tests serial. The native runtime uses
|
|
22
|
+
process-external specialization/cache state and can fail spuriously under
|
|
23
|
+
multi-process xdist loads; plain `pytest` is the source of truth.
|
|
24
|
+
|
|
25
|
+
**Markers:**
|
|
26
|
+
|
|
27
|
+
| Marker | Meaning |
|
|
28
|
+
|--------|---------|
|
|
29
|
+
| `ops` | Core operator parity tests — compare ONNX runtime vs. Core AI output |
|
|
30
|
+
| `ir` | MLIR-output tests; do not require the Core AI runtime |
|
|
31
|
+
| `slow` | Long-running tests; skipped by default in CI on PRs |
|
|
32
|
+
| `e2e` | End-to-end model conversion and execution tests |
|
|
33
|
+
|
|
34
|
+
**Runtime requirement:** op parity and e2e tests require the Core AI runtime, which
|
|
35
|
+
is only available on **macOS 27+**. Tests that need the runtime are guarded by the
|
|
36
|
+
`requires_coreai_runtime` marker/fixture in `tests/helpers.py`. They will be skipped
|
|
37
|
+
automatically on unsupported platforms.
|
|
38
|
+
|
|
39
|
+
## Adding an op lowering
|
|
40
|
+
|
|
41
|
+
1. **Write a failing parity test** in the appropriate `tests/test_ops_*.py`
|
|
42
|
+
file using the `single_op_model` helper and `assert_parity` from
|
|
43
|
+
`tests/helpers.py`. Use `zlib.crc32`-seeded inputs for reproducibility:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import zlib
|
|
47
|
+
|
|
48
|
+
import numpy as np
|
|
49
|
+
import pytest
|
|
50
|
+
|
|
51
|
+
from .helpers import assert_parity, requires_coreai_runtime, single_op_model
|
|
52
|
+
|
|
53
|
+
pytestmark = [pytest.mark.ops, requires_coreai_runtime]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
async def test_my_op_basic():
|
|
57
|
+
rng = np.random.default_rng(zlib.crc32(b"my_op_basic"))
|
|
58
|
+
x = rng.random((2, 3)).astype(np.float32)
|
|
59
|
+
model = single_op_model("MyOp", {"x": x})
|
|
60
|
+
await assert_parity(model, {"x": x})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
2. **Port or adapt the lowering** from `coreai-torch`'s `_aten_to_core.py`
|
|
64
|
+
patterns where applicable. Lowerings live under `src/coreai_onnx/_lowerings/`.
|
|
65
|
+
Each lowering is a function
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
(values_map: dict[str, Value], node: onnx.NodeProto, loc: Location) -> Value | list[Value]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
that reads its inputs from `values_map`, emits Core AI ops, and returns the
|
|
72
|
+
result `Value` (or a `list[Value]`, one entry per non-empty output slot, for
|
|
73
|
+
multi-output nodes).
|
|
74
|
+
|
|
75
|
+
3. **Register the lowering** in the appropriate
|
|
76
|
+
`src/coreai_onnx/_lowerings/_*.py` module's `REGISTRY` dict:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
REGISTRY["MyOp"] = lower_my_op
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
4. **Unsupported attribute combinations** must raise `ValueError` with a clear
|
|
83
|
+
message. Add a corresponding test:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
def test_my_op_unsupported_attr():
|
|
87
|
+
with pytest.raises(ConversionError, match="MyOp: attr X is not supported"):
|
|
88
|
+
convert(single_op_model("MyOp", {"x": x}, attrs={"X": 99}))
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
5. **Before opening a PR**, run:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
ruff check . && ruff format --check .
|
|
95
|
+
mypy --ignore-missing-imports src/coreai_onnx
|
|
96
|
+
pytest -m "not slow"
|
|
97
|
+
pytest -m "not slow" --cov=coreai_onnx --cov-report=term-missing
|
|
98
|
+
python -m build --sdist --wheel && twine check dist/*
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Error handling in lowerings
|
|
102
|
+
|
|
103
|
+
Raise plain `ValueError` with a precise message for anything the lowering
|
|
104
|
+
cannot handle (unsupported attribute combination, non-static dim, ...).
|
|
105
|
+
The converter wraps it into `ConversionError` with the node name and op
|
|
106
|
+
key attached — lowerings never raise `ConversionError` themselves. This
|
|
107
|
+
split is deliberate; don't "fix" it.
|
|
108
|
+
|
|
109
|
+
## PR checklist
|
|
110
|
+
|
|
111
|
+
- [ ] Failing test added before the fix / feature
|
|
112
|
+
- [ ] Lowering registered in `REGISTRY`
|
|
113
|
+
- [ ] Unsupported combos raise `ValueError` / `ConversionError` with clear message
|
|
114
|
+
- [ ] `ruff check . && ruff format --check .` passes
|
|
115
|
+
- [ ] `mypy --ignore-missing-imports src/coreai_onnx` passes
|
|
116
|
+
- [ ] `pytest -m "not slow"` passes
|
|
117
|
+
- [ ] `pytest -m "not slow" --cov=coreai_onnx --cov-report=term-missing` passes
|
|
118
|
+
- [ ] `python -m build --sdist --wheel && twine check dist/*` passes
|
|
119
|
+
|
|
120
|
+
## Known runtime quirks
|
|
121
|
+
|
|
122
|
+
These are confirmed bugs / limitations in the Core AI runtime as of the initial
|
|
123
|
+
release. Work around them in tests with `pytest.mark.xfail` or `pytest.mark.skip`
|
|
124
|
+
and leave a comment referencing this list.
|
|
125
|
+
|
|
126
|
+
- **Bool graph inputs crash logical primitives.** Passing a boolean tensor as a
|
|
127
|
+
top-level graph input (rather than casting inside the graph) crashes certain
|
|
128
|
+
logical ops. Workaround: cast to int32 at the graph boundary.
|
|
129
|
+
|
|
130
|
+
- **f16 graph-input crash.** Float16 tensors as graph inputs trigger a runtime
|
|
131
|
+
crash. Cast to float32 at the boundary and cast back as needed.
|
|
132
|
+
|
|
133
|
+
- **Multi-output `If` execution hang.** An `If` node whose branches return more
|
|
134
|
+
than one output value hangs indefinitely at runtime. Single-output `If` works.
|
|
135
|
+
|
|
136
|
+
- **Xcode Performance runner static-concat abort.** The Xcode model performance
|
|
137
|
+
service can abort inside MPSGraph's GPU `ConcatOpHandler` for common static
|
|
138
|
+
channel-concat image models. Keep static ONNX `Concat` lowered through the
|
|
139
|
+
pad+add/pad+where workaround unless the OS compiler bug is confirmed fixed.
|
|
140
|
+
|
|
141
|
+
- **Reduce ops ignore `keepdims=0`.** Reduce operators (ReduceSum, ReduceMean,
|
|
142
|
+
etc.) always keep the reduced dimension regardless of the `keepdims` attribute.
|
|
143
|
+
Squeeze the output manually as a workaround.
|
|
144
|
+
|
|
145
|
+
- **`floor_divide` truncates on integers.** Integer floor-division truncates
|
|
146
|
+
toward zero (C semantics) rather than flooring toward negative infinity
|
|
147
|
+
(Python / NumPy semantics). For negative operands the results will differ.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, coreai-onnx contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
include AGENTS.md
|
|
2
|
+
include CHANGELOG.md
|
|
3
|
+
include CODE_OF_CONDUCT.md
|
|
4
|
+
include CONTRIBUTING.md
|
|
5
|
+
include SECURITY.md
|
|
6
|
+
include LICENSE
|
|
7
|
+
include README.md
|
|
8
|
+
include CITATION.cff
|
|
9
|
+
include .editorconfig
|
|
10
|
+
include .gitattributes
|
|
11
|
+
include .pre-commit-config.yaml
|
|
12
|
+
include llms.txt
|
|
13
|
+
include pyproject.toml
|
|
14
|
+
|
|
15
|
+
recursive-include docs *.md *.py
|
|
16
|
+
recursive-include skills *.md
|
|
17
|
+
recursive-include tools *.py
|
|
18
|
+
recursive-include tests *.py
|
|
19
|
+
|
|
20
|
+
prune docs/superpowers
|
|
21
|
+
global-exclude .DS_Store
|