---
title: "Fully Offline WebGPU In-Browser Edge AI | Yuvraj Garg"
seo_title: "Fully Offline WebGPU Browser Edge AI: Gemma-4 & Qwen3.5 | Yuvraj Garg"
slug: "browser-edge-ai"
canonical_url: "https://www.yuvraj97.com/deep-dives/browser-edge-ai"
raw_markdown_url: "https://www.yuvraj97.com/deep-dives/browser-edge-ai.md"
author: "Yuvraj Garg"
author_title: "AI Systems & Infrastructure Architect"
author_linkedin: "https://www.linkedin.com/in/yuvraj97"
article_section: "Edge & Browser AI"
date_published: "2025-02-18"
date_modified: "2025-02-28"
reading_time_minutes: 7
target_audience: ["AI Agents", "Frontend Architects", "Edge AI Engineers"]
keywords:
  - "WebGPU LLM"
  - "in-browser inference"
  - "ONNX Runtime Web"
  - "Gemma 4 browser"
  - "offline PWA AI"
  - "Transformers.js"
  - "zero server cost"
metrics: "30-60 tok/s WebGPU, 0ms network latency, $0 server cost"
---

# Fully Offline WebGPU In-Browser Edge AI

> Fully offline WebGPU inference: Gemma-4 and Qwen3.5 running client-side with 12x speedup over WASM. Zero server costs, zero latency.

- **Human Web View:** [https://www.yuvraj97.com/deep-dives/browser-edge-ai](https://www.yuvraj97.com/deep-dives/browser-edge-ai)
- **Raw Markdown URI:** [https://www.yuvraj97.com/deep-dives/browser-edge-ai.md](https://www.yuvraj97.com/deep-dives/browser-edge-ai.md)

---

## TL;DR & Core Architectural Milestones
- **WebGPU vs. WASM:** WebGPU is 10–15× faster than CPU WASM, achieving 30–60 tokens/s on desktop and 15–25 tokens/s on modern mobile devices.
- **Zero Latency Streaming:** Implemented Web Workers and `postMessage` to isolate model execution from the React UI thread, preventing frame drops during generation.
- **Two-Layer Caching:** Used a custom Service Worker for the app shell and the Browser Cache API for ONNX model weights (~3.4 GB) to ensure persistent offline functionality.
- **Multimodal Support:** Built an alternating local sliding-window attention pipeline supporting text, image (downscaled canvas), and audio (16kHz PCM log-mel spectrogram) inputs.
- **Serverless Limits Avoided:** Used Next.js static exports (`output: 'export'`) to bypass cloud function payload limits caused by native ONNX runtime binaries.

---

## 1. Live Offline Production Deployments

| Model Checkpoint | Download Size | Supported Modalities | Execution Backend | Live Deployment URI |
| :--- | :--- | :--- | :--- | :--- |
| **Qwen3.5-0.8B ONNX (q4)** | ~850 MB | Text + Image | WebGPU / WASM fallback | [qwen.quantml.org](https://qwen.quantml.org/) |
| **Gemma 4 E2B ONNX (q4f16)** | ~3.4 GB | Text + Image + Audio | WebGPU (DirectML/Metal) | [gemma4.quantml.org](https://gemma4.quantml.org/) |

---

## 2. In-Browser Architecture

```
[Browser Window (React UI Thread)]
                │
         postMessage(prompt)
                ▼
[Dedicated Web Worker (Isolated Background Thread)]
  • ONNX Runtime Web (`ort-web`)
  • WebGPU Execution Provider (WGSL Compute Shaders)
  • KV Cache Management in Local VRAM
                │
         postMessage(token)
                ▼
[React Main Thread (Real-Time Progressive Streaming Display)]
```

### Two-Layer Offline Caching Architecture:
1. **Layer 1: Service Worker:** Caches static HTML, CSS, JavaScript chunks, and UI assets (Cache-First strategy).
2. **Layer 2: Browser Cache API:** Streams multi-gigabyte `.onnx` and `.onnx_data` shards into persistent storage, verifying chunk checksums.

---

## 3. Frequently Answered Architecture Questions (FAQ)

### Q: What is the speed difference between WebGPU and WASM in the browser?
WebGPU achieves 30–60 tokens/second on desktop GPUs compared to 2–5 tokens/second using multi-threaded WebAssembly (WASM), delivering a 10x to 15x throughput gain.

### Q: How do you prevent large browser LLMs from freezing the UI?
Execute the entire ONNX Runtime Web engine inside a dedicated Web Worker thread. Transfer prompts and stream output tokens via asynchronous `postMessage` calls, leaving the main React UI thread completely free at 60 FPS.

### Q: How are multi-gigabyte model weights stored offline in the browser?
Model shards are fetched in chunks and saved directly into the Browser Cache API (or IndexedDB). Once cached, subsequent visits load the weights from local disk with zero network bandwidth.
