tinkerbox-ane 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.
- tinkerbox_ane-1.0.0/.gitignore +12 -0
- tinkerbox_ane-1.0.0/LICENSES/LFM-Open-License-v1.0.txt +71 -0
- tinkerbox_ane-1.0.0/NOTICE +11 -0
- tinkerbox_ane-1.0.0/PKG-INFO +94 -0
- tinkerbox_ane-1.0.0/README.md +78 -0
- tinkerbox_ane-1.0.0/docs/cow-staging.md +30 -0
- tinkerbox_ane-1.0.0/examples/swiftui/Demo.swift +451 -0
- tinkerbox_ane-1.0.0/examples/swiftui/LICENSE-uv.txt +21 -0
- tinkerbox_ane-1.0.0/examples/swiftui/README.md +38 -0
- tinkerbox_ane-1.0.0/examples/swiftui/Tinkerbox.icon/Assets/Glow.svg +14 -0
- tinkerbox_ane-1.0.0/examples/swiftui/Tinkerbox.icon/Assets/Long 1.svg +3 -0
- tinkerbox_ane-1.0.0/examples/swiftui/Tinkerbox.icon/Assets/Long 2.svg +3 -0
- tinkerbox_ane-1.0.0/examples/swiftui/Tinkerbox.icon/Assets/Nodes.svg +10 -0
- tinkerbox_ane-1.0.0/examples/swiftui/Tinkerbox.icon/Assets/Short.svg +3 -0
- tinkerbox_ane-1.0.0/examples/swiftui/Tinkerbox.icon/icon.json +156 -0
- tinkerbox_ane-1.0.0/examples/swiftui/run.py +89 -0
- tinkerbox_ane-1.0.0/examples/swiftui/worker.py +78 -0
- tinkerbox_ane-1.0.0/hatch_build.py +34 -0
- tinkerbox_ane-1.0.0/pyproject.toml +41 -0
- tinkerbox_ane-1.0.0/scripts/build_reference.py +187 -0
- tinkerbox_ane-1.0.0/scripts/validate.py +65 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/__init__.py +1 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/__init__.py +29 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/bundle.py +83 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/compile.py +63 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/cow-staging.m +94 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/export.py +61 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/guard.py +155 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/host.py +121 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/host.swift +365 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/model.py +322 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/runtime.py +121 -0
- tinkerbox_ane-1.0.0/src/tinkerbox_ane/d1/validation.py +83 -0
- tinkerbox_ane-1.0.0/tests/test_runtime.py +63 -0
- tinkerbox_ane-1.0.0/uv.lock +957 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
LFM Open License v1.0
|
|
2
|
+
|
|
3
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
4
|
+
|
|
5
|
+
1. Definitions.
|
|
6
|
+
|
|
7
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by this document.
|
|
8
|
+
|
|
9
|
+
"Licensor" shall mean Liquid AI, Inc.
|
|
10
|
+
|
|
11
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
12
|
+
|
|
13
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
14
|
+
|
|
15
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
16
|
+
|
|
17
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
18
|
+
|
|
19
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work.
|
|
20
|
+
|
|
21
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
22
|
+
|
|
23
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
24
|
+
|
|
25
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
26
|
+
|
|
27
|
+
"Commercial Use" shall mean any use of the Work for direct or indirect commercial advantage or monetary compensation.
|
|
28
|
+
|
|
29
|
+
"Qualified Non-Profit Organization" shall mean a Legal Entity that is organized and operated exclusively for religious, charitable, scientific, testing for public safety, literary, or educational purposes, and which is exempt from federal income tax under Section 501(c)(3) of the United States Internal Revenue Code of 1986, as amended, or any equivalent non-profit or charitable organization in a foreign jurisdiction.
|
|
30
|
+
|
|
31
|
+
"Non-Commercial or Research Purposes" shall mean purposes that do not involve any use of the Work or a Derivative Work for Commercial Use.
|
|
32
|
+
|
|
33
|
+
"Threshold" shall mean annual revenue of 10 million United States dollars ($10,000,000) or more.
|
|
34
|
+
|
|
35
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, including the Commercial Use limitation set forth in Section 5, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
36
|
+
|
|
37
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, including the Commercial Use limitation set forth in Section 5, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
38
|
+
|
|
39
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
40
|
+
|
|
41
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
42
|
+
|
|
43
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
44
|
+
|
|
45
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
46
|
+
|
|
47
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
48
|
+
|
|
49
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
50
|
+
|
|
51
|
+
5. Commercial Use Limitation.
|
|
52
|
+
|
|
53
|
+
(a) The rights granted under this License for Commercial Use are conditioned upon You or Your Legal Entity not exceeding the Threshold.
|
|
54
|
+
|
|
55
|
+
(b) Any Commercial Use of the Work or a Derivative Work by a Legal Entity that exceeds the Threshold is not licensed under this Agreement.
|
|
56
|
+
|
|
57
|
+
(c) The Threshold shall not apply to a Qualified Non-Profit Organization's use of the Work or a Derivative Work for Non-Commercial or Research Purposes.
|
|
58
|
+
|
|
59
|
+
6. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
60
|
+
|
|
61
|
+
7. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except for the reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
62
|
+
|
|
63
|
+
8. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
64
|
+
|
|
65
|
+
9. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
66
|
+
|
|
67
|
+
10. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
68
|
+
|
|
69
|
+
11. Termination. This License will terminate automatically and immediately if You fail to comply with any of its terms and conditions. Upon termination, You must cease all use of the Work and any Derivative Works and delete all copies in Your possession.
|
|
70
|
+
|
|
71
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Independent FP16 text-backbone conversion of LiquidAI/d1-3B.
|
|
2
|
+
Upstream: https://huggingface.co/LiquidAI/d1-3B
|
|
3
|
+
Revision: 051bcc464b01b9f92942b364d9586b0ef5912432
|
|
4
|
+
|
|
5
|
+
The upstream checkpoint, code and converted weights are governed by the
|
|
6
|
+
LFM Open License v1.0 in LICENSES/LFM-Open-License-v1.0.txt.
|
|
7
|
+
|
|
8
|
+
The conversion uses 1x1 convolution projections, activation scaling,
|
|
9
|
+
tanh-form SiLU and a split FFN. Embeddings and option readout run on the
|
|
10
|
+
host. The vision tower is excluded; the model has not been retrained.
|
|
11
|
+
This project is not affiliated with or endorsed by Liquid AI.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tinkerbox-ane
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: LiquidAI d1-3B decision model on the Apple Neural Engine via Core AI
|
|
5
|
+
Project-URL: Homepage, https://github.com/WeGoToMars/tinkerbox
|
|
6
|
+
Project-URL: Issues, https://github.com/WeGoToMars/tinkerbox/issues
|
|
7
|
+
License-File: LICENSES/LFM-Open-License-v1.0.txt
|
|
8
|
+
License-File: NOTICE
|
|
9
|
+
Requires-Python: <3.14,>=3.12
|
|
10
|
+
Requires-Dist: huggingface-hub==2.2.0
|
|
11
|
+
Requires-Dist: numpy==2.4.6
|
|
12
|
+
Requires-Dist: safetensors==0.8.0
|
|
13
|
+
Requires-Dist: torch==2.9.0
|
|
14
|
+
Requires-Dist: transformers==5.19.0
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Tinkerbox for Apple Neural Engine
|
|
18
|
+
|
|
19
|
+
Run [LiquidAI/d1-3B](https://huggingface.co/LiquidAI/d1-3B) on Apple's Neural Engine through Core AI. FP16 backbone, 128-token chunks, 32,768-token context. Tokenization, embeddings and answer readout run on the CPU.
|
|
20
|
+
|
|
21
|
+
Requires Apple Silicon, macOS 27, and Python 3.12 or 3.13.
|
|
22
|
+
|
|
23
|
+
## Quickstart
|
|
24
|
+
|
|
25
|
+
Install the wheel from the GitHub release (Xcode is not required):
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
python -m pip install ./tinkerbox_ane-*.whl
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from tinkerbox_ane import d1
|
|
33
|
+
|
|
34
|
+
with d1.load() as model:
|
|
35
|
+
result = model.system_one(
|
|
36
|
+
"I was charged twice this month.",
|
|
37
|
+
{"refund": {"type": "noul", "instructions": "Is this a refund request?"}},
|
|
38
|
+
)
|
|
39
|
+
print(result)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`load()` downloads the matching Core AI architecture from [wegotomars/d1-3B-CoreAI-ANE](https://huggingface.co/wegotomars/d1-3B-CoreAI-ANE) (`v1.0.0`) into `~/Library/Caches/tinkerbox-ane/d1/models/`. Pass a directory path to `load(path)` to select a local AOT bundle.
|
|
43
|
+
|
|
44
|
+
The API exposes `system_one`, `system_one_batch`, `probabilities`, and `probabilities_batch` for binary, choice, and score queries. Requests run sequentially. Prompts and images exceeding 32,768 rendered tokens are rejected.
|
|
45
|
+
|
|
46
|
+
## SwiftUI Demo
|
|
47
|
+
|
|
48
|
+
A desktop demo is available in [examples/swiftui](examples/swiftui). To build and launch it from source:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
uv run --no-project --python 3.12 python examples/swiftui/run.py
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Pass `--build-only` to create `artifacts/swiftui/Tinkerbox.app` and the release ZIP without launching. The prebuilt app manages its own Python environment and dependencies via an embedded `uv` binary.
|
|
55
|
+
|
|
56
|
+
## Architecture & Staging
|
|
57
|
+
|
|
58
|
+
The Swift host manages recurrent state and allocates attention cache buffers dynamically. Initial execution compiles and specializes the AOT asset for the local ANE hardware, after which Core AI reuses its persistent cache.
|
|
59
|
+
|
|
60
|
+
Weight staging uses an [APFS copy-on-write workaround](docs/cow-staging.md) to eliminate redundant disk writes during specialization.
|
|
61
|
+
|
|
62
|
+
## Building from Source
|
|
63
|
+
|
|
64
|
+
Building requires Xcode 27 / Swift 6.4 and [uv](https://docs.astral.sh/uv/):
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
uv sync --locked
|
|
68
|
+
uv build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The wheel in `dist/` bundles the native host and links against macOS system frameworks. Attach it to the GitHub release. Source and editable installs compile the host during installation.
|
|
72
|
+
|
|
73
|
+
To export and compile model weights locally:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
uv run python -m tinkerbox_ane.d1.export
|
|
77
|
+
uv run python -m tinkerbox_ane.d1.compile
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Export writes `artifacts/build/d1_fp16_fused128_ctx32768`; compilation produces the final bundle in `artifacts/d1_fp16_fused128_ctx32768`. Load the local result with `d1.load(d1.DEFAULT_ASSET)`. Rebuilds require fresh `--out` directories.
|
|
81
|
+
|
|
82
|
+
Compilation verifies source identity, all nine functions, and ANE placement. Without cached sudo authentication, worker cancellation is best effort and emits a warning.
|
|
83
|
+
|
|
84
|
+
## Validation
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
uv run python scripts/build_reference.py
|
|
88
|
+
uv run python -m tinkerbox_ane.d1.guard artifacts/validation/check -- uv run python scripts/validate.py
|
|
89
|
+
uv run python -m tinkerbox_ane.d1.guard artifacts/validation/smoke -- uv run pytest -q
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Reference generation downloads benchmark inputs and runs the official FP32 CPU model. Validation checks prompt tokens and probabilities across all nine cache capacities. The two public API smoke tests require a local bundle and cached checkpoint.
|
|
93
|
+
|
|
94
|
+
Weights and upstream code are pinned to `LiquidAI/d1-3B@051bcc464b01b9f92942b364d9586b0ef5912432` under the [LFM Open License v1.0](LICENSES/LFM-Open-License-v1.0.txt). See [NOTICE](NOTICE).
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Tinkerbox for Apple Neural Engine
|
|
2
|
+
|
|
3
|
+
Run [LiquidAI/d1-3B](https://huggingface.co/LiquidAI/d1-3B) on Apple's Neural Engine through Core AI. FP16 backbone, 128-token chunks, 32,768-token context. Tokenization, embeddings and answer readout run on the CPU.
|
|
4
|
+
|
|
5
|
+
Requires Apple Silicon, macOS 27, and Python 3.12 or 3.13.
|
|
6
|
+
|
|
7
|
+
## Quickstart
|
|
8
|
+
|
|
9
|
+
Install the wheel from the GitHub release (Xcode is not required):
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
python -m pip install ./tinkerbox_ane-*.whl
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from tinkerbox_ane import d1
|
|
17
|
+
|
|
18
|
+
with d1.load() as model:
|
|
19
|
+
result = model.system_one(
|
|
20
|
+
"I was charged twice this month.",
|
|
21
|
+
{"refund": {"type": "noul", "instructions": "Is this a refund request?"}},
|
|
22
|
+
)
|
|
23
|
+
print(result)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`load()` downloads the matching Core AI architecture from [wegotomars/d1-3B-CoreAI-ANE](https://huggingface.co/wegotomars/d1-3B-CoreAI-ANE) (`v1.0.0`) into `~/Library/Caches/tinkerbox-ane/d1/models/`. Pass a directory path to `load(path)` to select a local AOT bundle.
|
|
27
|
+
|
|
28
|
+
The API exposes `system_one`, `system_one_batch`, `probabilities`, and `probabilities_batch` for binary, choice, and score queries. Requests run sequentially. Prompts and images exceeding 32,768 rendered tokens are rejected.
|
|
29
|
+
|
|
30
|
+
## SwiftUI Demo
|
|
31
|
+
|
|
32
|
+
A desktop demo is available in [examples/swiftui](examples/swiftui). To build and launch it from source:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
uv run --no-project --python 3.12 python examples/swiftui/run.py
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Pass `--build-only` to create `artifacts/swiftui/Tinkerbox.app` and the release ZIP without launching. The prebuilt app manages its own Python environment and dependencies via an embedded `uv` binary.
|
|
39
|
+
|
|
40
|
+
## Architecture & Staging
|
|
41
|
+
|
|
42
|
+
The Swift host manages recurrent state and allocates attention cache buffers dynamically. Initial execution compiles and specializes the AOT asset for the local ANE hardware, after which Core AI reuses its persistent cache.
|
|
43
|
+
|
|
44
|
+
Weight staging uses an [APFS copy-on-write workaround](docs/cow-staging.md) to eliminate redundant disk writes during specialization.
|
|
45
|
+
|
|
46
|
+
## Building from Source
|
|
47
|
+
|
|
48
|
+
Building requires Xcode 27 / Swift 6.4 and [uv](https://docs.astral.sh/uv/):
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
uv sync --locked
|
|
52
|
+
uv build
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The wheel in `dist/` bundles the native host and links against macOS system frameworks. Attach it to the GitHub release. Source and editable installs compile the host during installation.
|
|
56
|
+
|
|
57
|
+
To export and compile model weights locally:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
uv run python -m tinkerbox_ane.d1.export
|
|
61
|
+
uv run python -m tinkerbox_ane.d1.compile
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Export writes `artifacts/build/d1_fp16_fused128_ctx32768`; compilation produces the final bundle in `artifacts/d1_fp16_fused128_ctx32768`. Load the local result with `d1.load(d1.DEFAULT_ASSET)`. Rebuilds require fresh `--out` directories.
|
|
65
|
+
|
|
66
|
+
Compilation verifies source identity, all nine functions, and ANE placement. Without cached sudo authentication, worker cancellation is best effort and emits a warning.
|
|
67
|
+
|
|
68
|
+
## Validation
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
uv run python scripts/build_reference.py
|
|
72
|
+
uv run python -m tinkerbox_ane.d1.guard artifacts/validation/check -- uv run python scripts/validate.py
|
|
73
|
+
uv run python -m tinkerbox_ane.d1.guard artifacts/validation/smoke -- uv run pytest -q
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Reference generation downloads benchmark inputs and runs the official FP32 CPU model. Validation checks prompt tokens and probabilities across all nine cache capacities. The two public API smoke tests require a local bundle and cached checkpoint.
|
|
77
|
+
|
|
78
|
+
Weights and upstream code are pinned to `LiquidAI/d1-3B@051bcc464b01b9f92942b364d9586b0ef5912432` under the [LFM Open License v1.0](LICENSES/LFM-Open-License-v1.0.txt). See [NOTICE](NOTICE).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ANE Copy-on-Write Staging
|
|
2
|
+
|
|
3
|
+
The native host uses APFS copy-on-write (CoW) clones to eliminate redundant copies of shared weight files during Core AI specialization on macOS 27.
|
|
4
|
+
|
|
5
|
+
## Background
|
|
6
|
+
|
|
7
|
+
Model constants frequently reference different byte offsets within a single large `resources.bin`. During on-device specialization, AppleNeuralEngine's staging service copies external weight files in an un-deduplicated per-constant loop without requesting APFS clones. When many constants share a backing file, this behavior causes repeated full-file copies and substantial I/O overhead.
|
|
8
|
+
|
|
9
|
+
Ahead-of-time (AOT) compilation does not bypass this step, as device-specific specialization still occurs on the host. This workaround intercepts compilation requests in the host process without modifying system services or changing `coreai-build`.
|
|
10
|
+
|
|
11
|
+
## Implementation
|
|
12
|
+
|
|
13
|
+
1. **Staging Directory Setup:** [host.py](../src/tinkerbox_ane/d1/host.py) creates a temporary `.d1host-*` directory adjacent to the model bundle to guarantee CoW clones remain on the same APFS volume. It exports paths via `COW_CLIENT_DEST` and `COW_ASSET_PREFIX`.
|
|
14
|
+
2. **Method Interception:** [host.swift](../src/tinkerbox_ane/d1/host.swift) initializes the hook before specialization begins. [cow-staging.m](../src/tinkerbox_ane/d1/cow-staging.m) swizzles `-[_ANEClient compileModel:options:qos:error:]` in the runtime process.
|
|
15
|
+
3. **Deduplicated Cloning:** For each unique backing file in the request, the hook creates a single clone using `COPYFILE_CLONE_FORCE` and verifies `COPYFILE_STATE_WAS_CLONED`.
|
|
16
|
+
4. **Descriptor Remapping:** It updates `externConstants.FileConstants` entries to point to the cloned files while preserving byte offsets and metadata, stripping obsolete sandbox extension tokens (`_SBExtension`).
|
|
17
|
+
5. **Preflight Validation:** The hook executes `_ANECloneHelper` to verify descriptor integrity before forwarding the modified request to the original compilation method.
|
|
18
|
+
|
|
19
|
+
Cloned files share existing storage blocks with the source bundle. The host cleans up the staging directory on shutdown.
|
|
20
|
+
|
|
21
|
+
## Constraints and Safety Checks
|
|
22
|
+
|
|
23
|
+
- **Volume Compatibility:** The model directory must reside on an APFS volume with write permissions and cloning enabled. If cloning fails, the host aborts immediately.
|
|
24
|
+
- **External Resource Limits:** Requests referencing files outside the designated asset prefix are permitted only if every backing file exists and is smaller than 64 MiB (accommodating small framework auxiliary graphs).
|
|
25
|
+
- **Fail-Safe Operation:** Any unexpected resource size, altered preflight descriptor, missing Objective-C symbol, or compilation failure terminates the host process.
|
|
26
|
+
- **Privileges:** The hook operates entirely within user space and requires no elevated privileges.
|
|
27
|
+
|
|
28
|
+
## Deprecation Criteria
|
|
29
|
+
|
|
30
|
+
This workaround should be removed once AppleNeuralEngine natively deduplicates shared backing files or Core AI provides a supported staging API. Removal requires verifying that cold-cache specialization completes without redundant disk writes across the full model bundle.
|