Instructions to use litert-community/Laya-Multilingual-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/Laya-Multilingual-LiteRT with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Laya
How to use litert-community/Laya-Multilingual-LiteRT with Laya:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Laya Multilingual for LiteRT β Android GPU and NPU
The files in this repository run the multilingual checkpoint of convaiinnovations/laya with LiteRT on a phone GPU or NPU and on a desktop CPU. Laya reads a text or a JSON state and answers each question you define at request time in one forward pass: pick one option, score on an ordinal scale, or give a yes/no probability. On a Samsung Galaxy S26 a 256-token question takes 51 ms of graph time on the GPU and 36 ms on the Hexagon NPU.
Screenshots of the Android sample in android/ on the Galaxy S26 GPU. The Japanese email
is invented and the probabilities are the model's. assets/demo.mp4
shows the same run.
The recommended files were validated with LiteRT 2.2.0 on a Galaxy S26 (SM-S942Q, Android 16) and a Pixel 11 Pro (Tensor G6, Android 17).
Minimal usage
Python on a desktop CPU
This block ran in an empty directory with Python 3.12 on macOS arm64. Its seven files are
about 680 MB. Neither torch nor the laya package is required.
python3 -m venv .venv && . .venv/bin/activate
pip install ai-edge-litert==2.1.6 ml-dtypes==0.6.0 transformers==5.17.0 tokenizers==0.23.2 numpy==2.5.3
export HF_HUB_DISABLE_XET=1
hf download litert-community/Laya-Multilingual-LiteRT laya_host.py tokenizer.json tokenizer_config.json \
laya_ml_s256_embeds_wfp16.tflite laya_ml_act_head_fp32.tflite laya_ml_calibration.json \
token_embeddings_fp16.bin --local-dir laya
cd laya
Save this as example.py and run python example.py.
import json
from pathlib import Path
from laya_host import LayaHost
assets = Path(".")
questions = {
"intent": {
"type": "choice",
"instructions": "What does the customer need?",
"criteria": {"refund": "money returned", "help": "technical help"},
}
}
with LayaHost(
tokenizer_dir=assets,
main_graph_path=assets / "laya_ml_s256_embeds_wfp16.tflite",
act_graph_path=assets / "laya_ml_act_head_fp32.tflite",
window=256,
head_max_len=256,
temperatures_json=assets / "laya_ml_calibration.json",
embeddings_path=assets / "token_embeddings_fp16.bin",
) as host:
result = host.predict("The same payment was charged twice. Please refund me.", questions)
print(json.dumps(result, ensure_ascii=False, indent=2))
After a LiteRT warning that no NPU accelerator was loaded, it printed:
{
"model": "laya-rl-agent",
"answers": {
"intent": {
"type": "choice",
"choice": "refund",
"probabilities": {
"refund": 0.9835,
"help": 0.0165
},
"confidence": 0.879,
"action": {
"act_probability": 1.0
}
}
},
"usage": {
"input_tokens": 34,
"output_tokens": 0
}
}
The same request in Japanese returned refund at 0.9954.
Kotlin on Android
android/README.md has the sample app's download, build, install and
NPU steps. LayaMinimalUsage.kt
is the shortest call: the GPU with explicit FP32, then prepare, runRaw and decode.
When it does not work
- No other phone was tested, and the NPU ran only on the Galaxy S26.
- On the GPU, request explicit FP32. Plain FP16 changed one of 81 answers, and FP16 with FP32 accumulation put one validation row over the 0.01 probability limit.
- On the NPU, package the Qualcomm runtime libraries that
android/README.mdlists. The first launch compiles for about 40 s. - Questions with more than 20 options were not validated, and the S512 graphs ran on desktop CPU only.
ai-edge-litert2.1.3 stopslaya_host.pyatImportError: cannot import name 'Options' from 'ai_edge_litert.compiled_model'. Version 2.1.6 withoutml-dtypesstops it atModuleNotFoundError: No module named 'ml_dtypes'.
Which package to take
| Package | Checkpoint | On the phone | GPU ms per question | App |
|---|---|---|---|---|
| this repository | multilingual, mmBERT-base | 0.68 GB | 51 (NPU 36) | Android sample in android/, also zero_shot_classification in litert-samples |
| Laya-English-LiteRT | English, ModernBERT-large, and its typed-decisions/ fine-tune |
0.85 GB each | 123 (fine-tune 126) | none; a Kotlin GPU function on its card |
| laya-LiteRT | the same two checkpoints without the fine-tune | 1.3 GB multilingual, 1.7 GB English | 54 multilingual, 127 English | none; laya_host.py and HOST_CONTRACT.md |
The times are graph time at 256 tokens on a Galaxy S26 GPU with LiteRT 2.2.0 and explicit FP32. The first two packages look up embedding rows in the app, which adds about 15β20 ms. laya-LiteRT takes token ids and keeps the table inside its fp32 graphs.
Take this repository for non-English or mixed text. The publisher lists 100+ languages, and English and Japanese were validated here. On XNLI English, Convai reports 0.843 for this checkpoint against 0.860 for the English one.
Files
| File | Window N | Bytes | Role |
|---|---|---|---|
laya_ml_s256_embeds_wfp16.tflite |
256 | 250,889,040 | recommended; validated on the S26 GPU, NPU and CPU |
laya_ml_s256_embeds_fp32.tflite |
256 | 500,970,372 | fp32 reference; validated on the S26 GPU |
laya_ml_s512_embeds_wfp16.tflite |
512 | 251,806,544 | longer texts; desktop CPU only |
laya_ml_s512_embeds_fp32.tflite |
512 | 501,887,876 | fp32 reference; desktop CPU only |
laya_ml_act_head_fp32.tflite |
any | 795,816 | act head, shared by every main graph |
token_embeddings_fp16.bin, token_embeddings.json |
393,216,801 | float16 token table [256000,768] |
|
tokenizer.json, tokenizer_config.json |
34,363,712 | from the source checkpoint | |
laya_ml_calibration.json |
9,074 | temperatures per question type and option count | |
fixtures/gate_rows_s256.json |
1,018,117 | 201 validation rows with reference answers |
The recommended phone set is the S256 wfp16 graph, the act head, the token table, the
tokenizer pair and the calibration file: 679,274,443 bytes. wfp16 files store the 99
FULLY_CONNECTED weight tensors as float16 with a DEQUANTIZE to float32, written by
ai-edge-quantizer 0.8.0 FLOAT_CASTING.
How the graphs are built
The main graph holds the encoder, Laya's two typed head layers and the option scorer. The
host tokenizes, builds the prompt with one <mask> marker per option, looks up the
embedding rows, reads the logits at the markers and applies softmax.
HOST_CONTRACT.md specifies each step.
The graphs take embedding rows, not token ids. With the token table inside the graph,
the float16-weight file does not compile on LiteRT 2.2.0 CompiledModel GPU: the delegate
rejects the EMBEDDING_LOOKUP that reads a DEQUANTIZE-fed table with
Empty quantization params. With the lookup on the host, the graph compiles on the
Galaxy S26 GPU as one partition of all 1809 operators in 1.3 s.
The graphs are safe to compute in fp16 since the revision of 2026-09-29. The NPU
computes in fp16, so three rewrites keep it finite. Each large LayerNorm computes on its
input scaled by a power of two, with epsilon scaled by the square, because values up to
1.4e4 overflow fp16 when squared. The attention masks use β1e4 instead of β1e9, which is
βinf in fp16. Layers 11 and 12 scale the rows of Wi that produce gate by 2^-4 and
Wo by 2^4.
The rewrites are exact in fp32. Without them every row was non-finite on the NPU and on the GPU at FP16.
Measured quality and performance
The reference is the official laya 0.3.4 predict on fp32 CPU at checkpoint revision
1c5edc17, with max_len set to the window. The inputs are 44 invented states, 21
English, 21 Japanese and 2 mixed, with the upstream presets, the upstream quickstart
schema and custom schemas of up to 20 options. That gives 201 question
rows, 81 choice or score and 120 yes/no, compared at temperature 1.
| Device, accelerator | Graph | Same argmax | Max probability difference | Median ms per question |
|---|---|---|---|---|
| S26 GPU FP32 | S256 wfp16 | 81/81 | 0.0014 | 51.9 |
| S26 NPU (Hexagon v81, JIT) | S256 wfp16 | 81/81 | 0.0069 | 36.5 |
| S26 GPU FP32, previous revision | S256 fp32 | 81/81 | 0.0001 | 50.8 |
| S26 CPU, previous revision | S256 wfp16 | 81/81 | 0.0014 | 163.0 |
| Desktop CPU | S256 and S512, wfp16 | 81/81 | 0.0014 | |
| Desktop CPU | S256 and S512, fp32 | 81/81 | 0.0001 |
The previous-revision rows were measured on 2026-09-21, before the fp16 rewrites. Desktop CPU is ai-edge-litert 2.1.6 on macOS arm64 with 4 threads.
On the Pixel 11 Pro the sample's debug build ran the same 201 rows on 2026-11-16, on the GPU with explicit FP32 and on the CPU. Both runs gave the reference token ids, marker positions and argmax on every row and a maximum probability difference of 0.0014.
The time per question covers both graphs, from writing the inputs to the end of output readback. It is the median of 200 rows after one cold call in the debug build on the Galaxy S26, with the screen on, no other workload and the battery at 35β37 Β°C. The host embedding lookup adds a median of 14.6 ms.
In the sample app a five-question email-triage run took 301 ms and 303 ms on the GPU in the non-debuggable build, and 257 ms and 268 ms on the NPU in the debug build. These are samples from one Snapdragon 8 Elite Gen 5 phone, not a benchmark across devices or thermal states.
Calibration
The upstream checkpoint ships with every temperature at 1. laya_ml_calibration.json
holds temperatures fitted here on 4,415 labeled English and Japanese examples from public
datasets, at 256 tokens. A temperature never changes which option wins.
| Bucket | Validation rows | Temperature | ECE at T=1 β shipped |
|---|---|---|---|
| choice, 2 options | 140 | 1.40 | 0.089 β 0.117 |
| choice, 3β5 | 150 | 1.36 | 0.154 β 0.087 |
| choice, 6β10 | 125 | 1.00 | 0.162 β 0.162 |
| choice, 11β20 | 108 | 2.45 | 0.383 β 0.120 |
| score, 3β5 levels | 161 | 3.68 | 0.257 β 0.087 |
| yes/no | 200 | 3.63 | 0.310 β 0.200 |
A bucket keeps T=1 when a fitted value makes either language worse by more than 0.05 ECE, as for 6β10 options. For 2 options the fit helps Japanese and costs English 0.03. Refit on your own data before you rely on the probabilities. Sources and licenses are in licenses/CALIBRATION_DATASETS.md.
Limits
- These numbers measure agreement with the upstream model, not task accuracy. On five
Japanese rows the upstream answer differs from the intended reading, for example a
veiled threat that scores 0.0 for
threat.HOST_CONTRACT.mdlists them. - The act probability was 1.0 on all 201 rows, upstream and here, so evaluate it yourself before using it as an escalation signal.
- The NPU libraries add about 40 MB to the APK.
Provenance and license
- Source:
convaiinnovations/laya, revision1c5edc17a7acd8701df6fc341c0d179f1c62c982, subfoldermultilingual/, loaded withlaya0.3.4 andtransformers5.17.0. - Conversion:
litert-torch0.9.3 withtorch2.12.1, fixed shapes, fp32, exact GELU.
The Laya checkpoint, its code and these converted files are Apache-2.0. mmBERT-base declares MIT. License texts are in licenses/, and attribution and the graph changes are in NOTICE. The calibration datasets keep their own terms, and none of their text is included here.
- Downloads last month
- 997
Model tree for litert-community/Laya-Multilingual-LiteRT
Base model
convaiinnovations/laya