madewithlaya

Catalog / Tools & apps

0094GitHub

laya-pong: a browser paddle decided by Laya at 18.7 ms per frame on Metal

One typed question per frame; the other paddle is three lines of arithmetic as a control. Physics in WebAssembly, decisions in native Laya over POST /decide.

Open source ↗ github.comcostfree, localtime18.7 ms p50 on Metal (56% of a 30 fps frame)
aovestdipaperino/laya-pongREADME ↗
# laya-pong

A browser pong game whose left paddle is decided by [Laya](https://github.com/aovestdipaperino/laya-rust),
one typed question per frame. The right paddle is three lines of arithmetic, playing the same
ball, so you can watch the difference rather than take anyone's word for it.

The point of the demo is the clock, not the score. A 421M-parameter encoder answering a
`choice` question takes **18.7 ms p50 on Metal**, 56% of a 30 fps frame. Ask it the right way
and it matches the arithmetic paddle exactly; ask it the wrong way and it never moves. The
right-hand court is the control that keeps both claims honest.

## Why the model is not in the WebAssembly

The game is WebAssembly. The model is not, and that is deliberate:

- The checkpoint is 847 MB on disk and is upcast to f32 on load, so it wants ~2.4 GB resident.
  `wasm32` gives you a 4 GB address space and no Metal.
- Measured on CPU, one decision over a small state is 138 ms. That is 7 fps before you pay for
  a single-threaded wasm build, against a 33 ms budget.

So the split is: **WebAssembly owns the physics and writes the state down, native Laya owns the
decision.** The browser calls `POST /decide` once per frame and gets back a move.

## Building

You need Rust with the `wasm32-unknown-unknown` target and `wasm-pack`. The `laya` crate comes
in as a git dependency, so there is nothing else to clone.

```sh
git clone https://github.com/aovestdipaperino/laya-pong
cd laya-pong
```

Download the [checkpoint](https://huggingface.co/convaiinnovations/laya) into
`models/laya-base` (~847 MB, Apache-2.0, ungated):

```sh
mkdir -p models/laya-base/encoder models/laya-base/tokenizer
B=https://huggingface.co/convaiinnovations/laya/resolve/main
for f in model.safetensors encoder/config.json tokenizer/tokenizer.json

Also filed under Tools & apps

  1. 0005

    laya-mlx plays Snake at 60 decisions per second

    介绍比Jev快50倍,在你设备上跑的laya-mlx! 只在你的设备上占用最高1G内存 Laya是一个开源的类似于Jev的,基于文本输出概率的分类系统 我将其移植到MLX,并且做了一些性能优化! 视频中就是这个模型在我的本地M3Max上玩贪吃蛇 这个模型能够以每秒决策60次的速度玩贪吃蛇! https://t.co/31KGUiNunb

    @mizorewww · Tools & apps · free, local · 60 decisions/s

  2. 0112

    Laya on Axera AX650 and AX8850 edge NPUs, under 70 ms

    AXERA-TECH's conversion of all three Laya checkpoints for its edge AI chips, reported at latency under 70 ms per decision on AX650/AX8850.

    AXERA-TECH · Tools & apps · free, on-device · < 70 ms on AX650 / AX8850

  3. 0099

    laya-mcp (PerryLink): a warm sidecar that fixes Laya's silent truncation and constant noul

    MCP server plus HTTP sidecar: token-budget preflight that reports what would be cut, a persisted calibration store, structured errors, and a noul fix (P(true) 0.5 → 1.0).

    @PerryLink · Tools & apps · free, local

  4. 0097

    Gomoku against Laya-MLX: you play black, the model picks white's move from six candidates

    Local 15x15 Gomoku on Apple Silicon. Rules in Python, board in the browser, every AI move one real Laya choice over up to six candidates, probabilities shown. No Gomoku training.

    smile-magic · Tools & apps · free, local