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¶
- Evidence Map
- Product & System Overview
- Backend Deep Dive — inference core (
translator.js) - Frontend Deep Dive — UI controller
- Data Model & Storage
- Infra & Local Ops
- Security & Safety
- Testing & Quality
- Unique Engineering Highlights
- Interview Prep
- Risks & Next Steps
Note: Chapter
02-agentic-ai-architectureis 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¶
- Five source files; no bundler or
package.json. - Three ORT sessions: encoder, decoder, decoder_with_past.
- Models come from precision-suffixed HF repos (
-int8,-q4f16,-fp16). - Quantized + WebGPU is warned/auto-switched toward WASM.
- Companion export repo builds the artifacts this demo consumes.
- Inference is main-thread; no Web Worker.
- 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.