Laya-CoreML 核心概念入门choice/score/noul 三种类型化决策一个 Token 都不生成【免费下载链接】laya-coremlLocal Laya typed decisions on Apple Core ML and Neural Engine. Validated ports, ~5 ms short decisions on M3 Max, reproducible speed and energy benchmarks.项目地址: https://gitcode.com/gh_mirrors/la/laya-coremlLaya-CoreML是一个运行在 Apple Silicon 上的开放权重类型化决策模型基于 Apple Core ML 与 Neural Engine 推理。它最独特的地方在于你问它问题它直接返回带概率的结构化答案——既不逐 Token 生成文本也不产出需要解析的 JSON。一次短决策在 M3 Max 上仅约5 毫秒且output_tokens永远是 0。什么是类型化决策为什么强调零 Token 生成传统大模型的决策流程是生成一段文本 → 你再去解析文本。而 Laya-CoreML 采用双向编码器结构输入一次编码完成没有自回归解码auto-regressive decoding环节模型输出的是每个候选选项的 logit直接 softmax 成概率分布结果是确定结构答案、概率、置信度一步到位。laya_coreml/result.py 中的system_one就是这个核心一次前向推理一次model.predict调用完成所有问题的打分返回的usage中output_tokens恒为 0。这意味着对比项文本生成式 LLMLaya-CoreML 类型化决策推理方式逐 Token 自回归解码单次前向编码输出自由文本需解析固定结构 概率输出 Token 数不定恒为 0短决策延迟通常数百毫秒起P50 约 4.98 msM3 Max ANE FP16运行依赖PyTorch / MLX 等纯 Core ML无需 PyTorch 所以一个 Token 都不生成不是营销话术而是架构决定的predict()返回的用量统计里输出 Token 数就写死为 0。三种类型化决策choice / score / noulLaya-CoreML 只支持三种问题类型在 laya_coreml/common.py 中定义为QTYPES {choice: 0, score: 1, noul: 2}。任何不属于这三类的type都会在 laya_coreml/prompt.py 的输入校验阶段直接报错。1. choice —— 多选一从若干候选标签中挑一个并给出每个标签的概率。适合工单分派、意图分类、动作选择。{ department: { type: choice, instructions: Which department should handle this request?, criteria: { billing: Payments, invoices, refunds, technical: Broken features, errors, sales: Pricing, new purchases } } }返回内容choice中选标签、probabilities各标签概率、confidence置信度。2. score —— 有序评分对一组有序档位打分返回期望档位值0 起始的类别指数望值和档位图例。适合紧急程度分级、满意度评分、风险等级。{ urgency: { type: score, instructions: How urgent is the request?, criteria: [not urgent, soon, critical deadline] } }返回内容score0~n-1 的期望值、legend档位说明、probabilities各档位概率。3. noul —— 布尔判断回答是 / 否模型输出 true 的概率。适合退款请求检测、条件校验、安全判断。{ refund: { type: noul, instructions: Does the customer request a refund? } }返回内容noultrue 的概率、confidence取该概率与 1 减去它的较大者。选项渲染固定为[false, true]见 laya_coreml/common.py 中的render_options。 三类答案都额外携带confidence基于归一化香农熵的置信度与 action head 概率字段可以直接用于低置信度转人工之类的业务门槛。三种类型如何配合贪吃蛇演示仓库里最直观的验证是终端贪吃蛇模型每一帧只回答三个问题——movechoice四个方向各带一句安全性描述选概率最高的方向risknoul是否存在安全通路foodnoul食物是否可达。见 laya_coreml/snake/policy.py其中还有显式的循环安全层模型提议的方向不安全时安全盾会接管执行一个安全方向并在界面上计入Shield interventions。完整游戏循环在三条 600 步测试中稳定达到49.1–50.0 决策/秒零死亡——这就是每帧 5 毫秒级类型化决策的实际效果。快速上手安装与一次调用需要 Apple Silicon macOS 15 Python 3.11–3.13python -m pip install laya-coremlimport laya_coreml as laya agent laya.load(aac6fef/laya-multilingual-coreml-ane) result agent.predict( The customer requests a refund of a duplicate payment., { department: { type: choice, instructions: Which department should handle this?, criteria: {billing: refunds, technical: errors, sales: pricing}, }, urgency: { type: score, instructions: How urgent is the request?, criteria: [low, medium, high], }, refund: { type: noul, instructions: Does the customer request a refund?, }, }, ) print(result[answers]) print(result[usage]) # {input_tokens: ..., output_tokens: 0}更完整的三种类型示例文件见 examples/questions.jsonAPI 细节见 docs/USAGE.md。推理不依赖 PyTorch、Transformers 或 MLX模型首次下载后可用local_files_onlyTrue完全离线运行。性能与模型选择M3 Max 实测短决策基准91-token 问题ANE FP16共 65,598 次稳定调用数据见 benchmarks/results指标MLX FP16Core ML ANE FP16P50 / P95 延迟6.94 / 7.39 ms4.98 / 5.31 ms每次决策整机能耗0.4288 J0.1540 J2.78× 改善模型容量选择96-token ANE 包laya-multilingual-coreml-ane最短、最快适合高频短决策超出预算会直接报容量错误1024-token 通用包laya-multilingual-coreml长输入多语言场景。完整模型表与设备引擎说明见 docs/USAGE.md 与 docs/ANE_BENCHMARKS.md。想深入看这些模块类型定义与提示词构造laya_coreml/common.py、laya_coreml/prompt.py概率输出与置信度计算laya_coreml/result.pyCore ML 加载与引擎选择laya_coreml/agent.py贪吃蛇策略choice noul 实战laya_coreml/snake/policy.py小结Laya-CoreML 把让模型做判断从文本生成问题变成了结构化的类型化决策问题choice做多选一、score做有序评分、noul做布尔判断一次前向推理直接拿到概率与置信度零输出 Token、约 5 毫秒延迟、纯 Core ML 离线运行。如果你的场景是高频分类、分级或条件判断这正是比通用 LLM 更省更快的一条路。【免费下载链接】laya-coremlLocal Laya typed decisions on Apple Core ML and Neural Engine. Validated ports, ~5 ms short decisions on M3 Max, reproducible speed and energy benchmarks.项目地址: https://gitcode.com/gh_mirrors/la/laya-coreml创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考