Use English model card by default and link Chinese translation
Browse files- README.md +61 -60
- README.zh-CN.md +165 -0
- SHA256SUMS +17 -16
README.md
CHANGED
|
@@ -15,29 +15,29 @@ tags:
|
|
| 15 |
|
| 16 |
# Vela3-fast Core AI — experimental decision graph
|
| 17 |
|
| 18 |
-
|
| 19 |
-
本仓库发布的是经过验证的 **choice / noul 决策主干**:单样本、总长度最多 128 tokens、恰好两个选项。
|
| 20 |
-
**这是实验性子集,不是包含所有任务 adapter 的完整 Vela3-fast。**
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
-
- `noul`:固定 `no` / `yes` 两个选项,返回 `p(yes)`。
|
| 29 |
-
- 输入正文、问题、选项描述和特殊标记合计不超过 **128 tokens**;超长输入报错,不截断。
|
| 30 |
-
- 每次推理一个问题,batch size 为 1。Python 适配器支持文本或按上游规则序列化的 JSON 对象。
|
| 31 |
-
- CPU 模式已验证。自动设备模式此前因测试主机资源压力未完成验证,不宣称 GPU/ANE 性能。
|
| 32 |
-
- 原始 FP32 决策权重,无量化、训练或微调。
|
| 33 |
-
- 原模型的 router、span、relation、NER、evidence、domain/factcheck/feedback 等 adapter 不包含在此制品中;
|
| 34 |
-
超过两个选项、长上下文和完整 `system_one` 路由也不受支持。未测试不代表这些能力无法转换。
|
| 35 |
-
- 不提供完整 `hugging_mac_sdk` 模型注册或生产验收结论。概率是给定选项间的相对值,不是校准置信度。
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
```bash
|
| 43 |
uvx --from huggingface-hub hf download hugging-mac/vela3-fast-CoreAI --local-dir vela3-fast-CoreAI
|
|
@@ -51,10 +51,10 @@ import asyncio
|
|
| 51 |
from vela_coreai import VelaCoreAI
|
| 52 |
|
| 53 |
async def main():
|
| 54 |
-
#
|
| 55 |
async with VelaCoreAI.open(".") as model:
|
| 56 |
result = await model.predict(
|
| 57 |
-
"
|
| 58 |
{
|
| 59 |
"type": "choice",
|
| 60 |
"instructions": "What is the topic?",
|
|
@@ -72,33 +72,34 @@ async def main():
|
|
| 72 |
asyncio.run(main())
|
| 73 |
```
|
| 74 |
|
| 75 |
-
`predict`
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
|
| 80 |
```bash
|
| 81 |
USE_OS_COREAI=1 uv run --locked python smoke.py
|
| 82 |
```
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
|
| 87 |
-
## Swift
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
**Swift
|
| 92 |
|
| 93 |
```bash
|
| 94 |
-
#
|
| 95 |
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \
|
| 96 |
xcrun swiftc -parse-as-library -target arm64-apple-macos27.0 \
|
| 97 |
verify_coreai.swift -o /tmp/verify-vela
|
| 98 |
/tmp/verify-vela "$PWD"
|
| 99 |
```
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
```swift
|
| 104 |
import CoreAI
|
|
@@ -111,53 +112,53 @@ let model = try await AIModel(
|
|
| 111 |
guard let function = try model.loadFunction(named: "main") else {
|
| 112 |
fatalError("Missing main function")
|
| 113 |
}
|
| 114 |
-
// inputs: [String: NDArray]
|
| 115 |
var result = try await function.run(inputs: inputs)
|
| 116 |
guard let logits = result.remove("logits")?.ndArray else {
|
| 117 |
fatalError("Missing logits")
|
| 118 |
}
|
| 119 |
-
//
|
| 120 |
```
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
|
| 125 |
-
##
|
| 126 |
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
|
| 130 |
| --- | --- | --- | --- |
|
| 131 |
-
| `input_ids` | int32 | `[1,128]` |
|
| 132 |
-
| `attention_mask` | int32 | `[1,128]` |
|
| 133 |
-
| `option_positions` | int32 | `[1,2]` |
|
| 134 |
-
| `pool_mask` | float32 | `[1,128]` | `[SEG_user]`
|
| 135 |
-
| `logits`
|
| 136 |
|
| 137 |
-
|
| 138 |
|
| 139 |
```text
|
| 140 |
[BOS] [Q] instructions [O] key_1: description_1 [O] key_2: description_2
|
| 141 |
[SEP_SCHEMA] [SEG_user] state [EOS]
|
| 142 |
```
|
| 143 |
|
| 144 |
-
##
|
| 145 |
|
| 146 |
-
-
|
| 147 |
-
-
|
| 148 |
-
-
|
| 149 |
-
- Swift CPU
|
| 150 |
-
-
|
| 151 |
-
-
|
| 152 |
-
-
|
| 153 |
-
早期自动设备验证中止,后续在同一制品上完成 CPU 评测;没有把中止记录改写成成功。
|
| 154 |
|
| 155 |
-
|
| 156 |
-
`SHA256SUMS`
|
| 157 |
|
| 158 |
-
##
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
| 15 |
|
| 16 |
# Vela3-fast Core AI — experimental decision graph
|
| 17 |
|
| 18 |
+
English | [简体中文](README.zh-CN.md)
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
An Apple Core AI conversion of [vllm-sr/vela3-fast](https://huggingface.co/vllm-sr/vela3-fast) by hugging-mac.
|
| 21 |
+
This release contains the validated **choice / noul decision backbone**: one sample, at most 128 tokens in total, and exactly two options.
|
| 22 |
+
**It is an experimental subset, not the complete Vela3-fast model with all task adapters.**
|
| 23 |
|
| 24 |
+
Neural inference runs through Core AI, with host-side tokenization and response formatting. The model does not generate text.
|
| 25 |
|
| 26 |
+
## Supported contract
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
- `choice`: two ordered options; returns their probabilities and the selected option.
|
| 29 |
+
- `noul`: fixed `no` / `yes` options; returns `p(yes)`.
|
| 30 |
+
- The input text, question, option descriptions, and special markers together must fit within **128 tokens**. Longer inputs raise an error; they are not truncated.
|
| 31 |
+
- One question per inference, with batch size 1. The Python adapter accepts text or JSON objects serialized according to upstream rules.
|
| 32 |
+
- CPU execution is validated. Earlier automatic-device validation did not finish because of resource pressure on the test host; no GPU/ANE performance is claimed.
|
| 33 |
+
- Original FP32 decision weights, with no quantization, training, or fine-tuning.
|
| 34 |
+
- Router, span, relation, NER, evidence, domain/factcheck/feedback, and other upstream adapters are not included. More than two options, long contexts, and full `system_one` routing are not supported by this artifact. Untested capabilities are not known to be unconvertible.
|
| 35 |
+
- This release does not provide complete `hugging_mac_sdk` registration or production acceptance. Probabilities are relative to the supplied options, not calibrated confidence scores.
|
| 36 |
|
| 37 |
+
## Python usage
|
| 38 |
+
|
| 39 |
+
Validated on Apple Silicon, macOS 27.2.1, Python 3.12.13, and `coreai-core==1.0.0b3`.
|
| 40 |
+
A macOS version supporting the Core AI system runtime is required. The example environment uses uv and **does not require PyTorch, transformers, or the original safetensors weights**.
|
| 41 |
|
| 42 |
```bash
|
| 43 |
uvx --from huggingface-hub hf download hugging-mac/vela3-fast-CoreAI --local-dir vela3-fast-CoreAI
|
|
|
|
| 51 |
from vela_coreai import VelaCoreAI
|
| 52 |
|
| 53 |
async def main():
|
| 54 |
+
# Point to the downloaded repository; the adapter explicitly uses CPU mode.
|
| 55 |
async with VelaCoreAI.open(".") as model:
|
| 56 |
result = await model.predict(
|
| 57 |
+
"Write a Python sorting function.",
|
| 58 |
{
|
| 59 |
"type": "choice",
|
| 60 |
"instructions": "What is the topic?",
|
|
|
|
| 72 |
asyncio.run(main())
|
| 73 |
```
|
| 74 |
|
| 75 |
+
`predict` prepares token IDs, marker positions, and the pooling mask before calling Core AI.
|
| 76 |
+
Each instance accepts one inference request at a time; await completion before making another call.
|
| 77 |
+
Unknown tasks, invalid option counts, and inputs exceeding the token limit raise errors.
|
| 78 |
|
| 79 |
+
Run the standalone package checks:
|
| 80 |
|
| 81 |
```bash
|
| 82 |
USE_OS_COREAI=1 uv run --locked python smoke.py
|
| 83 |
```
|
| 84 |
|
| 85 |
+
This compares six cases with upstream reference probabilities, checks exact input-tensor equality against upstream encoding,
|
| 86 |
+
and verifies rejection of five invalid-request categories. It writes `package_smoke.json` and `swift_fixture.json` for the Swift example.
|
| 87 |
|
| 88 |
+
## Swift usage
|
| 89 |
|
| 90 |
+
Requires Xcode 27 / the macOS 27 SDK or newer. `verify_coreai.swift` is a complete, compilable example that
|
| 91 |
+
loads pretokenized inputs from `swift_fixture.json`, runs native `CoreAI` inference, and compares probabilities with Python.
|
| 92 |
+
**The Swift example demonstrates native model invocation; it does not include a Swift tokenizer or a complete SDK for arbitrary text inputs.**
|
| 93 |
|
| 94 |
```bash
|
| 95 |
+
# Run inside the model directory. Adjust DEVELOPER_DIR if Xcode is installed elsewhere.
|
| 96 |
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \
|
| 97 |
xcrun swiftc -parse-as-library -target arm64-apple-macos27.0 \
|
| 98 |
verify_coreai.swift -o /tmp/verify-vela
|
| 99 |
/tmp/verify-vela "$PWD"
|
| 100 |
```
|
| 101 |
|
| 102 |
+
The core invocation is shown below; see `verify_coreai.swift` for complete tensor construction:
|
| 103 |
|
| 104 |
```swift
|
| 105 |
import CoreAI
|
|
|
|
| 112 |
guard let function = try model.loadFunction(named: "main") else {
|
| 113 |
fatalError("Missing main function")
|
| 114 |
}
|
| 115 |
+
// inputs: [String: NDArray], following the dtypes, shapes, and encoding rules below.
|
| 116 |
var result = try await function.run(inputs: inputs)
|
| 117 |
guard let logits = result.remove("logits")?.ndArray else {
|
| 118 |
fatalError("Missing logits")
|
| 119 |
}
|
| 120 |
+
// Apply stable softmax to the two logits and interpret them in input-option order.
|
| 121 |
```
|
| 122 |
|
| 123 |
+
For new text, reuse `tokenizer.json`, `decision.json`, and the encoding rules in `vela_coreai.py`.
|
| 124 |
+
Tokenizing only the input body does not produce valid model inputs. The bundled fixture is a synthetic example and contains no user data.
|
| 125 |
|
| 126 |
+
## Tensor interface
|
| 127 |
|
| 128 |
+
Entry point: `main`. No persistent recurrent/KV state. Inputs are right-padded to 128 tokens.
|
| 129 |
|
| 130 |
+
| Name | Type | Shape | Meaning |
|
| 131 |
| --- | --- | --- | --- |
|
| 132 |
+
| `input_ids` | int32 | `[1,128]` | Complete question/options/body sequence |
|
| 133 |
+
| `attention_mask` | int32 | `[1,128]` | 1 for valid tokens, 0 for padding |
|
| 134 |
+
| `option_positions` | int32 | `[1,2]` | Positions of the two `[O]` markers |
|
| 135 |
+
| `pool_mask` | float32 | `[1,128]` | 1 from `[SEG_user]` through the end of the body, excluding EOS |
|
| 136 |
+
| `logits` (output) | float32 | `[1,2]` | Unnormalized scores for the two ordered options |
|
| 137 |
|
| 138 |
+
Upstream sequence format:
|
| 139 |
|
| 140 |
```text
|
| 141 |
[BOS] [Q] instructions [O] key_1: description_1 [O] key_2: description_2
|
| 142 |
[SEP_SCHEMA] [SEG_user] state [EOS]
|
| 143 |
```
|
| 144 |
|
| 145 |
+
## Validation and limitations
|
| 146 |
|
| 147 |
+
- **6/6** text cases matched the original model's decisions and the expected answers.
|
| 148 |
+
- Maximum absolute probability error was approximately **5.57e-7**. Validation uses `atol=0.02, rtol=0.02` and also requires decision agreement.
|
| 149 |
+
- The standalone Python package passed all six cases without PyTorch installed, with exact input-tensor parity against upstream.
|
| 150 |
+
- Native Swift CPU results are in `swift_smoke.json`; standalone Python results are in `package_smoke.json`.
|
| 151 |
+
- Six handcrafted examples are not a general accuracy benchmark. JSON-object encoding is supported but was not separately evaluated in these six semantic cases.
|
| 152 |
+
- iPhone/iPad, iOS AOT, automatic device selection, GPU/ANE placement, long contexts, and other upstream tasks have not been validated.
|
| 153 |
+
- Export and runtime environments differ; their versions are recorded in `manifest.json` and `environment.json`. Earlier automatic-device validation was interrupted; subsequent CPU evaluation used the same artifact. The interrupted result was not rewritten as a success.
|
|
|
|
| 154 |
|
| 155 |
+
Full cases and probabilities: `validation_cases.json` and `evaluation.json`.
|
| 156 |
+
`SHA256SUMS` covers the published files. Original weight copies, development caches, and virtual environments are not uploaded.
|
| 157 |
|
| 158 |
+
## Attribution and license
|
| 159 |
|
| 160 |
+
Upstream: [vllm-sr/vela3-fast](https://huggingface.co/vllm-sr/vela3-fast/tree/fa60e3aa41132c60bf05a84cabfdced39cb6d4f7),
|
| 161 |
+
pinned to commit `fa60e3aa41132c60bf05a84cabfdced39cb6d4f7`, under Apache-2.0.
|
| 162 |
+
The converted graph and input rendering adapt `vela3_encoder.py` and `ub_d3_common.py` from that revision.
|
| 163 |
+
See `NOTICE` for attribution and modification details, and `LICENSE` for the license.
|
| 164 |
+
This is a hugging-mac community conversion, not an official release from Apple or the upstream team.
|
README.zh-CN.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- zh
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
base_model: vllm-sr/vela3-fast
|
| 7 |
+
pipeline_tag: zero-shot-classification
|
| 8 |
+
tags:
|
| 9 |
+
- coreai
|
| 10 |
+
- apple-silicon
|
| 11 |
+
- aimodel
|
| 12 |
+
- experimental
|
| 13 |
+
- decision-model
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Vela3-fast Core AI — 实验性决策图
|
| 17 |
+
|
| 18 |
+
[English](README.md) | 简体中文
|
| 19 |
+
|
| 20 |
+
由 hugging-mac 从 [vllm-sr/vela3-fast](https://huggingface.co/vllm-sr/vela3-fast) 转换的 Apple Core AI 模型。
|
| 21 |
+
本仓库发布的是经过验证的 **choice / noul 决策主干**:单样本、总长度最多 128 tokens、恰好两个选项。
|
| 22 |
+
**这是实验性子集,不是包含所有任务 adapter 的完整 Vela3-fast。**
|
| 23 |
+
|
| 24 |
+
This is an experimental, fixed-shape decision-backbone export, not a complete replacement for upstream Vela3-fast.
|
| 25 |
+
It runs neural inference through Core AI with host-side tokenization and response formatting. It does not generate text.
|
| 26 |
+
|
| 27 |
+
## 支持范围 / Contract
|
| 28 |
+
|
| 29 |
+
- `choice`:两个有序选项,返回选项概率和选择结果。
|
| 30 |
+
- `noul`:固定 `no` / `yes` 两个选项,返回 `p(yes)`。
|
| 31 |
+
- 输入正文、问题、选项描述和特殊标记合计不超过 **128 tokens**;超长输入报错,不截断。
|
| 32 |
+
- 每次推理一个问题,batch size 为 1。Python 适配器支持文本或按上游规则序列化的 JSON 对象。
|
| 33 |
+
- CPU 模式已验证。自动设备模式此前因测试主机资源压力未完成验证,不宣称 GPU/ANE 性能。
|
| 34 |
+
- 原始 FP32 决策权重,无量化、训练或微调。
|
| 35 |
+
- 原模型的 router、span、relation、NER、evidence、domain/factcheck/feedback 等 adapter 不包含在此制品中;
|
| 36 |
+
超过两个选项、长上下文和完整 `system_one` 路由也不受支持。未测试不代表这些能力无法转换。
|
| 37 |
+
- 不提供完整 `hugging_mac_sdk` 模型注册或生产验收结论。概率是给定选项间的相对值,不是校准置信度。
|
| 38 |
+
|
| 39 |
+
## Python 基本调用
|
| 40 |
+
|
| 41 |
+
验证环境:Apple Silicon、macOS 27.2.1、Python 3.12.13、`coreai-core==1.0.0b3`。
|
| 42 |
+
需要支持 Core AI 系统运行时的 macOS。示例环境使用 uv 管理,**不需要 PyTorch、transformers 或原始 safetensors 权重**。
|
| 43 |
+
|
| 44 |
+
```bash
|
| 45 |
+
uvx --from huggingface-hub hf download hugging-mac/vela3-fast-CoreAI --local-dir vela3-fast-CoreAI
|
| 46 |
+
cd vela3-fast-CoreAI
|
| 47 |
+
uv sync --locked
|
| 48 |
+
USE_OS_COREAI=1 uv run --locked python example.py
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
```python
|
| 52 |
+
import asyncio
|
| 53 |
+
from vela_coreai import VelaCoreAI
|
| 54 |
+
|
| 55 |
+
async def main():
|
| 56 |
+
# root 指向下载后的仓库目录;适配器显式使用已验证的 CPU 模式。
|
| 57 |
+
async with VelaCoreAI.open(".") as model:
|
| 58 |
+
result = await model.predict(
|
| 59 |
+
"请写一个 Python 排序函数。",
|
| 60 |
+
{
|
| 61 |
+
"type": "choice",
|
| 62 |
+
"instructions": "What is the topic?",
|
| 63 |
+
"criteria": {"coding": "Software", "cooking": "Food"},
|
| 64 |
+
},
|
| 65 |
+
)
|
| 66 |
+
print(result) # type, choice, probabilities
|
| 67 |
+
|
| 68 |
+
yes_no = await model.predict(
|
| 69 |
+
"Python code",
|
| 70 |
+
{"type": "noul", "instructions": "Is this about software?"},
|
| 71 |
+
)
|
| 72 |
+
print(yes_no) # {"type": "noul", "noul": p_yes}
|
| 73 |
+
|
| 74 |
+
asyncio.run(main())
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
`predict` 执行 tokenizer、标记位置和 pooling mask 的准备,再调用 Core AI。
|
| 78 |
+
同一个实例一次只接收一个推理请求;请等待前一次调用完成。未知任务、错误选项数和超长输入都会报错。
|
| 79 |
+
|
| 80 |
+
运行独立包验证:
|
| 81 |
+
|
| 82 |
+
```bash
|
| 83 |
+
USE_OS_COREAI=1 uv run --locked python smoke.py
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
该脚本比较六个用例与上游参考概率,校验输入张量与上游编码完全相同,验证五类无效请求拒绝行为,
|
| 87 |
+
并生成 `package_smoke.json` 和用于 Swift 的 `swift_fixture.json`。
|
| 88 |
+
|
| 89 |
+
## Swift 基本调用
|
| 90 |
+
|
| 91 |
+
需要 Xcode 27 / macOS 27 SDK 或更新版本。本仓库的 `verify_coreai.swift` 是完整、可编译的示例,
|
| 92 |
+
从 `swift_fixture.json` 加载一组预分词输入,用原生 `CoreAI` 执行,并与 Python 概率比较。
|
| 93 |
+
**Swift 示例演示原生模型调用,不包含 Swift tokenizer;它不是任意文本输入的完整 Swift SDK。**
|
| 94 |
+
|
| 95 |
+
```bash
|
| 96 |
+
# 在模型目录中执行;如 Xcode 安装位置不同,请调整 DEVELOPER_DIR。
|
| 97 |
+
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \
|
| 98 |
+
xcrun swiftc -parse-as-library -target arm64-apple-macos27.0 \
|
| 99 |
+
verify_coreai.swift -o /tmp/verify-vela
|
| 100 |
+
/tmp/verify-vela "$PWD"
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
核心调用如下,完整张量构造见 `verify_coreai.swift`:
|
| 104 |
+
|
| 105 |
+
```swift
|
| 106 |
+
import CoreAI
|
| 107 |
+
import Foundation
|
| 108 |
+
|
| 109 |
+
let model = try await AIModel(
|
| 110 |
+
contentsOf: modelDirectory.appendingPathComponent("model.aimodel"),
|
| 111 |
+
options: .cpuOnly
|
| 112 |
+
)
|
| 113 |
+
guard let function = try model.loadFunction(named: "main") else {
|
| 114 |
+
fatalError("Missing main function")
|
| 115 |
+
}
|
| 116 |
+
// inputs: [String: NDArray],按下表的 dtype、shape 和编码规则构造。
|
| 117 |
+
var result = try await function.run(inputs: inputs)
|
| 118 |
+
guard let logits = result.remove("logits")?.ndArray else {
|
| 119 |
+
fatalError("Missing logits")
|
| 120 |
+
}
|
| 121 |
+
// 对两个 logits 计算稳定 softmax,按输入选项顺序解释概率。
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
对任意新文本调用时,必须���用本仓库 `tokenizer.json`、`decision.json` 和 `vela_coreai.py` 的编码规则;
|
| 125 |
+
只对正文单独分词无法构造正确输入。随包 fixture 是人工示例,不包含用户数据。
|
| 126 |
+
|
| 127 |
+
## 张量接口
|
| 128 |
+
|
| 129 |
+
入口:`main`,无持久 recurrent/KV 状态。右侧补齐到 128 tokens。
|
| 130 |
+
|
| 131 |
+
| 名称 | 类型 | 形状 | 含义 |
|
| 132 |
+
| --- | --- | --- | --- |
|
| 133 |
+
| `input_ids` | int32 | `[1,128]` | 完整问题/选项/正文序列 |
|
| 134 |
+
| `attention_mask` | int32 | `[1,128]` | 有效 token 为 1,padding 为 0 |
|
| 135 |
+
| `option_positions` | int32 | `[1,2]` | 两个 `[O]` 标记的位置 |
|
| 136 |
+
| `pool_mask` | float32 | `[1,128]` | `[SEG_user]` 到正文末尾为 1,不包括 EOS |
|
| 137 |
+
| `logits`(输出) | float32 | `[1,2]` | 对应两个有序选项的未归一化分数 |
|
| 138 |
+
|
| 139 |
+
上游序列格式:
|
| 140 |
+
|
| 141 |
+
```text
|
| 142 |
+
[BOS] [Q] instructions [O] key_1: description_1 [O] key_2: description_2
|
| 143 |
+
[SEP_SCHEMA] [SEG_user] state [EOS]
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
## 验证记录与限制
|
| 147 |
+
|
| 148 |
+
- 对上游原始模型的 **6/6** 文本用例,转换后决策全部一致,预期答案全部正确。
|
| 149 |
+
- 最大概率绝对误差约 **5.57e-7**;验证容差为 `atol=0.02, rtol=0.02`,同时要求决策一致。
|
| 150 |
+
- 独立 Python 包在未安装 PyTorch 的环境中通过六个用例,输入张量逐项匹配上游。
|
| 151 |
+
- Swift CPU 原生调用结果见 `swift_smoke.json`;Python 独立包记录见 `package_smoke.json`。
|
| 152 |
+
- 六个手工样例不是通用准确率基准;JSON 对象仅有编码支持,未在这组六个语义用例中单独评估。
|
| 153 |
+
- 未验证 iPhone/iPad、iOS AOT、自动设备模式、GPU/ANE 放置、长上下文或其他上游任务。
|
| 154 |
+
- 转换环境与运行环境的版本不同,分别记录在 `manifest.json` 与 `environment.json`。
|
| 155 |
+
早期自动设备验证中止,后续在同一制品上完成 CPU 评测;没有把中止记录改写成成功。
|
| 156 |
+
|
| 157 |
+
完整用例与概率:`validation_cases.json`、`evaluation.json`。
|
| 158 |
+
`SHA256SUMS` 覆盖发布文件;本仓库不上传原始权重副本、开发缓存或虚拟环境。
|
| 159 |
+
|
| 160 |
+
## 来源与许可证
|
| 161 |
+
|
| 162 |
+
上游:[vllm-sr/vela3-fast](https://huggingface.co/vllm-sr/vela3-fast/tree/fa60e3aa41132c60bf05a84cabfdced39cb6d4f7),
|
| 163 |
+
固定 commit `fa60e3aa41132c60bf05a84cabfdced39cb6d4f7`,Apache-2.0。
|
| 164 |
+
转换图与输入渲染改编自该版本的 `vela3_encoder.py` 和 `ub_d3_common.py`;归属与修改说明见 `NOTICE`,许可证见 `LICENSE`。
|
| 165 |
+
这是 hugging-mac 的社区转换,不是 Apple 或上游团队的官方发布。
|
SHA256SUMS
CHANGED
|
@@ -1,23 +1,24 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4 LICENSE
|
| 3 |
46710ad6644d63748efc1d91895ed2f7d039ddd3e4fe9caf7351f2f7a18ae448 NOTICE
|
| 4 |
-
|
| 5 |
-
1150af4f64b7cec72e35ad2ad06db180be009d5d18ed05903c2af21f2a85ece3 decision.json
|
| 6 |
-
e5800b20eaa3e72a09481cd4456051800b087f7c71466859c262e0c110d3df0a environment.json
|
| 7 |
-
c9c5b9a7a7f214d7e2fc1f2478139b47e82bf65f000ec64483f727d49b9046bd evaluation.json
|
| 8 |
-
83dd42bf29453dafe9ca9525e9f8085198dc01afee7338012643b900ed0ac57e example.py
|
| 9 |
-
91668d28adb713c2241894c42e8e5115cd49949b28a2e234fb321ff36fbbe49e manifest.json
|
| 10 |
-
f854ff014ef231c04a22951298a0c5560c68d951123b7943a9d232b34db6bee2 model.aimodel/main.hash
|
| 11 |
-
e759a2108bf439ee87b10940f26d61a4078853e02f97d181d34165ae086b45ce model.aimodel/main.mlirb
|
| 12 |
-
e9969e2a029f38890ec12496d8e5c2d46f90b6a7554de00fd84bc40db73c884c model.aimodel/metadata.json
|
| 13 |
-
aef579fd2a256ae0f9aa817d6c8476379e8b9801471e67e6ac4ce685a9c01eae package_smoke.json
|
| 14 |
fe8ebeab92a5ecbca37f7fd768d480c122ceee326f5ac78f2e02cbf8c42adb85 pyproject.toml
|
|
|
|
|
|
|
|
|
|
| 15 |
e21d2cd9f85b33194a0aefa2e69a572a80cc3d9e0497f4f793ef7afc813ca513 smoke.py
|
| 16 |
-
|
| 17 |
-
a42be9e045ef3544a8a74263b7c51b198c181dd6f044c922680ff7d8cd84ab0e swift_smoke.json
|
| 18 |
38734bb17ef19f84c67b5eb5692bea19801ffd02cb5c5ffc11429e76b0242e08 tokenizer.json
|
| 19 |
649781df90d51837dd6ba951a89fae07c985a9eacfd781d84002d480c3cb0b6e tokenizer_config.json
|
| 20 |
-
|
|
|
|
| 21 |
a37c2903b39eef663e4f644f924dc234d483e66af7bc229cc86e4f337cd86bd5 validation_cases.json
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
f6cd5f38bce95bd253b0d7bf4b4ac1f427c02e4a07dd7a8384fbd24f0bd98bab README.md
|
| 2 |
+
d8922e9a8a5d799abfae6ec063c04d1a1159ebe3813f62a6c0a4e3a0e188431c README.zh-CN.md
|
| 3 |
c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4 LICENSE
|
| 4 |
46710ad6644d63748efc1d91895ed2f7d039ddd3e4fe9caf7351f2f7a18ae448 NOTICE
|
| 5 |
+
7b55f8e67b5623c4bef3fa691288da9437d79d3aba156de48d481db32ac7d16d .python-version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
fe8ebeab92a5ecbca37f7fd768d480c122ceee326f5ac78f2e02cbf8c42adb85 pyproject.toml
|
| 7 |
+
2f622f1a164e966f012193787cc8325837d96c2bd33f62f7a704606f0d0e17a9 uv.lock
|
| 8 |
+
74444a35a0b888acf65e3ef9687577c1f1cfd664c2b071a2820408c22af5bc1f vela_coreai.py
|
| 9 |
+
83dd42bf29453dafe9ca9525e9f8085198dc01afee7338012643b900ed0ac57e example.py
|
| 10 |
e21d2cd9f85b33194a0aefa2e69a572a80cc3d9e0497f4f793ef7afc813ca513 smoke.py
|
| 11 |
+
c7364280e5c4173b277782fb403119f4485b4ea4fe441ca69b7d93bbe742491e verify_coreai.swift
|
|
|
|
| 12 |
38734bb17ef19f84c67b5eb5692bea19801ffd02cb5c5ffc11429e76b0242e08 tokenizer.json
|
| 13 |
649781df90d51837dd6ba951a89fae07c985a9eacfd781d84002d480c3cb0b6e tokenizer_config.json
|
| 14 |
+
1150af4f64b7cec72e35ad2ad06db180be009d5d18ed05903c2af21f2a85ece3 decision.json
|
| 15 |
+
91668d28adb713c2241894c42e8e5115cd49949b28a2e234fb321ff36fbbe49e manifest.json
|
| 16 |
a37c2903b39eef663e4f644f924dc234d483e66af7bc229cc86e4f337cd86bd5 validation_cases.json
|
| 17 |
+
c9c5b9a7a7f214d7e2fc1f2478139b47e82bf65f000ec64483f727d49b9046bd evaluation.json
|
| 18 |
+
e5800b20eaa3e72a09481cd4456051800b087f7c71466859c262e0c110d3df0a environment.json
|
| 19 |
+
aef579fd2a256ae0f9aa817d6c8476379e8b9801471e67e6ac4ce685a9c01eae package_smoke.json
|
| 20 |
+
71f4627d7ddd18d1c4ec86361d8cdb5558b2bbf6cba458fa3a093511761be37e swift_fixture.json
|
| 21 |
+
a42be9e045ef3544a8a74263b7c51b198c181dd6f044c922680ff7d8cd84ab0e swift_smoke.json
|
| 22 |
+
f854ff014ef231c04a22951298a0c5560c68d951123b7943a9d232b34db6bee2 model.aimodel/main.hash
|
| 23 |
+
e759a2108bf439ee87b10940f26d61a4078853e02f97d181d34165ae086b45ce model.aimodel/main.mlirb
|
| 24 |
+
e9969e2a029f38890ec12496d8e5c2d46f90b6a7554de00fd84bc40db73c884c model.aimodel/metadata.json
|