madewithlaya

Catalog / Tools & apps

0064GitHub

@r4ai/laya-web: client-side Laya-MLX inference with WebGPU and Wasm fallback

Browser runtime for Laya decisions on ONNX Runtime Web. WebGPU with SIMD Wasm fallback, Web Worker friendly, CPU embedding slicing to get past storage-buffer limits.

Open source ↗ github.comcostfree, client-sidetime-
r4ai/laya-webREADME ↗
# @r4ai/laya-web

[](LICENSE)
[](https://r4ai.github.io/laya-web/)
[](https://www.npmjs.com/package/@r4ai/laya-web)

Client-side inference runtime for [Laya-MLX](https://github.com/mizorewww/laya-mlx) decision models in the browser, powered by ONNX Runtime Web (WebGPU and WebAssembly SIMD).

Laya evaluates structured decisions (**typed decisions**) directly over input state or text without generating free-form text:

- **Categorical Choice (`choice`)**: Selects the best option from discrete candidate labels
- **Ordinal Scoring (`score`)**: Evaluates input against an ordered rubric or severity scale
- **Proposition Verification (`noul`)**: Computes the probability that a statement holds true

[Live Demo](https://r4ai.github.io/laya-web/)

## Key Features

- **100% Client-Side Inference**: Evaluates decisions entirely in the browser without sending input data to external servers
- **Web Worker Compatible**: Runs smoothly in dedicated Web Workers to keep the UI thread responsive at 60fps
- **WebGPU with Wasm Fallback**: WebGPU hardware acceleration with automatic fallback to single-threaded SIMD WebAssembly
- **CPU Embedding Slicing**: Slices FP16 embeddings on the CPU to bypass browser WebGPU storage buffer limits on large vocabularies (>128k tokens)
- **Calibrated Decision Confidence**: Computes normalized Shannon entropy ($0.0$ to $1.0$) for reliable uncertainty filtering

## Architecture

The library runs in both main threads and Web Workers. Hosting the agent inside a dedicated Web Worker isolates heavy tensor computation from the UI:

```mermaid
flowchart TD
    subgraph Host ["Browser Environment"]
        subgraph Main ["Main Thread (UI)"]
            App["Web Application"]
        end

        subgraph Worker ["Web Worker (Recommended)"]
            Agent["Agent (

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