arXiv:2610.39761cs.CYOct 2026

Manuscript Offprint

arXiv:2610.39761

GPU-Resident Speculative Decoding for In-Browser LLM Inference with WebGPU

Wei Song, Yuxin Cao, Ziqi Ding, Xiao Cheng

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

WebGPU enables private, offline LLM inference inside web pages, but browser dispatch, inter-process communication, synchronous readback and single-token kernels slow decoding and make conventional speculative decoding inefficient. We present a WebGPU runtime that addresses these browser-specific costs. Deterministic small-batch integer kernels accelerate multi-token verification while preserving exact agreement with greedy decoding in the same quantized runtime. A GPU-resident loop performs drafting, verification, acceptance and KV-cache maintenance without a per-token CPU decision. A draft-free context-mixing drafter reuses page content, conversation history and session memory, while a device-aware controller adapts the speculation width and the submission window to measured costs. Across seven models from 0.5B to 8B parameters, 11 tasks and three client GPUs, our runtime decodes 3.5 to 5.4× faster than WebLLM on a laptop GPU, 4.8 to 6.2× faster on an integrated GPU and 4.8 to 8.6× faster on a workstation GPU. The GPU-resident loop and speculation contribute a further 1.8 to 3.2× over the optimized kernels on the workstation. Outputs match the quantized greedy decoding of the runtime exactly, and the mean GSM8K accuracy matches that of WebLLM. Optional draft heads raise the peak speedup to 10.2×, while session memory provides additional gains without downloading extra weights.

CCS Concepts

• Information systems → World Wide Web; • Computing methodologies → Natural language processing.

Keywords

WebGPU, speculative decoding, LLM inference

1 Introduction

Language models are moving into the web page itself. With WebGPU [32], a page can download a model of a few gigabytes once and run it on the GPU of its visitor, and engines such as WebLLM [36] already serve models up to 8B parameters in a browser tab. The page, the forms and the conversation then stay on the device, the site pays nothing per token, and assistants that summarize the open page or help inside web editors keep working offline.

Decoding is the bottleneck of these in-page assistants. A browser places a security boundary between the page and the GPU, so every WebGPU dispatch is validated in the renderer and forwarded to a separate GPU process, and every token that JavaScript reads back stalls the pipeline until the GPU drains. The kernels of current

Yuxin Cao

National University of Singapore

Singapore

Xiao Cheng

Macquarie University

Australia

engines add a third cost, since they are compiled for one token per step and process several tokens through their prefill path. On a laptop GPU, WebLLM spends 20.15 ms per token on Qwen2.5-0.5B, while our kernels need 5.93 ms with the same per-token readback and 4.22 ms without it. Speculative decoding [3, 18], the standard remedy for memory-bound decoding on servers, works against the platform in its usual form. A draft model pays the dispatch overhead of its own forward passes, the prefill kernels of WebLLM make the verification of 8 tokens cost 2.7 times a decoding step, and a CPU that inspects every verification result pays the full cost of the readback again at every step. The effect is strong enough to reverse the usual recipe. A fixed tree of 8 nodes, which speeds up decoding by half on a workstation GPU, makes it 2.7 times slower than plain decoding on the integrated GPU of a laptop.

This paper argues that the whole decoding loop of a browser runtime, from the kernels to the control of speculation, must be designed around the costs of the browser, and it presents a runtime that does so. To our knowledge, it is the first WebGPU runtime that moves tree-based speculative decoding, including drafting, verification, acceptance and KV-cache maintenance, into a GPU-resident loop that avoids per-token submission and readback in the browser. This requires deterministic small-batch verification kernels and control of the speculation width and of the submission window from costs that are measured on the device. Its small-batch kernels multiply 4-bit weights with 8-bit activations through integer dot products, so that verifying 8 tokens costs 19% to 77% more than one token on discrete GPUs instead of 2.7 times, and their reductions follow a fixed order, so that the verification of N tokens is bit-identical to N single-token steps and speculation reproduces the greedy decoding of the same quantized runtime exactly. The speculation loop runs entirely on the GPU. Drafting, verification, acceptance and the maintenance of the KV cache are kernels that read their control state from a GPU buffer, so the runtime encodes several steps into one command buffer and the CPU reads only a few bytes between windows of steps. A draft-free drafter in the spirit of context mixing in data compression [8, 27] predicts continuations from the page, the conversation and a memory of earlier sessions, with no second model to download or run. A feedback controller measures the cost of each tree width on the device of the visitor and chooses the width that maximizes the expected tokens per millisecond, because a step of 8 nodes costs 19% more than a step of one node on a workstation GPU and 4.1 times as much on the integrated GPU of a laptop.

We evaluate the runtime as a page would deploy it, in Chrome on the GPU of the visitor, with a laptop discrete GPU, an integrated

GPU and a workstation GPU, using seven models from 0.5B to 8B parameters and 11 tasks, seven of which are grounded in web content. We compare against the three in-browser engines WebLLM, Transformers.js and LlamaWeb on all three GPUs. Controlled ablations separate the effects of the optimized kernels, GPU-resident execution and adaptive speculation, while cross-device tests characterize when wide verification helps or hurts. We also measure request latency, output agreement and task quality. Because the model shares the GPU with the page, we test whether the page still renders at 60 frames per second while it decodes, and we report the one-time cost that a page pays to load and calibrate a model, with the session memory kept in the same-origin storage of the page. These results establish both the performance benefits and the hardware-dependent limits of GPU-resident speculation in the browser. The contributions of this paper are as follows.

  • We measure the costs of dispatch, readback and multi-token kernels that make in-browser decoding slow, and we show that the same costs make naive speculation slower than plain decoding on weak client GPUs.

  • We introduce GPU-resident speculative decoding for WebGPU, which removes the per-token acceptance decision of the CPU and its readback, and deterministic small-batch kernels that make multi-token steps cheap while keeping exact agreement with our quantized greedy decoder.

  • We propose a draft-free context-mixing drafter with a session memory, and a cost-aware controller that adapts the speculation width to each client GPU.

  • On three client GPUs, our runtime decodes 3.5 to 8.6×8.6\times faster than WebLLM with output identical to its own greedy decoding and equal mean task accuracy, and ablations attribute the gain to each component of the runtime.

References (14)