madewithlaya

Catalog / Tools & apps

0055GitHub

Laya4j: pure-Java 17+ SDK for Laya on ONNX Runtime

Java port of Laya with choice/score/noul, a script-detecting router that picks the checkpoint, HuggingFace Hub fetching and bit-level parity with the Python ONNX output.

Open source ↗ github.comcostfree, localtime-
githubMJ/Laya4jREADME ↗
# Laya4j

Java SDK for **Laya** System 1 decision models — fast, non-autoregressive, calibrated decisions
in a single forward pass. Targets Apache 2.0 multilingual checkpoints via ONNX Runtime.

---

## 特性

- **多语种**:100+ 语言(通过 `laya-multilingual` checkpoint)
- **三种决策原语**:`choice`(分类)/ `score`(序数)/ `noul`(是/否概率)
- **校准的置信度**:基于 RLCD(proper scoring rule)训练,概率可直接用
- **零 Python 依赖**:纯 Java + ONNX Runtime + HuggingFace Hub
- **可路由**:内置 ScriptDetector 模拟 laya.Router,自动选择 checkpoint
- **bit-级 Python 对齐**:经过验证 Java 输出与 Python ONNX Runtime 完全一致

---

## 项目结构

```
Laya4j/
├── pom.xml                              # Maven 17 + ORT 1.19.2 + DJL 0.30 + JUnit 5
├── README.md
├── src/
│   ├── main/java/com/laya4j/
│   │   ├── MainApplication.java         # 端到端 demo 入口(5 个 Test)
│   │   ├── core/       # 9 文件: Question/Decision/DecisionType/RoutingDecision/LayaConfig/LayaException
│   │   ├── model/      # 3 文件: LayaOnnxModel / SequenceBuilder / HuggingFaceFetcher
│   │   ├── router/     # 2 文件: ScriptDetector / LayaRouter
│   │   ├── predict/    # 2 文件: LayaPredictor / Presets
│   │   └── benchmark/   # 1 文件: Benchmark
│   └── test/java/com/laya4j/
│       ├── core/QuestionTest.java          # 9 测试
│       ├── core/DecisionTest.java          # 4 测试
│       ├── predict/PresetsTest.java        # 4 测试
│       ├── router/ScriptDetectorTest.java  # 11 测试(8 语言)
│       └── model/SequenceBuilderAlignmentTest.java  # 6 测试(Python 对齐)
└── models/                              # 打包好的模型权重(1.2 GB)
    ├── VERSION.md                       # 版本对应文档
    ├── rl_agent_config.json             # decision head 配置
    ├── laya-decision-multilingual-mmbert-base-v0.3.4-1c5edc1.onnx   # FP32 满血版
    └── tokenizer/                       # mmBERT byte-level BPE
        ├── tokenizer.json                # 33 MB
 

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