社区 Runtime

Laya MPS(macOS)

面向 Apple GPU / MPS 的本地 runtime 与 HTTP server,提供多种内存模式与 benchmark 工具。

macOSApple GPU / MPSHTTP Serving内存调优
快速开始
git clone https://github.com/afshinm/laya-mps.git
cd laya-mps
./scripts/serve.sh
Source
afshinm/laya-mps

要求 Apple Silicon 与较新的 macOS,性能数字与具体硬件高度相关。

laya-mps 通过 PyTorch 的 Metal Performance Shaders(MPS) 后端在 Mac 的 GPU 上运行 Laya,以本地 HTTP 服务加浏览器 Demo 的形式提供,重点是低内存占用。

注意默认模型:它默认使用 laya-typed-decisions,也就是针对客服、发票、安全事件和 Agent trace 微调过的 checkpoint(这意味着什么)。想用通用英文模型,加 --checkpoint english。

环境要求

  • Apple Silicon Mac(M1 及以上),macOS 14+。
  • Git 和 uv;需要时 uv 会自动安装 Python 3.12。
  • 约 4 GB 可用磁盘,用于运行时、缓存和约 843 MB 的模型。

启动

git clone https://github.com/afshinm/laya-mps.git
cd laya-mps
./scripts/serve.sh

第一次运行会安装依赖并下载模型,之后可以离线运行。服务监听 127.0.0.1:8000,/demo/ 下有 Pong 游戏 Demo 和一个 60 秒的延迟测试。

内存模式(项目 README,M5 Pro,24 GiB)

模式进程内存峰值决策延迟中位数
minimal0.74 GiB171 ms
reduced(默认)2.11 GiB32 ms
full2.30 GiB32 ms

三种模式都以 FP32 运行完整模型,在 260 个决策上结果完全一致。minimal 从磁盘流式读取模型层,所以更慢。切换方式:./scripts/serve.sh --memory minimal。

API

curl -sS http://127.0.0.1:8000/v1/decisions \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "state": "The export page returns HTTP 500. Our team cannot finish its work.",
    "questions": {
      "owner": {"type": "choice",
                "instructions": "Which team should investigate this report?",
                "criteria": {"billing": "Payments and invoices",
                             "engineering": "Software failures"}}
    }
  }'
  • 接口:GET /health、GET /v1/config、POST /v1/decisions、GET /docs、GET /demo/。
  • 每次请求 1–16 个问题;choice 支持 2–26 个标签,score 支持 2–10 个 levels。
  • 加 ?metrics=true 返回耗时和内存,加 ?diagnostics=true 返回 token、温度和 logits。
  • 同一时间只跑一个推理,忙时返回 503 并带 Retry-After: 1。
  • 不能直接替代 Jev 接口:它有自己的路径、用 levels 字段表示评分等级,并有自己的限制。需要兼容 Jev 的 API,请看 Arbiter 或上游的 laya-serve。

命令行

uv run --locked laya-mps decide request.json 不启动服务就能评估一个请求;laya-mps doctor 检查 GPU 是否可用、模型是否就绪。

来源:afshinm/laya-mps · MIT(模型权重为 Apache 2.0)。

最后对照项目 README 核实:2026 年 9 月 24 日。