Skip to content

IndicTrans2 ONNX Browser Demo — Codebase Interview Dossier

Repository: Hari31416/indictrans2-onnx-browser-demo (public)
Inspected checkout: repos/indictrans2-onnx-browser-demo (cloned 2026-07-09)
HEAD: ec2f3ad (2026-07-07)
Companion: indictrans2-onnx-export (producer of ONNX artifacts)
Stack: Vanilla ES modules · ONNX Runtime Web 1.21 · @huggingface/transformers · Cache Storage · GitHub Pages / HF Spaces static

Reading order

  1. Evidence Map
  2. Product & System Overview
  3. Backend Deep Dive — inference core (translator.js)
  4. Frontend Deep Dive — UI controller
  5. Data Model & Storage
  6. Infra & Local Ops
  7. Security & Safety
  8. Testing & Quality
  9. Unique Engineering Highlights
  10. Interview Prep
  11. Risks & Next Steps

Note: Chapter 02-agentic-ai-architecture is omitted — classical NMT in the browser, not an agent system.

Preview

make -C projects/indictrans2-onnx-browser-demo serve
make -C projects/indictrans2-onnx-browser-demo consolidate

Executive summary

A ~1.2k LOC static playground that downloads IndicTrans2 ONNX graphs from Hugging Face, caches them in the browser, and runs English↔Indic / Indic↔Indic translation on WebGPU or WASM. There is no app backend. The hard parts are ORT externalData sidecars, a hand-rolled encoder–decoder greedy loop with KV cache, and Unicode-block transliteration so non-Devanagari scripts match model expectations.

System map

graph TD
  classDef default fill:#1e293b,stroke:#38bdf8,stroke-width:2px,color:#f8fafc
  classDef highlight fill:#065f46,stroke:#34d399,stroke-width:2px,color:#f0fdf4

  UI["app.js"]:::highlight --> T["translator.js"]
  T --> HF["HF Hub ONNX repos"]
  T --> Cache["Cache Storage"]
  T --> ORT["ORT WebGPU/WASM"]
  T --> Tok["AutoTokenizer"]
  UI --> X["transliterate.js"]
  X --> T

  linkStyle default stroke:#64748b,stroke-width:2px

Top things to know

  1. Five source files; no bundler or package.json.
  2. Three ORT sessions: encoder, decoder, decoder_with_past.
  3. Models come from precision-suffixed HF repos (-int8, -q4f16, -fp16).
  4. Quantized + WebGPU is warned/auto-switched toward WASM.
  5. Companion export repo builds the artifacts this demo consumes.
  6. Inference is main-thread; no Web Worker.
  7. Deploy: static HF Space + GitHub Pages workflow.

Most impressive engineering

Hand-rolled KV-cache decode; WASM externalData sidecar loading; Cache Storage progress for large weights; Indic transliteration pipeline.