laya-coreml README

The project's README from github.com/mizorewww/laya-coreml. As one markdown file: README.md.

Laya-CoreML

Open-weight typed decisions on Apple Silicon: Core ML, Neural Engine, zero generated tokens.

中文 · Usage reference · Benchmarks · PyPI · 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 as Core ML programs on the CPU, GPU or Neural Engine. Inference needs no PyTorch, Transformers or MLX.

4.98 ms median for one short multilingual decision on the M3 Max Neural Engine, using 2.78× less system energy than compiled MLX.

Laya Core ML playing Snake with real local model probabilities

Quick start

Requires Apple Silicon, macOS 15+ and Python 3.11–3.13.

pip install laya-coreml
import laya_coreml as laya

agent = laya.load("aac6fef/laya-multilingual-coreml-adaptive-fp16")
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 bundle downloads before first use; predictions after that are local. Pass local_files_only=True to forbid network access.

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.

Model bundles

All bundles are under aac6fef/ on Hugging Face.

Bundle Engine Capacity Use
laya-multilingual-coreml-adaptive-fp16 (also -fp32) CPU + GPU 1,024 tokens, native batch 1/2/4/16 Recommended general multilingual model
laya-coreml-adaptive-fp16 / -fp32 CPU + GPU 512 tokens, native batch 1/2/4/16 English, 421M
laya-typed-decisions-coreml-adaptive-fp16 / -fp32 CPU + GPU 1,024 tokens, native batch 1/2/4/16 Upstream typed-decisions workflows
laya-coreml, laya-multilingual-coreml, laya-typed-decisions-coreml CPU + GPU 512 / 1,024 tokens, batch 1 Original single-graph bundles; Router() defaults
laya-multilingual-coreml-ane CPU + Neural Engine 96 tokens total, batch 1 Fastest short decisions, FP16
laya-multilingual-coreml-ane-w8 CPU + Neural Engine 96 tokens total, batch 1 Approximate 8-bit palette weights
laya-multilingual-coreml-snake CPU + GPU 64 tokens, batch 3 The Snake demo's three questions

The ANE bundles' 96-token limit covers question, options and state together. Longer state is truncated, while oversized questions or option sets raise. Every bundle includes its tokenizer, model card, provenance, checksums and validation results. Choosing a bundle, pinned revisions and offline use.

What else it does

All of these are covered in the usage reference:

Performance

M3 Max (40-core GPU, 128 GiB). One 91-token question padded to 96, end to end, from 65,598 stable calls in alternating 20-second blocks:

Compiled MLX FP16 Core ML ANE FP16 Core ML ANE W8
P50 / P95 6.94 / 7.39 ms 4.98 / 5.31 ms 4.88 / 5.23 ms
System energy per decision 0.4288 J 0.1540 J 0.1344 J
Speed / energy vs MLX 1× / 1× 1.39× / 2.78× 1.42× / 3.19×

Timings include prompt preparation, tokenization, inference, calibration and formatting; loading and warm-up are excluded. Energy comes from SMC power-sensor readings and is an estimate. The ANE advantage is for short inputs: a 1,024-token ANE graph takes about 91.7 ms, and a full Snake game is not consistently faster than compiled MLX. Speed, energy and hardware evidence · CPU/GPU benchmarks.

Port fidelity: the general bundles match upstream's selected answer on all 63 validation questions per checkpoint in FP32 and FP16, with 100 stable repeated calls each. The ANE FP16 bundle matches all 59 questions that fit in 96 tokens. These are conversion-fidelity checks, not task accuracy.

Snake demo

The GIF above replays a recorded Core ML run at 1× speed, with live probabilities, latency and a visible safety layer.

pip install 'laya-coreml[demo]'
hf download aac6fef/laya-multilingual-coreml-ane --local-dir models/snake
laya-coreml-snake --model ./models/snake

The terminal must be at least 104 × 35. Space pauses, ↑/↓ changes speed, R resets, Q quits. First Core ML initialization can take tens of seconds. The full loop sustained 49.1–50.0 decisions/s over three uncapped 600-step episodes with zero deaths. Demo guide · measured rates.

Relationship to upstream

This is an independent port, not an official Convai Innovations or Apple release. Prompt formatting, calibration, routing, output schema and host APIs follow NandhaKishorM/laya v0.5.10. Only the tensor, artifact, device and resource layers are Core ML-specific. Core ML bundles do not expose encoder embeddings; the vegaml engine (upstream's default since v0.5.0, and its Learner and Escalator) and training stay upstream; Agent() and load() here load the classic checkpoint. A sibling port for MLX is laya-mlx. Native boundaries · upstream compatibility record · all documentation.

Contributing

Bug reports and pull requests are welcome. Host behavior must stay traceable to upstream. See CONTRIBUTING.md for the development setup, tests, conversion and release process.

License

Apache-2.0; see LICENSE and NOTICE. Laya and its pretrained weights are by Convai Innovations and upstream contributors.

laya-coreml (mizorewww/laya-coreml)

Searching Database…

What is this?It's an open-weight Python port of Laya that answers typed questions — pick an option, an ordinal score, or yes/no — locally on Apple Silicon through Core ML and the Neural Engine, generating zero text tokens.
So is it a Python library I code against, or an app I run?A Python library: install laya-coreml from PyPI and call its Agent, ANEAgent and Router classes from code (a CLI is included). An optional terminal demo plays Snake with the model.
How do I get it running?pip install laya-coreml on an Apple Silicon Mac (macOS 15+, Python 3.11–3.13); model weights download from Hugging Face once. The optional Snake demo needs a 104-column × 35-row terminal.
Do I need PyTorch or Transformers installed as well?No. Inference needs no PyTorch, Transformers or MLX — those heavy frameworks are only for optional extras like temperature fitting, training helpers and converting your own checkpoints.
What's the catch with the fast Neural Engine mode?ANE bundles cap a request at 96 tokens total — question, options and state — and oversized inputs fail. Long text belongs in the 1024-token CPU+GPU bundles; the 1024-token ANE export measures about 91.7 ms per request, so ANE is for short decisions.
So this only runs on Macs?In practice yes: inference goes through Core ML and the Neural Engine, so you need an Apple Silicon Mac on macOS 15+. The repo's portable tests run on Linux CI, but actual Core ML inference is macOS-only.
Does it work offline, or does it send my questions somewhere?It works fully offline after a one-time model download from the Hugging Face hub; every prediction after that stays on your machine. Pass localfilesonly=True to require the existing cache.
Is the license permissive, and is this an official Apple or Convai release?Apache-2.0, so commercial use is fine. It's an independent community port of Laya (originally by Convai Innovations and contributors), not an official Convai or Apple release.
How fast is it, really?On an M3 Max, the ANE FP16 model answers a short question in 4.98 ms P50 / 5.31 ms P95, the W8 variant in 4.88 ms, versus 6.94 ms for compiled MLX FP16. Whole-system energy per decision is 2.78× better than MLX (3.19× with W8). These are single-question numbers, not full Snake frame times.
Which model bundles can I pull from Hugging Face?Six: the original English 421M (512-token context), a 322M multilingual and a 421M typed-decisions model (1024 tokens each), a Snake GPU bundle, and two Neural Engine multilingual variants — FP16 and an approximate W8 palette. Each ships tokenizer, config, model card, checksums and the tensors it needs.
Does the Core ML port answer exactly like the original model?On the validation fixtures, yes: the three general-purpose FP16 checkpoints matched upstream on 189/189 questions, each also passing 100 identical repeat calls. The ANE FP16 variant drifts at most about 0.003 in calibrated probability, W8 about 0.014, under a 0.02 gate — fixture fidelity, not proven task accuracy.
What does the Router class add?It keeps several Core ML bundles resident and routes each request to the right one, defaulting to multilingual when the language is undecided; route() inspects a request without loading weights. Answers can pass a minconfidence gate (default 0.7) that flags low-confidence results as abstentions, and large option sets go through tournament elimination.
Creator
mizorewww
Size
6.8 MB
Stars
1.6K
Age
2mo
Commits · 90 Days