WebGPU & WebLLM Browser-Native Agents: Running 3B Reasoning Models Zero-Cost Inside Chrome Without Backend GPU Servers
Zero-Server-Cost AI Inference in the Browser
For Chrome extensions, local-first document analyzers, and privacy-sensitive developer tools, sending every user keystroke to a cloud GPU API kills unit economics and scares off security-conscious buyers.
With WebGPU now enabled by default across Chrome, Edge, and Safari, @mlc-ai/web-llm compiles quantized 1.5B–3B models (Qwen2.5-3B-Instruct-q4f16_1-MLC, Llama-3.2-3B-Instruct-q4f16_1-MLC) into native GPU compute shaders running 100% locally inside a browser Web Worker.
text[React / Next.js UI Thread] │ (postMessage: zero UI jank) ▼ [Web Worker: @mlc-ai/web-llm Engine] ├── First Load: Fetch 1.6GB shards -> Cache permanently in Browser IndexedDB / CacheStorage └── Inference: Direct WebGPU Shader Execution on User's M-Series / RTX GPU (50-75 tok/s, $0!)
TypeScript Web Worker Implementation
Always isolate WebLLM inside a dedicated Web Worker so shader compilation and matrix ops never block the main DOM thread:
typescript// worker.ts import { WebWorkerMLCEngineHandler } from "@mlc-ai/web-llm"; const handler = new WebWorkerMLCEngineHandler(); self.onmessage = (msg: MessageEvent) => { handler.onmessage(msg); };
typescript// client.ts import { CreateWebWorkerMLCEngine } from "@mlc-ai/web-llm"; export async function initLocalBrowserAgent(onProgress: (pct: number) => void) { const engine = await CreateWebWorkerMLCEngine( new Worker(new URL("./worker.ts", import.meta.url), { type: "module" }), "Qwen2.5-3B-Instruct-q4f16_1-MLC", { initProgressCallback: (report) => onProgress(Math.round(report.progress * 100)), } ); const reply = await engine.chat.completions.create({ messages: [ { role: "system", content: "Extract structured JSON action items concisely." }, { role: "user", content: "Follow up with Raj on Stripe webhook idempotency tomorrow." }, ], temperature: 0.1, response_format: { type: "json_object" }, }); return reply.choices[0].message.content; }
Real-World Tradeoffs
- First-Visit Download: Expect a ~1.5GB–1.8GB initial shard download (cached in browser
CacheStoragefor instant ~1.2s cold starts on every subsequent visit). - Throughput: 55–75 tokens/sec on Apple M2/M3 and 85+ tokens/sec on RTX 3060/4060 laptops—zero API keys, zero CORS issues, and infinite horizontal scaling on the user's own hardware.