Hardware-Aware Model Optimization › Browser and WebAssembly Targets

Michael BrenndoerferDecember 1, 20262 min read
Language AI HandbookAll chapters
Part 43 of 67Small and On-Device Language Models
Chapter 328Hardware-Aware Model Optimization › Browser and WebAssembly Targets
Reading section 6 of 11 · Browser and WebAssembly Targets · 2 minSection 6 of 11 · 2 min

Section 6 of 11 · 2 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The browser exposes execution through its APIs and implementation. Check what the same model uses on the browsers and devices you intend to support. The availability of an API also differs from the availability of one optimized kernel.

  • WebGPU exposes GPU compute. WGSL’s FP16 arithmetic depends on the optional shader-f16 feature. Check the adapter features and buffer limits before choosing a shader and weight packing. W3C, WGSL
  • WebAssembly with SIMD supports 128-bit vector operations. A runtime can use them for packed arithmetic when its compiled kernel implements the format. WebAssembly 2.0
  • WebNN defines an interface for neural inference hardware acceleration, including implementations that target a GPU or dedicated ML accelerator. Test the graph and options on the implementation you ship. W3C, WebNN §2.2.4
  • A CPU path can help with coverage and debugging if your application provides one. Measure it separately from the accelerator path.

Use the actual browser, adapter, and model to measure throughput and test whether the weights and cache fit. Include staging copies and runtime buffers in the memory estimate.

End-to-end token rate is the useful comparison across browser and native paths. Keep the sampling settings, sequence lengths, and evaluation inputs fixed where possible. The application can also profile loading, prompt processing, and subsequent decode separately. If an adapter cannot allocate the tensor buffers, changing the launch configuration alone cannot make that buffer layout fit. A smaller model, a representation with a smaller resident payload, or a runtime that partitions tensors differently changes the memory side of the comparison.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy