An fp16 ONNX conversion of convaiinnovations/laya-typed-decisions for running in the browser with ONNX Runtime Web (WebGPU). Upstream is a ~400M-parameter ModernBERT-large encoder that scores typed decisions (choice / score / noul questions) in one forward pass.
Not an official release by the laya authors; they have not reviewed or endorsed it. For the original weights, use the upstream repo.
onnxruntime.transformers.float16.convert_float_to_float16, keep_io_types=True, so inputs and outputs stay fp32).Where(IsNaN(p), 0, p) rewritten as Where(Not(Equal(p, p)), 0, p). Same arithmetic; IsNaN has no WebGPU kernel and forced a GPU-to-CPU copy per layer, the replacement ops run on the WebGPU provider.Nothing else. No retraining, no fine-tuning, no pruning.
| check | result |
|---|---|
| Browser: Chrome 155, ONNX Runtime Web 1.31-dev, WebGPU, Apple Metal-3 | same top option as native fp32 on 47/47 recorded passes; max probability difference 0.021 |
| Native ONNX Runtime 1.30.0 CPU, 134-message subset, 23-node decision tree | 0 / 3,082 node-decision flips; final intent 134/134; probability delta mean 0.0001, max 0.0101 |
Limits: one GPU, one browser; the native check is a 134-message subset, not the full 616-message sample; the 47 browser passes are a small sample. This is not a general guarantee of fp32-identical behavior.
Observed speed on that GPU (machine under heavy load, so indicative only): about 52 ms per batch-1 forward pass.
| file | bytes | sha256 |
|---|---|---|
fp16/laya.fp16-nonan.onnx |
846,157,544 | 06405e8bae697839ee2654bef55b5fd26b3435ac479980e48da6cb6b777ce46a |
The graph takes token ids; tokenization and input construction (special tokens, marker positions, option layout) are done by the caller with laya's tokenizer and laya package from the upstream repo.
Inputs: input_ids int64 [batch, seq], attention_mask int64 [batch, seq], marker_pos int64 [batch, markers], marker_mask bool [batch, markers], qtype int64 [batch] (choice=0, score=1, noul=2). Outputs: logits f32 [batch, markers], act_logits f32 [batch, 2].
import * as ort from "onnxruntime-web/webgpu";
const url = "https://huggingface.co/ningsuhen/laya-typed-decisions-onnx/resolve/main/fp16/laya.fp16-nonan.onnx";
const session = await ort.InferenceSession.create(url, { executionProviders: ["webgpu"] });
const big = (a) => new ort.Tensor("int64", BigInt64Array.from(a.map(BigInt)), [1, a.length]);
const out = await session.run({
input_ids: big(ids), attention_mask: big(ids.map(() => 1)),
marker_pos: big(markerPos),
marker_mask: new ort.Tensor("bool", Uint8Array.from(markerPos.map(() => 1)), [1, markerPos.length]),
qtype: new ort.Tensor("int64", BigInt64Array.from([0n]), [1]),
});
WebGPU needs a browser and adapter with shader-f16. On the wasm CPU provider the same file is about 50x slower (about 2.4 s per pass in our test), so use WebGPU.
CORS: Hugging Face resolve URLs are served with Access-Control-Allow-Origin: * and support HTTP range requests, so the file can be fetched cross-origin from a web page. The download is 846 MB; cache it (Cache API / OPFS).
Typed decisions for a decision-tree benchmark and a browser speed-test demo (intent routing with a decision tree). Not for safety-critical, medical, legal or financial decisions.
choice questions under about 20 options.Apache-2.0, same as upstream. Derived from convaiinnovations/laya-typed-decisions (Copyright Convai Innovations, Apache-2.0; backbone ModernBERT-large, Apache-2.0). Changes are listed above and in NOTICE; the licence text is in LICENSE.
convaiinnovations/laya-typed-decisions