/** * @copyright Sister Software * @license AGPL-3.0 * @author Teffen Ellis, et al. * * Browser ONNX inference wrapper. Implements the same `NeuralRunner` contract `@mailwoman/neural`'s * classifier consumes, but backed by `onnxruntime-web` (WASM + optional WebGPU) instead of * `onnxruntime-node`. * * Execution provider strategy: * * - Try WebGPU first when `useWebGPU !== false`. ~10× faster than WASM on supported devices, but * availability depends on browser (Chromium 113+, Safari Tech Preview) AND hardware. The * runtime surfaces a clean error when WebGPU is unavailable, so the constructor falls back to * WASM automatically. * - WASM (SIMD when available) is the universal fallback. ~2× slower than WebGPU on the same model * but works everywhere onnxruntime-web does — including in Node, which is how the test * harness exercises this file. * * Tensor shape + I/O contract matches `ONNXRunner` exactly: fixed-length int64 inputs, padded with * zeros + attention_mask, output is a `logits` tensor of shape `[batch, seq, num_labels]`. See * `@mailwoman/neural/onnx-runner` for the full export contract this file mirrors. */ import type { NeuralRunner } from "./classifier.ts"; import type { InferResult } from "./onnx-runner.ts"; export interface WebONNXRunnerOpts { /** * Try the WebGPU execution provider first. Defaults to true. Set false to skip the WebGPU probe — useful in test * environments where WebGPU isn't available and the probe failure adds latency. */ useWebGPU?: boolean; /** * Fixed sequence length the model expects. Matches `ONNXRunner.DEFAULT_FIXED_SEQ_LEN` (128) by default. Re-quantized * models can override. */ fixedSeqLen?: number; /** * Optional override for where onnxruntime-web should load its `.wasm` assets from. Defaults to the package's CDN * paths; bundlers usually want to point this at a self-hosted copy. * * Example: `setWASMPaths("/static/ort/")` and put the .wasm files at /static/ort/. */ wasmPathsRoot?: string; } /** * Sequence length the web runtime pads to when the model was exported with a fixed input shape. WebGPU requires static * shapes, so a fixed length is the portable default. */ export declare const DEFAULT_FIXED_SEQ_LEN = 128; export interface WebONNXRunnerDiagnostics { backend: "webgpu" | "wasm"; modelBytes: number; } export declare class WebONNXRunner implements NeuralRunner { #private; readonly fixedSeqLen: number; diagnostics: WebONNXRunnerDiagnostics | null; private readonly modelBytes; private readonly opts; private constructor(); /** * Construct from already-fetched model bytes. */ static fromBytes(modelBytes: Uint8Array, opts?: WebONNXRunnerOpts): Promise; /** * Fetch the model from a URL and construct. */ static fromURL(modelURL: string, opts?: WebONNXRunnerOpts): Promise; /** * Names of the inputs the loaded ONNX graph declares. `null` until the session has been created (first `infer()` * call). Lets callers (e.g. the neural-web loader) detect anchor/gazetteer-trained models and warn loudly when the * corresponding feature source wasn't provided — running such a model on the zero-filled fallback is the measured * train/inference mismatch ("the zero-fill trap"), not a quality-neutral degrade. */ get inputNames(): readonly string[] | null; infer(tokenIDs: number[], anchor?: { features: ReadonlyArray>; confidence: ReadonlyArray; }, gazetteer?: { features: ReadonlyArray>; confidence: ReadonlyArray; }, country?: { features: ReadonlyArray>; confidence: ReadonlyArray; }, evidence?: { streetType?: { features: ReadonlyArray>; confidence: ReadonlyArray; }; localitySurface?: { features: ReadonlyArray>; confidence: ReadonlyArray; }; }): Promise; } //# sourceMappingURL=web-onnx-runner.d.ts.map