laya-apple 1.0.1__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.
- laya_apple-1.0.1/LICENSE +176 -0
- laya_apple-1.0.1/NOTICE +33 -0
- laya_apple-1.0.1/PKG-INFO +267 -0
- laya_apple-1.0.1/README.md +215 -0
- laya_apple-1.0.1/laya_apple/__init__.py +37 -0
- laya_apple-1.0.1/laya_apple/artifacts.py +416 -0
- laya_apple-1.0.1/laya_apple/backends/__init__.py +0 -0
- laya_apple-1.0.1/laya_apple/backends/base.py +23 -0
- laya_apple-1.0.1/laya_apple/backends/coreml_ane.py +249 -0
- laya_apple-1.0.1/laya_apple/backends/mlx.py +76 -0
- laya_apple-1.0.1/laya_apple/benchmark.py +102 -0
- laya_apple-1.0.1/laya_apple/cli.py +342 -0
- laya_apple-1.0.1/laya_apple/conversion/__init__.py +0 -0
- laya_apple-1.0.1/laya_apple/conversion/bc1s.py +145 -0
- laya_apple-1.0.1/laya_apple/conversion/build.py +309 -0
- laya_apple-1.0.1/laya_apple/conversion/torch_reference.py +227 -0
- laya_apple-1.0.1/laya_apple/data/__init__.py +0 -0
- laya_apple-1.0.1/laya_apple/data/manifest.schema.json +76 -0
- laya_apple-1.0.1/laya_apple/data/placement.json +80 -0
- laya_apple-1.0.1/laya_apple/data/routing.json +328 -0
- laya_apple-1.0.1/laya_apple/derivation.py +48 -0
- laya_apple-1.0.1/laya_apple/errors.py +54 -0
- laya_apple-1.0.1/laya_apple/executor.py +362 -0
- laya_apple-1.0.1/laya_apple/hub.py +75 -0
- laya_apple-1.0.1/laya_apple/lifecycle.py +335 -0
- laya_apple-1.0.1/laya_apple/model.py +580 -0
- laya_apple-1.0.1/laya_apple/models/__init__.py +0 -0
- laya_apple-1.0.1/laya_apple/models/modernbert_mlx.py +250 -0
- laya_apple-1.0.1/laya_apple/parity/__init__.py +109 -0
- laya_apple-1.0.1/laya_apple/parity/ane.py +54 -0
- laya_apple-1.0.1/laya_apple/parity/goldens/__init__.py +0 -0
- laya_apple-1.0.1/laya_apple/parity/goldens/laya-multilingual.json +1 -0
- laya_apple-1.0.1/laya_apple/parity/goldens/laya-typed-decisions.json +1 -0
- laya_apple-1.0.1/laya_apple/parity/goldens/laya.json +1 -0
- laya_apple-1.0.1/laya_apple/profiles.py +217 -0
- laya_apple-1.0.1/laya_apple/prompt.py +269 -0
- laya_apple-1.0.1/laya_apple/py.typed +0 -0
- laya_apple-1.0.1/laya_apple/registry.py +97 -0
- laya_apple-1.0.1/laya_apple/result.py +51 -0
- laya_apple-1.0.1/laya_apple/routing.py +75 -0
- laya_apple-1.0.1/laya_apple/scheduling.py +93 -0
- laya_apple-1.0.1/laya_apple/schema.py +66 -0
- laya_apple-1.0.1/laya_apple/workload.py +111 -0
- laya_apple-1.0.1/pyproject.toml +115 -0
- laya_apple-1.0.1/pyproject.toml.orig +83 -0
laya_apple-1.0.1/LICENSE
ADDED
|
@@ -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
|
laya_apple-1.0.1/NOTICE
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
laya-apple
|
|
2
|
+
Copyright 2026 laya-apple contributors
|
|
3
|
+
|
|
4
|
+
Independent project. Not an official Convai Innovations, Apple, or MLX release.
|
|
5
|
+
|
|
6
|
+
This product includes software adapted from the following Apache-2.0 projects:
|
|
7
|
+
|
|
8
|
+
Laya — https://github.com/NandhaKishorM/laya
|
|
9
|
+
Copyright Convai Innovations and Laya contributors.
|
|
10
|
+
Revision: 573e5b62696ba441230cd6be71d593331b5d23af
|
|
11
|
+
Adapted: prompt construction, option rendering, calibration temperatures and
|
|
12
|
+
clamping, result schema (laya_apple/prompt.py, laya_apple/result.py).
|
|
13
|
+
|
|
14
|
+
laya-mlx — https://github.com/mizorewww/laya-mlx
|
|
15
|
+
Copyright 2026 laya-mlx contributors.
|
|
16
|
+
Revision: 0a859518634112655cb97c745dbf04f5191aaf13
|
|
17
|
+
Adapted: native MLX ModernBERT and Laya decision heads, weight-name mapping
|
|
18
|
+
(laya_apple/models/modernbert_mlx.py); Rust-tokenizer wrapper.
|
|
19
|
+
Modifications: packaging only; module docstring and imports.
|
|
20
|
+
|
|
21
|
+
laya-coreml — https://github.com/mizorewww/laya-coreml
|
|
22
|
+
Copyright 2026 laya-coreml contributors.
|
|
23
|
+
Revision: 4619e0483f07adf39068532e85b42ec2347edb83
|
|
24
|
+
Adapted: export-only PyTorch DecisionModel (laya_apple/conversion/torch_reference.py),
|
|
25
|
+
channel-first BC1S Neural Engine graph (laya_apple/conversion/bc1s.py, from
|
|
26
|
+
experiments/ane_engineering/model.py), host embedding / action-head runtime
|
|
27
|
+
(laya_apple/backends/coreml_ane.py, from laya_coreml/ane.py), Core ML compute-plan
|
|
28
|
+
inspection (laya_apple/artifacts.py).
|
|
29
|
+
Modifications: generalised to ModernBERT-large checkpoints, strict artifact
|
|
30
|
+
verification, fixed-shape bucket management.
|
|
31
|
+
|
|
32
|
+
Model weights are not included. They are downloaded from the upstream Hugging Face
|
|
33
|
+
repositories at pinned revisions and remain under their respective licenses.
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: laya-apple
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Correctness-validated heterogeneous Laya runtime for Apple Silicon (MLX GPU + Apple Neural Engine)
|
|
5
|
+
Keywords: laya,apple-silicon,mlx,coreml,apple-neural-engine,ane,inference,heterogeneous-computing,machine-learning
|
|
6
|
+
Author: oliver
|
|
7
|
+
Author-email: oliver <tc3oliver@gmail.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: NOTICE
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
16
|
+
Classifier: Environment :: GPU
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Dist: mlx>=0.32.2,<0.33 ; platform_machine == 'arm64' and sys_platform == 'darwin'
|
|
25
|
+
Requires-Dist: numpy>=1.26
|
|
26
|
+
Requires-Dist: tokenizers>=0.21,<1
|
|
27
|
+
Requires-Dist: huggingface-hub>=0.34,<2
|
|
28
|
+
Requires-Dist: safetensors>=0.6
|
|
29
|
+
Requires-Dist: coremltools==9.0 ; extra == 'ane'
|
|
30
|
+
Requires-Dist: numpy>=1.26,<2.2 ; extra == 'ane'
|
|
31
|
+
Requires-Dist: coremltools==9.0 ; extra == 'convert'
|
|
32
|
+
Requires-Dist: numpy>=1.26,<2.2 ; extra == 'convert'
|
|
33
|
+
Requires-Dist: torch==2.7.0 ; extra == 'convert'
|
|
34
|
+
Requires-Dist: pytest>=8 ; extra == 'dev'
|
|
35
|
+
Requires-Dist: ruff>=0.12 ; extra == 'dev'
|
|
36
|
+
Requires-Dist: psutil>=6 ; extra == 'dev'
|
|
37
|
+
Requires-Dist: torch==2.7.0 ; extra == 'reference'
|
|
38
|
+
Requires-Dist: transformers==5.17.0 ; extra == 'reference'
|
|
39
|
+
Requires-Dist: laya==0.3.5 ; extra == 'reference'
|
|
40
|
+
Requires-Python: >=3.11, <3.14
|
|
41
|
+
Project-URL: Homepage, https://github.com/tc3oliver/laya-apple
|
|
42
|
+
Project-URL: Documentation, https://github.com/tc3oliver/laya-apple/blob/main/docs/guide.md
|
|
43
|
+
Project-URL: Changelog, https://github.com/tc3oliver/laya-apple/blob/main/CHANGELOG.md
|
|
44
|
+
Project-URL: Issues, https://github.com/tc3oliver/laya-apple/issues
|
|
45
|
+
Project-URL: Repository, https://github.com/tc3oliver/laya-apple
|
|
46
|
+
Project-URL: Upstream, https://github.com/NandhaKishorM/laya
|
|
47
|
+
Provides-Extra: ane
|
|
48
|
+
Provides-Extra: convert
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Provides-Extra: reference
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
|
|
53
|
+
# laya-apple
|
|
54
|
+
|
|
55
|
+
[](https://github.com/tc3oliver/laya-apple/actions/workflows/ci.yml)
|
|
56
|
+

|
|
57
|
+
[](LICENSE)
|
|
58
|
+
|
|
59
|
+
**Correctness-validated heterogeneous [Laya](https://github.com/NandhaKishorM/laya) runtime
|
|
60
|
+
for Apple silicon.** It runs the MLX GPU and the Apple Neural Engine at the same time, and
|
|
61
|
+
uses the Neural Engine only where it has been proven to give the same decisions as
|
|
62
|
+
upstream Laya.
|
|
63
|
+
|
|
64
|
+
**Mixed-workload throughput against GPU-only serving:**
|
|
65
|
+
|
|
66
|
+
| Model | GPU-only | GPU + ANE | Speed-up | Answer mismatches |
|
|
67
|
+
|---|---:|---:|---:|---:|
|
|
68
|
+
| laya | 41.9 req/s | 122.5 req/s | **2.92×** | 0 |
|
|
69
|
+
| laya-multilingual | 55.7 req/s | 241.8 req/s | **4.34×** | 0 |
|
|
70
|
+
| laya-typed-decisions | 24.0 req/s | 109.6 req/s | **4.57×** | 0 |
|
|
71
|
+
|
|
72
|
+
This is the v1.0 benchmark on one Apple M4 Max with macOS 26.6.2: one short and one long
|
|
73
|
+
request stream through one `Laya` instance. Other Macs are untested, and you can
|
|
74
|
+
[add yours](docs/community-benchmarks.md). The method and raw data are in
|
|
75
|
+
[`benchmarks/v1.0.md`](benchmarks/v1.0.md).
|
|
76
|
+
|
|
77
|
+
## Why this exists
|
|
78
|
+
|
|
79
|
+
Laya answers typed questions about a context (`choice`, `score`, `noul`) in one forward
|
|
80
|
+
pass. On a Mac there are two engines that can run it, with different strengths.
|
|
81
|
+
|
|
82
|
+
1. **Correct ANE execution.** A fast Core ML export is not necessarily correct. On the
|
|
83
|
+
tested Mac, the ordinary Core ML export ran on the Neural Engine without any error and
|
|
84
|
+
changed up to 85 decisions against upstream PyTorch. laya-apple ships an ANE artifact
|
|
85
|
+
only after it passes a parity gate on the machine that uses it
|
|
86
|
+
([`docs/correctness.md`](docs/correctness.md)).
|
|
87
|
+
2. **Automatic routing.** Short, validated single-question requests go to the ANE. Long or
|
|
88
|
+
multi-question requests go to the MLX GPU. The router decides before a request runs and
|
|
89
|
+
records why.
|
|
90
|
+
3. **Concurrent GPU + ANE serving.** Both engines serve independent requests at the same
|
|
91
|
+
time, so short requests stop queueing behind long ones.
|
|
92
|
+
|
|
93
|
+
## Install
|
|
94
|
+
|
|
95
|
+
From a clone (Apple silicon, Python 3.11–3.13; not on PyPI yet):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
git clone https://github.com/tc3oliver/laya-apple && cd laya-apple
|
|
99
|
+
uv sync --extra ane --extra convert
|
|
100
|
+
uv run laya-apple artifacts build laya-typed-decisions # optional: build + parity-validate ANE artifacts here (~5 min)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Without `artifacts build`, or with a plain `uv sync`, everything runs on the MLX GPU.
|
|
104
|
+
|
|
105
|
+
## Quickstart (30 seconds)
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from laya_apple import Laya
|
|
109
|
+
|
|
110
|
+
model = Laya.from_pretrained(
|
|
111
|
+
"convaiinnovations/laya-typed-decisions",
|
|
112
|
+
device="auto",
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
result = model.predict(
|
|
116
|
+
context="The customer was charged twice for the same invoice and is frustrated.",
|
|
117
|
+
questions={
|
|
118
|
+
"urgency": {
|
|
119
|
+
"type": "choice",
|
|
120
|
+
"instructions": "How urgent is this?",
|
|
121
|
+
"criteria": ["low", "medium", "high"],
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
)
|
|
125
|
+
print(result.answers["urgency"]["choice"], result.answers["urgency"]["probabilities"])
|
|
126
|
+
|
|
127
|
+
rt = result.runtime
|
|
128
|
+
print(rt.backend, rt.device, rt.routing_reason, f"{rt.latency_ms:.1f} ms")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
On the tested machine:
|
|
132
|
+
|
|
133
|
+
```text
|
|
134
|
+
high {'low': 0.1713, 'medium': 0.3358, 'high': 0.4929}
|
|
135
|
+
coreml ane validated_short_single_question_path 11.2 ms
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- The first call downloads the pinned checkpoint. After that it works offline
|
|
139
|
+
(`local_files_only=True`).
|
|
140
|
+
- Without ANE artifacts, the same request runs on MLX and `routing_reason` says why.
|
|
141
|
+
- More: [`examples/`](examples/) (`basic.py`, `auto_routing.py`,
|
|
142
|
+
`heterogeneous_serving.py`) and the [user guide](docs/guide.md).
|
|
143
|
+
|
|
144
|
+
## How auto routing works
|
|
145
|
+
|
|
146
|
+
| Request | Goes to | Why (measured on the tested Mac) |
|
|
147
|
+
|---|---|---|
|
|
148
|
+
| One question, ≤ 128 tokens, validated artifact present | **ANE** | Faster: laya-typed-decisions L128 takes 9.9 ms on the ANE against 12.2 ms on MLX (forward P50) |
|
|
149
|
+
| Longer context | **MLX GPU** | MLX is faster there: 19.2 ms at L256 and 71.0 ms at L1024 |
|
|
150
|
+
| Several questions | **MLX GPU** | MLX batches the questions; the ANE runs them one at a time |
|
|
151
|
+
| Unvalidated Mac, missing artifact, or no Core ML | **MLX GPU** | Recorded as `platform_not_validated`, `ane_artifact_unavailable` or `ane_runtime_unavailable` |
|
|
152
|
+
|
|
153
|
+
**The production threshold is more conservative than the measured crossover.**
|
|
154
|
+
laya-multilingual is slightly faster on the ANE at exactly 256 tokens (8.3 ms against
|
|
155
|
+
8.6 ms), but that bucket stays explicit-only, because it does not beat MLX at the previous
|
|
156
|
+
bucket, 128 tokens. Every result carries `routing_reason`.
|
|
157
|
+
|
|
158
|
+
How the thresholds are derived: [`docs/support-matrix.md`](docs/support-matrix.md). How
|
|
159
|
+
the pieces fit together: [`docs/architecture.md`](docs/architecture.md).
|
|
160
|
+
|
|
161
|
+
## GPU + ANE heterogeneous serving
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
with Laya.from_pretrained("convaiinnovations/laya-typed-decisions", execution="workers") as model:
|
|
165
|
+
futures = [model.submit(context=c, questions=q) for c, q in requests] # thread-safe
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
- The GPU runs in a worker process, and the ANE on its own dispatcher.
|
|
169
|
+
- Each request runs on one device, chosen by the router.
|
|
170
|
+
- Under load, the router also compares queue backlogs.
|
|
171
|
+
|
|
172
|
+
**Short-request P99 under open-loop bursty arrivals**, measured from arrival with queueing
|
|
173
|
+
included (v1.0, same arrival sequence for both):
|
|
174
|
+
|
|
175
|
+
| Model | GPU-only | GPU + ANE |
|
|
176
|
+
|---|---:|---:|
|
|
177
|
+
| laya (46.2 req/s offered) | 1538.0 ms | 108.5 ms |
|
|
178
|
+
| laya-multilingual (83.8 req/s) | 2052.3 ms | 29.6 ms |
|
|
179
|
+
| laya-typed-decisions (35.8 req/s) | 1592.9 ms | 79.5 ms |
|
|
180
|
+
|
|
181
|
+
A single short request is not dramatically faster on the ANE (for example 9.9 against
|
|
182
|
+
12.2 ms). The gain comes from using both engines at once.
|
|
183
|
+
|
|
184
|
+
## Correctness
|
|
185
|
+
|
|
186
|
+
Parity against upstream Laya on PyTorch CPU FP32, over the shipped golden rows (v1.0).
|
|
187
|
+
Each cell gives hard mismatches, then the max probability error.
|
|
188
|
+
|
|
189
|
+
| Implementation on the tested Mac | laya | laya-multilingual | laya-typed-decisions |
|
|
190
|
+
|---|---|---|---|
|
|
191
|
+
| Ordinary Core ML export · `CPU_AND_NE` | ❌ 12, 0.56 | ❌ 85, 1.0 | ❌ 19, 0.42 |
|
|
192
|
+
| Ordinary Core ML export · `CPU_AND_GPU` | ✅ 0, 0.0066 | ✅ 0, 0.0059 | ✅ 0, 0.0028 |
|
|
193
|
+
| **laya-apple MLX FP16** | ✅ 0, 0.0037 | ✅ 0, 0.0045 | ✅ 0, 0.0017 |
|
|
194
|
+
| **laya-apple ANE FP16** | ✅ 0 (1 near-tie), 0.012 | ✅ 0, 0.013 | ✅ 0, 0.0077 |
|
|
195
|
+
|
|
196
|
+
- **The FP16 gate:** probability error ≤ 0.02 and 0 hard mismatches.
|
|
197
|
+
- **Near-tie flips** (upstream's top-two margin < 0.04) are listed, not hidden.
|
|
198
|
+
- **Explicit ANE requests never fall back.** They run the validated artifact or raise, and
|
|
199
|
+
every loaded artifact is also timed against `CPU_ONLY` to catch a silent CPU placement.
|
|
200
|
+
- Definitions, every configuration tested, and the fallback audit are in
|
|
201
|
+
[`docs/correctness.md`](docs/correctness.md) and
|
|
202
|
+
[`docs/no-silent-fallback.md`](docs/no-silent-fallback.md).
|
|
203
|
+
|
|
204
|
+
## Supported models and platforms
|
|
205
|
+
|
|
206
|
+
| Model | max_len | MLX GPU | ANE buckets (explicit) | ANE buckets used by `auto` |
|
|
207
|
+
|---|---:|---|---|---|
|
|
208
|
+
| [`convaiinnovations/laya`](https://huggingface.co/convaiinnovations/laya) | 512 | FP16 / FP32, any length | 64, 96, 128 | 64, 96, 128 |
|
|
209
|
+
| [`convaiinnovations/laya-multilingual`](https://huggingface.co/convaiinnovations/laya-multilingual) | 1024 | FP16 / FP32, any length | 64, 96, 128, 256 | 64, 96, 128 |
|
|
210
|
+
| [`convaiinnovations/laya-typed-decisions`](https://huggingface.co/convaiinnovations/laya-typed-decisions) | 1024 | FP16 / FP32, any length | 64, 96, 128 | 64, 96, 128 |
|
|
211
|
+
|
|
212
|
+
**Tested:**
|
|
213
|
+
- Apple M4 Max, macOS 26.6.2, MLX 0.32.2, coremltools 9.0;
|
|
214
|
+
- Python 3.11–3.13.
|
|
215
|
+
|
|
216
|
+
**Other Apple silicon:**
|
|
217
|
+
- MLX is expected to work.
|
|
218
|
+
- `auto` stays on MLX until artifacts are built and calibrated on that machine
|
|
219
|
+
(`laya-apple calibrate`).
|
|
220
|
+
|
|
221
|
+
See [`docs/compatibility.md`](docs/compatibility.md) and the community matrix in
|
|
222
|
+
[`docs/community-benchmarks.md`](docs/community-benchmarks.md).
|
|
223
|
+
|
|
224
|
+
## Reproduction
|
|
225
|
+
|
|
226
|
+
Each headline number above traces to a report, raw data, a command and an environment in
|
|
227
|
+
[`docs/reproducibility.md`](docs/reproducibility.md). The full v1.0 suite, which compares
|
|
228
|
+
PyTorch CPU/MPS, the ordinary Core ML export, MLX and laya-apple, is in
|
|
229
|
+
[`benchmarks/v1.0.md`](benchmarks/v1.0.md). The quick check for your own Mac:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
uv run python scripts/hardware_report.py --quick
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Contributing
|
|
236
|
+
|
|
237
|
+
The most useful first contribution is a benchmark from a Mac other than an M4 Max: run
|
|
238
|
+
the command above and open a PR with `hardware-results/`
|
|
239
|
+
([how](docs/community-benchmarks.md)).
|
|
240
|
+
|
|
241
|
+
- [`CONTRIBUTING.md`](CONTRIBUTING.md) covers setup, test tiers (which tests a change
|
|
242
|
+
actually needs), parity checks and backend changes.
|
|
243
|
+
- Open work is labelled `good first issue`, `help wanted` and `research`.
|
|
244
|
+
|
|
245
|
+
## Limitations
|
|
246
|
+
|
|
247
|
+
- **One test machine.** Every benchmark is from one Apple M4 Max on macOS 26.6.2. Routing
|
|
248
|
+
thresholds are not assumed to hold on other Apple SoCs.
|
|
249
|
+
- **Long contexts stay on MLX,** which is faster there. The ANE path is batch 1 only.
|
|
250
|
+
- **Isolation is partial.** Under concurrency, each stream's P99 is above its solo value.
|
|
251
|
+
- **Cold start** on a fresh artifact location costs 3–5 minutes of Core ML compile per
|
|
252
|
+
model. `ane_startup="background"` serves on MLX in the meantime.
|
|
253
|
+
- **`choice` decisions can depend on option order.** This comes from upstream Laya, and
|
|
254
|
+
laya-apple reproduces it exactly ([`research/option-order/`](research/option-order/)).
|
|
255
|
+
- **Not measured yet:** energy use, quantized artifacts and cross-SoC validation.
|
|
256
|
+
|
|
257
|
+
## More
|
|
258
|
+
|
|
259
|
+
- User guide: [`docs/guide.md`](docs/guide.md).
|
|
260
|
+
- Stable API: [`docs/api.md`](docs/api.md).
|
|
261
|
+
- Architecture: [`docs/architecture.md`](docs/architecture.md).
|
|
262
|
+
- Changes: [`CHANGELOG.md`](CHANGELOG.md).
|
|
263
|
+
- Security: [`SECURITY.md`](SECURITY.md).
|
|
264
|
+
|
|
265
|
+
Apache-2.0; see [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE). Model weights are downloaded
|
|
266
|
+
from their pinned Hugging Face revisions and are not redistributed. This is an independent
|
|
267
|
+
project, not an official release of Convai Innovations, Apple or MLX.
|