Memory Budgets and Quantization for Client AI

Memory Budgets and Quantization for Client AI

Why a model that fits on a 32 GB workstation can die on real phones: the full memory budget, quantization trade-offs, device memory shapes, and out-of-memory as a designed path.

A model that fits comfortably on a 32 GB development workstation can exhaust memory on the phones real users actually carry, because the headline weight figure is never the whole budget — the KV cache, activation workspace, and runtime overhead all compete for the same pool. This article gives you the full line-item budget, quantization as a major lever for shrinking it, how that budget lands differently across unified and discrete memory devices, and treating out-of-memory as a designed path rather than a crash.

What actually occupies memory

The resident-memory budget has several line items, and the model's weight size is only the headline one. Model weights are the number everyone quotes first. The KV cache, for models shaped like a conversational LLM, scales with how much of the conversation the model holds in context. Activation workspace is consumed during the forward pass. And runtime overhead — the inference engine's own bookkeeping — sits on top of all of it. The headline weight figure is never the total, and treating it as one is a budgeting mistake.

The KV cache holds a particular surprise for LLM-shaped features. With a cache that grows as tokens are processed (Hugging Face Transformers' DynamicLayer, for example), memory grows with context length as a conversation continues, so a model that comfortably fits in memory at load time can exhaust the budget purely through use, mid-session, with no code change and no new request triggering it. A cache with a fixed length set when it is created spends that memory up front instead — WebLLM's model list, for example, gives a separate VRAM figure for each context-window setting of the same model (as of November 2026, WebLLM v0.2.88). Capping context length is therefore memory policy as much as it is a quality lever — a cap exists to protect the budget, not only to bound how much the model can consider at once.

Task-shaped models are the easier case, and it is worth stating that honestly rather than treating every model as equally risky. An embedding model or a classification model has a footprint that is mostly static weights, with no growing cache to worry about — a large part of why these tasks are the browser's comfortable home turf throughout this topic.

The last framing matters as much as the arithmetic. The page is a tenant in the browser process, not the owner of the device's memory. The model shares the page's memory with the DOM and the surrounding framework, and shares the device's memory with every other open tab and app — budgeting against the device's total physical memory, rather than against what the browser process can realistically claim, is budgeting straight toward a crash. A workstation with 32 GB of physical memory and a browser process that can realistically claim a fraction of that under normal multitasking are two very different numbers, and only the second one is the honest budget.

Quantization as a memory lever

The mechanism, stated in one honest paragraph: lower-precision weights — moving from fp16 down through the various 4-bit families — shrink the weights, and with them the download size, roughly in proportion to the bits per weight. The resident footprint shrinks by less, because the KV cache, activation workspace, and runtime overhead are not weights and weight quantization alone does not shrink them. The quality cost has to be measured per task rather than assumed from the precision drop.

A concrete worked example makes the scale of the lever tangible: moving the same small language model from fp16 to a 4-bit quantization cuts its weight bytes to roughly a quarter (16 bits per weight down to 4, before quantization-scale overhead), but shrinks the whole resident footprint by less. WebLLM's prebuilt model list gives about 2.6 GB of VRAM at fp16 versus about 0.9 GB at 4-bit for Llama-3.2-1B-Instruct, about 2.9 times smaller, and about 1.6 GB versus about 0.9 GB for Qwen2.5-0.5B-Instruct, about 1.7 times smaller, both at a 4,096-token context window (as of November 2026, WebLLM v0.2.88).

PrecisionRelative weight sizeQuality impact
fp16BaselineReference quality
8-bitRoughly halfTask-dependent — measure per task
4-bitRoughly a quarterTask-dependent — measure per task

The quality cost cannot be assumed uniform across task types, and this is where this topic's evaluation discipline earns its keep. A working hypothesis, not a documented rule, is that classification and embedding tasks tolerate aggressive quantization better than open-ended generation does, and that instruction-following degrades before basic fluency does — and because quality loss cannot be trusted to be uniform or predictable, any precision change warrants re-running the task-specific evaluation set.

In practice, the variant ladder a team designs at selection time is mostly a quantization ladder wearing a different name — the same architecture offered at different precisions for different device tiers, rather than genuinely different models. Framing it that way keeps the maintenance burden honest: adding a rung to the ladder usually means producing and testing one more quantization of an existing model, not sourcing and maintaining an entirely separate one.

The device population's memory shapes

Devices come in two broad memory shapes, and they behave differently under the same budget. Integrated and mobile devices share one unified memory pool between the CPU and GPU, so the model is directly competing with everything else running on the device. Discrete GPUs carry their own dedicated VRAM with an independent ceiling, which behaves more predictably but is not unlimited either. The same nominal memory budget lands very differently depending on which shape the device has.

The limits of the WebGPU device a page requests act as hard walls regardless of how much free memory the hardware otherwise appears to have: they are the specification's default limits unless higher values, up to the adapter's own limits, were requested in requiredLimits when the device was created. Maximum buffer size caps the size of a single buffer, and the maximum binding sizes cap a single buffer binding, independent of total available memory — the capability-detection side of this topic is responsible for probing those limits; this article's job is budgeting within whatever they turn out to be, not discovering them.

Mobile reality deserves to be named plainly rather than softened. Browsers sometimes suspend pages or discard them entirely when system resources are constrained, as Chrome's Page Lifecycle documentation describes; a hidden, backgrounded page can be discarded with no event fired, and a large resident model adds to the memory pressure behind those discards. Mobile memory budgets are a fraction of desktop budgets as a structural fact of the platform, not an edge case to handle later.

The practical size range is a judgment rather than a documented limit: quantized chat-shaped models in the single-digit-billions-of-parameters range are a practical target for in-browser chat on consumer hardware. The WebLLM paper (arXiv:2412.15803, revised April 13, 2026) says open-weight providers now routinely ship capable small models in the 1–8B-parameter range, and evaluates two 4-bit models, Llama-3.1-8B and Phi-3.5-mini (3.8B), on one Apple MacBook Pro M3 Max in Chrome Canary 133. WebLLM's prebuilt model list puts a 4-bit 8B model at about 5 GB of VRAM, while its 70B entries, at 3-bit, need about 31 GB (as of November 2026, WebLLM v0.2.88).

Budgeting and monitoring in practice

The healthiest practice writes the budget down per device tier, before launch, rather than discovering it in production. A target resident footprint, a context-length cap, and which model variant each tier receives — decided deliberately, and adjusted afterward on evidence rather than intuition.

Measurement honesty matters here because the tools available are genuinely limited. Memory APIs exposed to web pages are coarse and partial by design, for good security reasons, so the practical posture combines pre-launch profiling on representative hardware with runtime signals — allocation failures, device-lost events — rather than trusting any single reported memory number as ground truth. Representative hardware means the median device in the actual audience, not the newest laptop in the office, since a budget tested only on the newest hardware says little about how it holds on the median device.

Out-of-memory conditions deserve a designed path, not an unhandled exception. Allocation failure and GPU device-loss events are handled rungs in the same degradation ladder this topic builds elsewhere: release what memory can be released, downgrade to a lighter model variant or the next rung down, and tell the user honestly what happened. A white-screen crash is never the correct outcome of a memory condition the team could have anticipated — WebGPU reports device loss by resolving the device's lost promise rather than by generating an error, and most later operations that report back to the page's script appear to succeed (mapAsync() is the exception and produces an error), so a lost device has to be watched for and routed explicitly.

Session hygiene closes the loop. Releasing the model's memory when a feature closes, rather than holding it resident indefinitely on the chance it gets used again, is a real trade-off worth making deliberately. Keeping a two-gigabyte model warm for a use that may never come costs real memory the rest of the page could otherwise use; the loading article's territory covers what re-initialization costs if that memory gets released and the model has to be reloaded later. Neither choice is universally correct — a feature invoked constantly across a session earns its resident memory back quickly, while a rarely used one rarely does, and the written per-tier budget from earlier in this article is exactly where that decision belongs, made once and revisited on evidence rather than argued fresh on every code review.

Project Inquiry