﻿# ONNX Runtime WebGPU KV-cache report: allocator steps differ from ordinary context growth

An ONNX Runtime issue links stepped decode latency to bucketed KV-buffer reuse. Its static-cache control and later stale closure do not establish a released allocator fix.

Author: Retrivium editorial team
Updated: 2026-11-05
Canonical URL: https://retrivium.ai/journal/onnxruntime-webgpu-kv-bucket-allocation-staircase-case/
Language: en

Longer context can increase decode work, but an abrupt permanent step can also come from memory management. [ONNX Runtime issue 32017](https://github.com/microsoft/onnxruntime/issues/32017), opened on 12 August 2026, documents a WebGPU case with a growing KV cache. Its measurements and controls are useful evidence, provided the reported workload, proposed workaround and release status remain distinct.

## The reported staircase

The author used Phi-4-mini q4f16 with ONNX Runtime Web 1.29 and an Intel integrated GPU. The issue reports approximately 46 milliseconds per token below the first boundary, rising through later steps to approximately 298 milliseconds per token. It summarizes decode falling from roughly 22 to 4 tokens per second as context grows toward 8k.

The reproduction description begins with about 1900 prompt tokens and 256 greedy output tokens to cross the first boundary. Other longer prompts probe later boundaries. This is not one short generation that necessarily traverses the entire reported range. It is also an owner experiment, without an independent repetition or an all-browser benchmark.

## Why allocation counts matter

In the issue’s explanation, the model produces 64 KV tensors per decode step. The buffer manager groups allocations by size, but retains fewer buffers in each bucket than the model requests together. Releasing the previous cache and requesting the next one therefore repeatedly creates and clears buffers beyond the retained capacity.

A longer sequence eventually crosses a size-bucket boundary and changes the allocation cost. The author’s evidence includes a transition at a non-power-of-two boundary and a model with fewer cache tensors that behaves differently. This is a more specific diagnosis than saying the GPU has become slower because context is longer. The general [KV-cache accounting guide](/journal/kv-cache-economics/) explains the request-state memory that grows here, but does not predict this allocator behavior.

## A static cache provides a control

The report compares the growing cache with preallocated storage bound in place. In an additional comparison with 4096 prompt tokens and 256 generated tokens, Phi-4-mini reaches 5.6 tokens per second dynamically and 20.8 with the static approach on the named Intel setup. These aggregate figures belong to that later comparison, rather than replacing the per-step staircase measurements.

The related [Transformers.js pull request](https://github.com/huggingface/transformers.js/pull/1745) describes an opt-in StaticCache that fixes capacity and binds present outputs onto existing GPU buffers. This avoids reallocating those cache entries each step. It requires the model and execution path to support that sharing and reserves capacity in advance. The [I/O-binding guide](/journal/fg2-onnxruntime-io-binding-device-buffer-lifetime/) explains why ownership, shapes and reuse lifetime still matter when supplying storage explicitly.

## Raising every limit has a memory cost

The issue proposes adaptive demand tracking or eviction under a total memory budget. Simply retaining more buffers in every bucket can keep obsolete allocations after the growing cache moves elsewhere. The contributor discussion agrees that fixed limits are a limitation for this dynamic workload, while distinguishing static-shape cases and other cache modes.

These suggestions are design directions. They do not establish that a particular adaptive policy has shipped, or that one setting optimizes all models. A comparison needs both latency and retained-memory behavior over the complete sequence.

## Closed does not mean a verified release fix

The issue was closed on 15 October 2026 by the inactivity bot, despite a completed status label. The linked static-cache pull request remained open when reviewed. Neither observation establishes a released allocator correction. The supported conclusion is a documented workload-specific diagnosis and control, which can guide a fresh test of the exact installed software and model.
