laya-coreml 0.1.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.
@@ -0,0 +1,17 @@
1
+ .venv/
2
+ .upstream/
3
+ __pycache__/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ models/
7
+ artifacts/
8
+ *.mlpackage/
9
+ *.mlmodelc/
10
+ *.trace/
11
+ *.safetensors
12
+ *.pt
13
+ *.log
14
+ dist/
15
+ build/
16
+ .DS_Store
17
+ .env
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,22 @@
1
+ laya-coreml
2
+ Copyright 2026 laya-coreml contributors
3
+
4
+ This product includes software adapted from Laya (Apache-2.0):
5
+ https://github.com/NandhaKishorM/laya
6
+ Copyright Convai Innovations and Laya contributors.
7
+ Upstream source revision: 6a5819129eb220570792e417e49723d697efd76f
8
+
9
+ Prompt construction, tokenization, result formatting, validation fixtures,
10
+ the ModernBERT architecture implementation, and the Snake game, policy, terminal
11
+ UI, recording/export and benchmark tools are adapted from laya-mlx:
12
+ https://github.com/mizorewww/laya-mlx
13
+ Copyright 2026 laya-mlx contributors. Licensed under Apache-2.0.
14
+ Adapted revision: fc1df62828a3fedf4d8229fdac1cbd85f1cdf337
15
+ Changes: Core ML runtime, export-only PyTorch graph, fixed/ranged shape input
16
+ handling, Core ML validation, device planning, and performance measurement;
17
+ ANE graph/runtime, portable model bundles and offline Core ML Snake integration.
18
+
19
+ The model follows Laya's DecisionModel and Hugging Face Transformers ModernBERT.
20
+ Original checkpoint weights belong to their respective upstream authors and
21
+ are downloaded separately. No weights are included in this repository.
22
+ This is an independent project, not an official Convai Innovations or Apple release.
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.4
2
+ Name: laya-coreml
3
+ Version: 0.1.0
4
+ Summary: Local Laya typed decisions on Apple Core ML and Neural Engine, with a live Snake demo
5
+ Project-URL: Repository, https://github.com/mizorewww/laya-coreml
6
+ Project-URL: Upstream, https://github.com/NandhaKishorM/laya
7
+ Project-URL: Documentation, https://github.com/mizorewww/laya-coreml#readme
8
+ Project-URL: Issues, https://github.com/mizorewww/laya-coreml/issues
9
+ Project-URL: Benchmarks, https://github.com/mizorewww/laya-coreml/blob/main/docs/ANE_BENCHMARKS.md
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: apple-silicon,coreml,decision-model,laya,local-ai,neural-engine
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: <3.14,>=3.11
20
+ Requires-Dist: coremltools<10,>=9
21
+ Requires-Dist: huggingface-hub<2,>=0.34
22
+ Requires-Dist: numpy<2.2,>=1.26
23
+ Requires-Dist: safetensors>=0.6
24
+ Requires-Dist: tokenizers<1,>=0.21
25
+ Provides-Extra: compare
26
+ Requires-Dist: laya-mlx==0.1.0; extra == 'compare'
27
+ Provides-Extra: convert
28
+ Requires-Dist: safetensors>=0.6; extra == 'convert'
29
+ Requires-Dist: torch==2.7.0; extra == 'convert'
30
+ Provides-Extra: demo
31
+ Requires-Dist: pillow<13,>=12; extra == 'demo'
32
+ Requires-Dist: rich<16,>=15; extra == 'demo'
33
+ Provides-Extra: dev
34
+ Requires-Dist: build>=1; extra == 'dev'
35
+ Requires-Dist: psutil>=6; extra == 'dev'
36
+ Requires-Dist: pytest>=8; extra == 'dev'
37
+ Requires-Dist: ruff>=0.12; extra == 'dev'
38
+ Provides-Extra: publish
39
+ Requires-Dist: twine<7,>=6; extra == 'publish'
40
+ Provides-Extra: research
41
+ Requires-Dist: kmeans1d==0.4.0; extra == 'research'
42
+ Description-Content-Type: text/markdown
43
+
44
+ ![Laya Core ML playing Snake with real local model probabilities](https://raw.githubusercontent.com/mizorewww/laya-coreml/main/docs/assets/snake-demo.gif)
45
+
46
+ # Laya-CoreML
47
+
48
+ **Open-weight typed decisions on Apple Silicon. Core ML, Neural Engine, zero generated tokens.**
49
+
50
+ [PyPI](https://pypi.org/project/laya-coreml/) · [Hugging Face weights](https://huggingface.co/aac6fef/laya-multilingual-coreml-ane) · [中文](https://github.com/mizorewww/laya-coreml/blob/main/README.zh-CN.md)
51
+
52
+ A real Laya model plays Snake locally, with visible probabilities, score, length,
53
+ latency and safety interventions. The GIF replays a recorded Core ML run at **1× speed**.
54
+ The game uses explicit planner features and a visible cycle safety layer.
55
+
56
+ The complete active Snake loop sustained **49.1–50.0 decisions/s** across three
57
+ uncapped 600-step episodes, with zero deaths and two safety interventions.
58
+ [Game-loop timings and paced-rate limits](https://github.com/mizorewww/laya-coreml/blob/main/docs/SNAKE_BENCHMARKS.md)
59
+ include rendering serialization; terminal painting is excluded.
60
+
61
+ **One short multilingual decision: 4.98 ms P50 / 5.31 ms P95 on M3 Max with ANE FP16.**
62
+ The same experiment measured **2.78× better whole-system energy per decision** than
63
+ compiled MLX FP16. A separately validated W8 palette variant reached 4.88 ms and
64
+ 3.19× energy improvement. These are single-question results, not full Snake frame
65
+ times; the requested 10× improvement was not achieved.
66
+
67
+ ## Run the demo
68
+
69
+ Apple Silicon · macOS 15+ · Python 3.11–3.13.
70
+
71
+ ```bash
72
+ pip install 'laya-coreml[demo]'
73
+ hf download aac6fef/laya-multilingual-coreml-ane --local-dir models/snake
74
+ laya-coreml-snake --model ./models/snake
75
+ ```
76
+
77
+ Download once, then play offline. No PyTorch, Transformers or MLX is needed for
78
+ inference. The terminal needs 104 columns × 35 rows. Space pauses; ↑/↓ changes
79
+ speed; R resets; Q quits. First-time Core ML initialization can take tens of seconds.
80
+
81
+ [Controls, recording and video export](https://github.com/mizorewww/laya-coreml/blob/main/docs/SNAKE_DEMO.md)
82
+ · [Measured stable decision rates](https://github.com/mizorewww/laya-coreml/blob/main/docs/SNAKE_BENCHMARKS.md)
83
+ · [Shareable video and recording provenance](https://github.com/mizorewww/laya-coreml/blob/main/docs/LAUNCH.md)
84
+
85
+ ## Ask for a decision
86
+
87
+ ```bash
88
+ pip install laya-coreml
89
+ ```
90
+
91
+ ```python
92
+ import laya_coreml as laya
93
+
94
+ agent = laya.load("aac6fef/laya-multilingual-coreml-ane")
95
+ result = agent.predict(
96
+ "The customer requests a refund of a duplicate payment.",
97
+ {
98
+ "refund": {
99
+ "type": "noul",
100
+ "instructions": "Does the customer request a refund?",
101
+ }
102
+ },
103
+ )
104
+ print(result["answers"]["refund"])
105
+ ```
106
+
107
+ Laya returns probabilities for **choice**, ordinal **score**, and boolean **noul**
108
+ questions. There is no autoregressive decoding or generated JSON to parse. Hub
109
+ models download before initialization; subsequent predictions stay local. Pass
110
+ `local_files_only=True` to require an existing cache, or load a local directory.
111
+
112
+ The ANE bundle has a **96-token total limit**, including question, options and
113
+ state. Longer requests raise a capacity error. Use
114
+ `aac6fef/laya-multilingual-coreml` for the general-purpose 1024-token model.
115
+ [Full API, model selection and offline usage](https://github.com/mizorewww/laya-coreml/blob/main/docs/USAGE.md).
116
+
117
+ ## Measured on M3 Max
118
+
119
+ 40-core GPU, 128 GiB, macOS 27.2. One 91-token question padded to 96, including
120
+ prompt preparation, tokenization, arrays, synchronous inference, calibration and
121
+ formatting. Loading and warmup are excluded. MLX enables compile, prefix caching
122
+ and shape buckets. Six alternating 20-second blocks per implementation produced
123
+ **65,598 stable calls**.
124
+
125
+ | Metric | Compiled MLX FP16 | Core ML ANE FP16 | Core ML ANE W8 |
126
+ |---|---:|---:|---:|
127
+ | P50 / P95 | 6.94 / 7.39 ms | **4.98 / 5.31 ms** | **4.88 / 5.23 ms** |
128
+ | Mean system power estimate | 61.39 W | 30.75 W | 27.39 W |
129
+ | System energy / decision | 0.4288 J | **0.1540 J** | **0.1344 J** |
130
+ | Speed gain | 1× | **1.39×** | **1.42×** |
131
+ | System energy gain | 1× | **2.78×** | **3.19×** |
132
+
133
+ Energy uses direct SMC PSTR sensor readings, with raw samples and explicit anomaly
134
+ rejection. This is an estimate with sensor and background-load uncertainty.
135
+ **Speed gain × average power ratio = energy gain**; multiplying energy by speed
136
+ again would double-count time. The W8 variant compresses weights while retaining
137
+ FP16 compute. It is approximate, and its package-size reduction is not a speed ratio.
138
+
139
+ [Speed, energy and hardware evidence](https://github.com/mizorewww/laya-coreml/blob/main/docs/ANE_BENCHMARKS.md)
140
+ · [Raw measurements](https://github.com/mizorewww/laya-coreml/tree/main/benchmarks/results).
141
+
142
+ ## Available checkpoints
143
+
144
+ | Hugging Face bundle | Default engine | Capacity | Purpose |
145
+ |---|---|---:|---|
146
+ | [Laya 421M](https://huggingface.co/aac6fef/laya-coreml) | CPU + GPU | 512 tokens | Original English model |
147
+ | [Multilingual 322M](https://huggingface.co/aac6fef/laya-multilingual-coreml) | CPU + GPU | 1024 tokens | General multilingual decisions |
148
+ | [Typed Decisions 421M](https://huggingface.co/aac6fef/laya-typed-decisions-coreml) | CPU + GPU | 1024 tokens | Original specialized checkpoint |
149
+ | [Snake GPU](https://huggingface.co/aac6fef/laya-multilingual-coreml-snake) | CPU + GPU | B3 / L64 | Batches the three compact game questions |
150
+ | [Multilingual ANE](https://huggingface.co/aac6fef/laya-multilingual-coreml-ane) | CPU + ANE | B1 / L96 | Short decisions, FP16 |
151
+ | [Multilingual ANE W8](https://huggingface.co/aac6fef/laya-multilingual-coreml-ane-w8) | CPU + ANE | B1 / L96 | Optional approximate palette compression |
152
+
153
+ Every bundle includes tokenizer/configuration, model card, provenance, checksums
154
+ and packaging-time validation. ANE bundles also include the exact original host
155
+ embedding/action tensors they need. No original training checkout is required.
156
+
157
+ ## Port fidelity and limits
158
+
159
+ The three general-purpose FP16 checkpoints match upstream selected answers on
160
+ **189/189 validation questions**. Each passes 100 repeated calls. ANE FP16 L96
161
+ passes **59/59 fitting questions**, with maximum calibrated-probability drift
162
+ 0.002925; W8 passes the same subset with drift 0.014393 under an unchanged 0.02
163
+ gate. Six- and four-bit experiments failed that gate and are not published weights.
164
+ These are conversion-fidelity fixtures, not proof of general task accuracy.
165
+
166
+ A separately exported FP16 ANE L1024 graph passes the complete **63/63** fixture,
167
+ but an actual 1024-token request takes about **91.7 ms** in its serial screen.
168
+ The short ANE result does not establish a long-context advantage. A 600-step
169
+ paired Snake check matches **600/600 actions**, with zero deaths and zero shield
170
+ interventions; the current ANE adapter's three sequential calls do not establish
171
+ a consistent full-game speedup over compiled MLX.
172
+
173
+ The ordinary SDPA Core ML export and the ANE graph are different implementations.
174
+ The ordinary export defaults to CPU+GPU after unrestricted RangeDim GPU shapes
175
+ failed local fidelity checks. Changing its device setting alone does not reproduce
176
+ the ANE result. The ANE rewrite uses BC1L activations, 1×1 projections and per-head
177
+ attention; its plan and a separate Instruments trace support Neural Engine work.
178
+ CPU still handles input/output boundaries.
179
+
180
+ ## Documentation and reproducibility
181
+
182
+ - [Install and Python/CLI API](https://github.com/mizorewww/laya-coreml/blob/main/docs/USAGE.md)
183
+ - [Snake demo and media](https://github.com/mizorewww/laya-coreml/blob/main/docs/SNAKE_DEMO.md)
184
+ - [Release artifacts and pinned Hub revisions](https://github.com/mizorewww/laya-coreml/blob/main/docs/RELEASE.md)
185
+ - [General Core ML benchmarks](https://github.com/mizorewww/laya-coreml/blob/main/BENCHMARKS.md)
186
+ - [ANE engineering experiments](https://github.com/mizorewww/laya-coreml/blob/main/docs/ANE_ENGINEERING.md)
187
+ - [Mathematical investigation of the 10× target](https://github.com/mizorewww/laya-coreml/blob/main/docs/ANE_MATH.md)
188
+ - [Conversion issues and supported shapes](https://github.com/mizorewww/laya-coreml/blob/main/docs/CONVERSION.md)
189
+
190
+ To export yourself, install `laya-coreml[convert]` and run
191
+ `laya-coreml convert laya-multilingual models/custom`. ANE research conversion,
192
+ compression and benchmark scripts live in the Git checkout. The inference wheel
193
+ contains the portable runtime and optional terminal demo.
194
+
195
+ Apache-2.0. Independent port of [Laya](https://github.com/NandhaKishorM/laya), by
196
+ Convai Innovations and contributors, building on the [MLX sibling project](https://github.com/mizorewww/laya-mlx).
197
+ Not an official Convai Innovations or Apple release. See
198
+ [NOTICE](https://github.com/mizorewww/laya-coreml/blob/main/NOTICE).
@@ -0,0 +1,155 @@
1
+ ![Laya Core ML playing Snake with real local model probabilities](https://raw.githubusercontent.com/mizorewww/laya-coreml/main/docs/assets/snake-demo.gif)
2
+
3
+ # Laya-CoreML
4
+
5
+ **Open-weight typed decisions on Apple Silicon. Core ML, Neural Engine, zero generated tokens.**
6
+
7
+ [PyPI](https://pypi.org/project/laya-coreml/) · [Hugging Face weights](https://huggingface.co/aac6fef/laya-multilingual-coreml-ane) · [中文](https://github.com/mizorewww/laya-coreml/blob/main/README.zh-CN.md)
8
+
9
+ A real Laya model plays Snake locally, with visible probabilities, score, length,
10
+ latency and safety interventions. The GIF replays a recorded Core ML run at **1× speed**.
11
+ The game uses explicit planner features and a visible cycle safety layer.
12
+
13
+ The complete active Snake loop sustained **49.1–50.0 decisions/s** across three
14
+ uncapped 600-step episodes, with zero deaths and two safety interventions.
15
+ [Game-loop timings and paced-rate limits](https://github.com/mizorewww/laya-coreml/blob/main/docs/SNAKE_BENCHMARKS.md)
16
+ include rendering serialization; terminal painting is excluded.
17
+
18
+ **One short multilingual decision: 4.98 ms P50 / 5.31 ms P95 on M3 Max with ANE FP16.**
19
+ The same experiment measured **2.78× better whole-system energy per decision** than
20
+ compiled MLX FP16. A separately validated W8 palette variant reached 4.88 ms and
21
+ 3.19× energy improvement. These are single-question results, not full Snake frame
22
+ times; the requested 10× improvement was not achieved.
23
+
24
+ ## Run the demo
25
+
26
+ Apple Silicon · macOS 15+ · Python 3.11–3.13.
27
+
28
+ ```bash
29
+ pip install 'laya-coreml[demo]'
30
+ hf download aac6fef/laya-multilingual-coreml-ane --local-dir models/snake
31
+ laya-coreml-snake --model ./models/snake
32
+ ```
33
+
34
+ Download once, then play offline. No PyTorch, Transformers or MLX is needed for
35
+ inference. The terminal needs 104 columns × 35 rows. Space pauses; ↑/↓ changes
36
+ speed; R resets; Q quits. First-time Core ML initialization can take tens of seconds.
37
+
38
+ [Controls, recording and video export](https://github.com/mizorewww/laya-coreml/blob/main/docs/SNAKE_DEMO.md)
39
+ · [Measured stable decision rates](https://github.com/mizorewww/laya-coreml/blob/main/docs/SNAKE_BENCHMARKS.md)
40
+ · [Shareable video and recording provenance](https://github.com/mizorewww/laya-coreml/blob/main/docs/LAUNCH.md)
41
+
42
+ ## Ask for a decision
43
+
44
+ ```bash
45
+ pip install laya-coreml
46
+ ```
47
+
48
+ ```python
49
+ import laya_coreml as laya
50
+
51
+ agent = laya.load("aac6fef/laya-multilingual-coreml-ane")
52
+ result = agent.predict(
53
+ "The customer requests a refund of a duplicate payment.",
54
+ {
55
+ "refund": {
56
+ "type": "noul",
57
+ "instructions": "Does the customer request a refund?",
58
+ }
59
+ },
60
+ )
61
+ print(result["answers"]["refund"])
62
+ ```
63
+
64
+ Laya returns probabilities for **choice**, ordinal **score**, and boolean **noul**
65
+ questions. There is no autoregressive decoding or generated JSON to parse. Hub
66
+ models download before initialization; subsequent predictions stay local. Pass
67
+ `local_files_only=True` to require an existing cache, or load a local directory.
68
+
69
+ The ANE bundle has a **96-token total limit**, including question, options and
70
+ state. Longer requests raise a capacity error. Use
71
+ `aac6fef/laya-multilingual-coreml` for the general-purpose 1024-token model.
72
+ [Full API, model selection and offline usage](https://github.com/mizorewww/laya-coreml/blob/main/docs/USAGE.md).
73
+
74
+ ## Measured on M3 Max
75
+
76
+ 40-core GPU, 128 GiB, macOS 27.2. One 91-token question padded to 96, including
77
+ prompt preparation, tokenization, arrays, synchronous inference, calibration and
78
+ formatting. Loading and warmup are excluded. MLX enables compile, prefix caching
79
+ and shape buckets. Six alternating 20-second blocks per implementation produced
80
+ **65,598 stable calls**.
81
+
82
+ | Metric | Compiled MLX FP16 | Core ML ANE FP16 | Core ML ANE W8 |
83
+ |---|---:|---:|---:|
84
+ | P50 / P95 | 6.94 / 7.39 ms | **4.98 / 5.31 ms** | **4.88 / 5.23 ms** |
85
+ | Mean system power estimate | 61.39 W | 30.75 W | 27.39 W |
86
+ | System energy / decision | 0.4288 J | **0.1540 J** | **0.1344 J** |
87
+ | Speed gain | 1× | **1.39×** | **1.42×** |
88
+ | System energy gain | 1× | **2.78×** | **3.19×** |
89
+
90
+ Energy uses direct SMC PSTR sensor readings, with raw samples and explicit anomaly
91
+ rejection. This is an estimate with sensor and background-load uncertainty.
92
+ **Speed gain × average power ratio = energy gain**; multiplying energy by speed
93
+ again would double-count time. The W8 variant compresses weights while retaining
94
+ FP16 compute. It is approximate, and its package-size reduction is not a speed ratio.
95
+
96
+ [Speed, energy and hardware evidence](https://github.com/mizorewww/laya-coreml/blob/main/docs/ANE_BENCHMARKS.md)
97
+ · [Raw measurements](https://github.com/mizorewww/laya-coreml/tree/main/benchmarks/results).
98
+
99
+ ## Available checkpoints
100
+
101
+ | Hugging Face bundle | Default engine | Capacity | Purpose |
102
+ |---|---|---:|---|
103
+ | [Laya 421M](https://huggingface.co/aac6fef/laya-coreml) | CPU + GPU | 512 tokens | Original English model |
104
+ | [Multilingual 322M](https://huggingface.co/aac6fef/laya-multilingual-coreml) | CPU + GPU | 1024 tokens | General multilingual decisions |
105
+ | [Typed Decisions 421M](https://huggingface.co/aac6fef/laya-typed-decisions-coreml) | CPU + GPU | 1024 tokens | Original specialized checkpoint |
106
+ | [Snake GPU](https://huggingface.co/aac6fef/laya-multilingual-coreml-snake) | CPU + GPU | B3 / L64 | Batches the three compact game questions |
107
+ | [Multilingual ANE](https://huggingface.co/aac6fef/laya-multilingual-coreml-ane) | CPU + ANE | B1 / L96 | Short decisions, FP16 |
108
+ | [Multilingual ANE W8](https://huggingface.co/aac6fef/laya-multilingual-coreml-ane-w8) | CPU + ANE | B1 / L96 | Optional approximate palette compression |
109
+
110
+ Every bundle includes tokenizer/configuration, model card, provenance, checksums
111
+ and packaging-time validation. ANE bundles also include the exact original host
112
+ embedding/action tensors they need. No original training checkout is required.
113
+
114
+ ## Port fidelity and limits
115
+
116
+ The three general-purpose FP16 checkpoints match upstream selected answers on
117
+ **189/189 validation questions**. Each passes 100 repeated calls. ANE FP16 L96
118
+ passes **59/59 fitting questions**, with maximum calibrated-probability drift
119
+ 0.002925; W8 passes the same subset with drift 0.014393 under an unchanged 0.02
120
+ gate. Six- and four-bit experiments failed that gate and are not published weights.
121
+ These are conversion-fidelity fixtures, not proof of general task accuracy.
122
+
123
+ A separately exported FP16 ANE L1024 graph passes the complete **63/63** fixture,
124
+ but an actual 1024-token request takes about **91.7 ms** in its serial screen.
125
+ The short ANE result does not establish a long-context advantage. A 600-step
126
+ paired Snake check matches **600/600 actions**, with zero deaths and zero shield
127
+ interventions; the current ANE adapter's three sequential calls do not establish
128
+ a consistent full-game speedup over compiled MLX.
129
+
130
+ The ordinary SDPA Core ML export and the ANE graph are different implementations.
131
+ The ordinary export defaults to CPU+GPU after unrestricted RangeDim GPU shapes
132
+ failed local fidelity checks. Changing its device setting alone does not reproduce
133
+ the ANE result. The ANE rewrite uses BC1L activations, 1×1 projections and per-head
134
+ attention; its plan and a separate Instruments trace support Neural Engine work.
135
+ CPU still handles input/output boundaries.
136
+
137
+ ## Documentation and reproducibility
138
+
139
+ - [Install and Python/CLI API](https://github.com/mizorewww/laya-coreml/blob/main/docs/USAGE.md)
140
+ - [Snake demo and media](https://github.com/mizorewww/laya-coreml/blob/main/docs/SNAKE_DEMO.md)
141
+ - [Release artifacts and pinned Hub revisions](https://github.com/mizorewww/laya-coreml/blob/main/docs/RELEASE.md)
142
+ - [General Core ML benchmarks](https://github.com/mizorewww/laya-coreml/blob/main/BENCHMARKS.md)
143
+ - [ANE engineering experiments](https://github.com/mizorewww/laya-coreml/blob/main/docs/ANE_ENGINEERING.md)
144
+ - [Mathematical investigation of the 10× target](https://github.com/mizorewww/laya-coreml/blob/main/docs/ANE_MATH.md)
145
+ - [Conversion issues and supported shapes](https://github.com/mizorewww/laya-coreml/blob/main/docs/CONVERSION.md)
146
+
147
+ To export yourself, install `laya-coreml[convert]` and run
148
+ `laya-coreml convert laya-multilingual models/custom`. ANE research conversion,
149
+ compression and benchmark scripts live in the Git checkout. The inference wheel
150
+ contains the portable runtime and optional terminal demo.
151
+
152
+ Apache-2.0. Independent port of [Laya](https://github.com/NandhaKishorM/laya), by
153
+ Convai Innovations and contributors, building on the [MLX sibling project](https://github.com/mizorewww/laya-mlx).
154
+ Not an official Convai Innovations or Apple release. See
155
+ [NOTICE](https://github.com/mizorewww/laya-coreml/blob/main/NOTICE).
@@ -0,0 +1,6 @@
1
+ """Core ML runtime for Laya. PyTorch is only needed when converting weights."""
2
+
3
+ from .agent import Agent, load
4
+
5
+ __all__ = ["Agent", "load"]
6
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ main()