laya-mlx README

项目的 README,来自 github.com/mizorewww/laya-mlx。合并为一个 markdown 文件:README.md。

Laya-MLX

Open-weight typed decisions, running natively on Apple Silicon.

中文 · Usage reference · Benchmarks · Hugging Face weights · Changelog

Laya answers constrained questions (pick an option, score against a rubric, judge true or false) with calibrated probabilities from one bidirectional forward pass. It generates no tokens and returns no JSON to parse. This package runs the original Laya weights in MLX, without PyTorch, Transformers or a cloud API.

13.4 ms median for a short English decision, 7.4 ms with the multilingual checkpoint (M3 Max, FP16).

Laya MLX playing Snake: actual decisions at original speed

Quick start

Requires Apple Silicon, macOS 14+ and Python 3.11+.

pip install laya-mlx
import laya_mlx as laya

agent = laya.load("aac6fef/laya-mlx")
result = agent.predict(
    "I was billed twice. Please refund the duplicate.",
    {
        "department": {
            "type": "choice",
            "instructions": "Which department should handle this request?",
            "criteria": {
                "billing": "Payments, invoices, refunds, and duplicate charges.",
                "technical": "Broken features, errors, and product troubleshooting.",
                "sales": "Pricing, upgrades, and new purchases.",
            },
        },
        "refund": {
            "type": "noul",
            "instructions": "Does the customer ask for money back?",
        },
    },
)
print(result["answers"]["department"]["choice"])  # billing

Describing each option, as above, works much better than bare labels. The first load downloads the checkpoint; later inference is fully local.

Question types

Type You provide You get
choice Named options, as a list or a label → description dict Probability per option
score Ordered rubric levels Probability per level and the expected level
noul A yes/no proposition P(true)

States can be text, JSON-like dicts or conversation lists. Each answer carries calibrated probabilities and confidence fields; confidence does not guarantee accuracy on a new task.

Checkpoints

Pre-converted MLX (FP16) Original Parameters Context Use
aac6fef/laya-mlx convaiinnovations/laya 421M 512 English
aac6fef/laya-multilingual-mlx convaiinnovations/laya-multilingual 322M 1,024 Multilingual input
aac6fef/laya-typed-decisions-mlx convaiinnovations/laya-typed-decisions 421M 1,024 Upstream typed-decisions workflows

laya.load accepts either column. Context counts instructions, options and state together. Each published checkpoint includes its model card, validation results, provenance and checksums (pinned revisions and hashes).

What else it does

All of these are covered in the usage reference:

Performance

M3 Max (40-core GPU, 128 GiB), FP16, end to end:

Laya 421M Multilingual 322M
One short question, P50 / P95 13.42 / 13.92 ms 7.39 / 7.79 ms
50-question throughput 146.8 q/s 395.0 q/s
Peak MLX allocation, one question 943.6 MiB 687.6 MiB

Timings include prompt preparation, tokenization, inference, calibration and formatting; model loading is excluded. The throughput row uses batch_size=64 (the default is 16). Latency varies with input length, question count and system load.

All three checkpoints matched upstream's selected answer on 63/63 validation questions in FP32 and FP16 (378/378 comparisons), with deterministic repeated calls and no measured memory growth. That measures port fidelity on those fixtures, not task accuracy. Method, every timing sample and probability errors.

Snake demo

The GIF above is a real local run at original speed: every move asks Laya three questions, and a visible safety layer can override unsafe moves.

pip install 'laya-mlx[demo]'
hf download aac6fef/laya-multilingual-mlx
laya-snake                      # paced; add --max-speed to remove pacing
laya-snake --optimize --max-speed

The terminal must be at least 104 × 35. Space pauses, ↑/↓ changes speed, R resets, Q quits. With --optimize, the measured M3 Max run reached 75.4 moves/s over 2,400 moves with zero deaths. Demo guide · speed and stability · optimization.

Relationship to upstream

This is an independent port, not an official Convai Innovations release. Prompt formatting, calibration, routing, output schema and host APIs follow NandhaKishorM/laya v0.5.5; the encoder and decision heads are reimplemented in MLX. CUDA, ONNX, PyTorch backend controls, the vegaml engine and training are out of scope. RLCD training and fine-tuning stay upstream. Native boundaries · upstream compatibility record · all documentation.

Contributing

Bug reports and pull requests are welcome. Upstream-compatible fixes take priority over new features. See CONTRIBUTING.md for the development setup, tests, benchmarks and release process.

License

Apache-2.0; see LICENSE and NOTICE. Laya and its pretrained weights are by Convai Innovations and upstream contributors. The neural architecture follows Laya and Hugging Face ModernBERT.

laya-mlx (mizorewww/laya-mlx)

正在搜索数据库…

这是什么?Laya-MLX 是一个原生 MLX 运行时,可在 Apple Silicon 上本地运行开放权重的 Laya 类型化决策模型,以毫秒级速度返回结构化答案(如一个选项、一个量规评分或一个概率),而不是生成文本。
这是 Python 库还是独立应用?它是一个通过 laya.load(...) 安装和调用的 Python 库,另外还有一个终端 CLI 演示(laya-snake),展示模型进行实时决策。
怎么把它跑起来?先用 pip 安装(或安装 GitHub 上的最新版本),然后在 Python 中加载检查点;首次加载会从 Hugging Face 下载模型,之后的每次调用都完全在本地运行。
需要 PyTorch 或云端 API 密钥吗?不需要——你只需要 Apple Silicon、Python 3.11 及以上版本和 macOS 14 及以上版本;不涉及 PyTorch、Transformers 运行时或云端 API。
这是 Convai Innovations 的官方发布吗?不是,它是 Convai Innovations 的 Laya 模型的独立 MLX 移植版,并保留了上游的局限性:英文检查点不能替代多语言检查点,且高置信度并不保证准确。
它必须用 Apple Silicon,还是也能在 Intel Mac 上运行?它专为 macOS 14 及以上版本的 Apple Silicon Mac 构建;没有提到对 Intel Mac、Windows 或 Linux 的支持。
「typed decisions」是什么?Laya 在单次双向前向传播中回答受约束的问题,而不是生成文本:choice 给出各命名选项的概率,score 给出有序量规等级的概率,noul 给出命题为真的概率 P(true)。
Snake 演示是用来做什么的?laya-snake 是一个终端游戏,每一步移动都会调用 Laya 做实时决策,并带有一个可见的安全层,可以否决不安全的走法;它用于展示模型的实时运行,采用优化路径时可达每秒 75.40 步。
在 M3 Max 上推理有多快?英文检查点回答一个简短问题的端到端中位耗时为 13.42 毫秒,多语言检查点为 7.39 毫秒,且不生成任何输出 token。
支持哪些检查点?共三个:convaiinnovations/laya(英文,ModernBERT-large,4.21 亿参数)、convaiinnovations/laya-multilingual(mmBERT-base,3.22 亿)和 convaiinnovations/laya-typed-decisions(4.21 亿);预转换的 FP16 MLX 版本已发布在 Hugging Face 上。
作者
mizorewww
大小
7 MB
星标
7.1K
时长
2个月
提交 · 90 天