← All posts

A 1.5M-parameter NLP model in WebAssembly under 10ms

How Stedy pulled a cloud LLM out of the command bar: deterministic parsing plus ADS-1.5M via onnxruntime-web.

A 1.5M-parameter NLP model in WebAssembly under 10ms
Contents

In brief

The author of Stedy got tired of waiting ~500 ms on every command-bar keystroke while a cloud LLM decided whether a line was an event, a task, or a note. Bad campus Wi‑Fi made the call fail, and paying for API tokens just to classify a short sentence felt wrong.

The fix: deterministic TypeScript extracts dates and known course names, then a tiny INT8 model ADS-1.5M (~1.5M parameters) classifies intent in WebAssembly through onnxruntime-web. Once the model is cached in CacheStorage, a forward pass lands under 10 ms.

What happened

The scenario is familiar to anyone who wired an “smart” input. A line like “Algorithms exam tomorrow at 9am” does not need frontier-model reasoning—it needs fast labels: EVENT / TASK / NOTE plus a category. A cloud call on the hot path meant network lag, flaky Wi‑Fi, and a token bill.

The architecture splits the work. Plain TypeScript first pulls dates, time ranges, and known course names—the parts rules can own without a model. Then ADS-1.5M in INT8 runs in the browser via onnxruntime-web/wasm: input_ids in, intent class and category out.

The .int8.onnx file and vocab.json live in CacheStorage. After that, the local forward pass stays under 10 ms. The model is not a frontier LLM: low confidence still falls back to an API call. By the author’s estimate, about 90% of daily inputs stay on the local path—offline, unpaid, with notes on the user’s device.

Why it matters

Many products drag a cloud LLM into places where a tiny classifier is enough. The user does not feel “AI magic”; they feel half a second of pause and a network dependency. Moving a narrow job into WASM changes the UI: Enter feels instant, and the cloud becomes a safety net.

For frontend teams the stack is pragmatic: ONNX Runtime in the browser, INT8 quantization, asset caching. You do not need a separate inference service for 90% of traffic. Privacy here is a side effect, not a slogan: the note text can stay on-device while local confidence is high enough.

The trade-off is honest. A small model is dumber than a large one. That is why a confidence threshold and an API fallback matter more than promising “fully offline forever.” Hybrid “local by default, cloud on doubt” usually beats the reverse.

In practice

  1. Pull out of the model everything rules can parse: dates, times, entity dictionaries.
  2. For narrow classification, prefer a quantized model in the millions of parameters—not a gigabyte LLM.
  3. Cache .onnx and the vocab in CacheStorage, or the cold start erases the win.
  4. Set a confidence floor and an explicit API fallback—do not hide degradation.
  5. Measure the offline hit rate: if it sits below ~80–90%, fix data and thresholds before blindly growing the model.

Takeaway

Short-phrase classification in a UI often does not need a cloud LLM. A tiny INT8 model in WebAssembly plus deterministic preprocessing gives an instant feel, offline use, and a smaller API bill—while keeping a cloud escape hatch for uncertain cases.

Comments

Loading comments…