Local LLM Deployment: GPU Memory and Runtime Version Planning
Deploying an LLM locally requires more than fitting its weights into GPU memory. This guide explains how to budget weights, temporary buffers, and the KV cache; estimate memory requirements for context length and concurrency; align runtime builds with model formats; and validate a deployment under its intended workload.
Local LLM deployment is often reduced to one question: are the model weights smaller than the GPU’s memory capacity? That comparison covers only static memory usage. Whether inference can finish, how much context it can support, and how many requests it can serve simultaneously also depend on the attention cache that grows with token count—and on whether the inference runtime, weight format, and compute kernels are compatible.
Model parameter count alone is therefore not the most useful starting point for deployment planning.
Separate GPU Memory into Three Budgets
Treat GPU memory as three separate expenses rather than comparing a single “model size” against the card’s advertised capacity.
1. Model weights
Quantized weight files account for most of a model’s disk footprint. Once loaded into GPU memory, their size generally remains in the same range, with additional alignment and metadata overhead.
Published sizes do not always use the same units. Some publishers use decimal gigabytes, where one GB is 10^9 bytes; others use binary gibibytes, where one GiB is 2^30 bytes. The ratio is approximately 1.074. Although the difference is less than 10%, it can determine whether a model fits when planning close to the limit.
Use the byte counts in the file listing rather than rounded download-page estimates:
- GB: bytes divided by 10^9
- GiB: bytes divided by 2^30
Compare those figures with the GPU capacity expressed in matching units. Leave room for the driver, framework runtime, and temporary tensors rather than allocating the entire advertised capacity to weights.
2. Activations and temporary buffers
Intermediate results from forward passes and workspaces for tiled matrix multiplication vary with batch size and implementation strategy. They are usually much smaller than the cache for a long context, but they are not zero.
As batch size increases, this portion of memory usage can become significant.
3. The attention cache, or KV cache
During autoregressive generation, previously computed keys and values are retained for reuse by later tokens. This key-value cache grows approximately linearly with context length and with the number of concurrent requests.
If one deployment supports a long context while another runs out of memory after a modest increase on the same GPU, the difference often lies in this cache budget—not in the weight size.
Estimate the KV Cache from the Model Configuration
A model’s configuration file usually provides the number of layers, the number of key-value heads, and the dimension of each head.
For half-precision storage, at two bytes per element, the KV cache required by one token in one layer is:
KV heads × head dimension × 2 (key and value) × 2 (bytes per element)
Multiply by the number of layers to obtain cache bytes per token, then by the planned context length to estimate the cache for one request.
The following calculation illustrates the method; it does not describe a particular model release:
bytes_per_token = n_kv_heads * head_dim * 2 * 2 * n_layerskv_bytes = bytes_per_token * context_tokens * concurrency
For an example architecture with 32 layers, 4 KV heads, and a head dimension of 128:
- Each token requires 4 × 128 × 2 × 2 = 2,048 bytes per layer.
- Across 32 layers, that becomes 65,536 bytes per token.
- An approximately 8,000-token context requires about 0.5 GiB.
- An approximately 32,000-token context requires about 2 GiB.
These figures cover only the cache. Weights, runtime overhead, and temporary buffers must be budgeted separately.
Several adjustments are easy to overlook:
- Cache precision. The formula assumes two bytes per element. If the runtime uses four-byte cache elements, usage roughly doubles. For lower-bit-width cache storage, substitute the actual bytes per element. Do not infer KV cache size from the weight quantization ratio.
- Attention architecture. Grouped-query attention reduces the number of KV heads, making long contexts more practical. If the number of KV heads equals the number of query heads, the cache will be substantially larger.
- Allocation behavior. Some runtimes preallocate for the maximum context length; others grow the cache as the sequence grows. Some round allocations upward to meet kernel alignment requirements. The formula provides a baseline estimate, not a guaranteed allocation size. Test the actual runtime with the target context before deployment.
- Multimodal inputs and very long sequences. Visual tokens and tokens from long-document chunks consume the same sequence-length budget. User-visible character counts are not a reliable substitute for token counts.
Concurrency Is More Than Dividing the Remaining Memory
A single-user session typically needs one cache. Once the model becomes a small network service, each concurrent request slot usually needs its own cache.
Four concurrent requests with an 8,000-token context each require roughly four times the cache of one such request. They do not share a single 8,000-token allowance.
Some runtimes instead reserve a fixed total context pool and divide it among request slots. For example, a total budget of 64,000 tokens split across four slots gives each slot a window of approximately 16,000 tokens—not 64,000 tokens per request.
A deployment that works during individual testing but runs out of memory when colleagues start using it often has one of two problems: request slots multiply cache usage, or the shared pool reduces each slot’s context window while clients continue sending requests sized for the original limit.
Before exposing the process over the network, define three policies:
- Maximum concurrency and maximum context per request. The cache implied by their product must fit within the memory left after weights and other overhead.
- Handling of oversized requests. Decide whether to reject, truncate, or queue them. If truncation is used, document it at the API layer so earlier context is not silently discarded.
- Cache retention for idle slots. Determine whether idle slots release their cache. If the implementation reserves memory for peak usage, low traffic will not return that memory. Plan for peak capacity rather than average concurrency.
Check Version Compatibility Before Downloading the Weights Again
Inference runtimes evolve quickly, as do tensor layouts, quantization types, and metadata fields in model files. An apparent model-loading failure may actually be a runtime that is too old—or otherwise incompatible with the weight release.
One class of failure has nothing to do with the text being processed. While assembling tensors into a contiguous buffer and launching a compute kernel, the runtime may encounter a dimension that exceeds the range representable by a kernel parameter. For example, a parameter stored as an unsigned 16-bit integer cannot represent a value above 65,535.
The resulting log may contain little more than “invalid parameter,” making the problem look like a driver or GPU failure. Video inputs, very long contexts, and unusually wide tensors are more likely to expose such limits. If a fix is available only after a particular runtime build, an older installation will reproduce the failure regardless of whether the weights were downloaded correctly.
Another source of confusion is dependency packaging. Many applications call an inference core through a bundled or referenced downstream copy rather than the copy installed separately on the machine. The version displayed in the interface may identify only the application wrapper. Tensor assembly and kernel launches may still be handled by an older library.
Updating the wrapper without checking the inference core actually in use can leave the problem unchanged.
Make version checks part of the deployment checklist:
- Record three identifiers: the inference runtime build, the model weight release, and the quantization format. Manage them as a compatible set rather than changing one in isolation.
- Use the minimum build specified in release notes. “A package from roughly the last month” is not a precise compatibility requirement.
- For vague parameter or dimension errors, check dimension limits and build dates before reinstalling drivers. Driver problems more often involve an unavailable device or failures across models, rather than a failure confined to one unusually wide tensor.
- After an upgrade, test generation with a fixed short context, then increase it gradually to the target length. Verify that the cache allocation path also works with the updated kernels.
A Practical Deployment Sequence
Turning these considerations into an ordered checklist is more useful than collecting installation commands.
Step 1: Calculate the cache for one request
Read the model configuration, calculate cache bytes per token, and multiply by the target context length.
Step 2: Add weights and runtime headroom
Convert weight sizes from their actual byte counts. Add roughly 10–20% runtime headroom and account for temporary buffers, then compare the total with GPU capacity expressed in GiB. Treat this as an initial budget, not a substitute for measurement.
Step 3: Apply the concurrency budget
Multiply the per-request cache by the planned concurrency; do not multiply the shared weights. If the runtime divides a fixed total context pool among slots, define the advertised per-request context as the total budget divided by the slot count, and document that limit for clients.
Step 4: Lock compatible versions
Record the inference runtime build and weight format. Confirm that the application wrapper is using the intended inference core.
Step 5: Test at the intended limits
Run a load test using both the target context length and target concurrency. Measure peak GPU memory usage rather than checking only the moment when the model finishes loading.
Local or Hosted, the Capacity Budget Still Applies
The practical limitations of local deployment often lie in the toolchain rather than in the model’s capabilities: omitted cache costs, mixed capacity units, concurrency that exceeds the budget, or mismatches between runtimes and weight formats.
Memory budgeting and version records can expose these issues before deployment.
If a team does not intend to keep tracking inference builds and kernel limitations, a hosted inference service may be simpler to operate. Platforms such as Baidu AI Cloud offer model inference, object storage, and monitoring and alerting that can support delegating weight storage, runtime maintenance, and capacity scaling to a platform, subject to the services available in the intended deployment region. A local environment can then be retained for development and short-context debugging.
Whether inference stays local or moves to the cloud, context length, concurrent request slots, and cache precision still belong in the capacity assessment. Moving to a hosted service changes where the memory budget is enforced; it does not remove the budget.
