Multimodal Large Model Deployment: From VRAM Estimation to Production Acceptance
This article addresses the key engineering challenges of deploying multimodal large models: estimating VRAM capacity, managing KV Cache for long contexts and multi-image inputs, and running heterogeneous accelerators within a unified scheduling system. It provides practical VRAM estimation formulas, MoE parallelization strategies, pseudocode for scheduling with fallback mechanisms, and guidelines for production acceptance.
What This Article Solves
When deploying multimodal large models, engineers must first answer three questions: Can the model fit into the available VRAM? How much cache will long contexts and multiple images consume? Can heterogeneous accelerators run stably within the same scheduling system? This article is organized around these three questions and provides scheduling pseudocode, visual failure handling, and a production acceptance checklist.
This article does not cover training methods, compare vendor pricing, or evaluate public benchmark scores. All figures provided are examples based on hypothetical configurations and do not represent the actual performance of any specific model. Before going live, you should re-measure using your own models, hardware, and traffic samples.
After reading this article, you should be able to accomplish four things: estimate KV Cache consumption, determine the required number of GPUs and parallelization strategy for a Mixture of Experts (MoE) model, write scheduling logic with failure fallback, and complete acceptance testing using a checklist.
1. KV Cache: Estimate the Cache First
The computational complexity of standard self-attention grows quadratically with the sequence length n. Expanding from 8,000 tokens to 1,000,000 tokens increases the attention computation by approximately 15,625 times, calculated as (1,000,000 / 8,000)².
Linear attention reduces computational complexity to linear in n, but it is not completely equivalent to standard softmax attention; the quality of long-range precise retrieval may degrade. A common practice is hybrid matching: using linear attention or sliding window attention for most layers, while retaining a full attention layer every few layers.
Only the cache of full attention layers grows with the context. Linear attention layers maintain a fixed-size state, and sliding window layers have a cache upper bound equal to the window size. Therefore, only full attention layers are counted during estimation.
The formula for estimating KV Cache in bytes is as follows:
KV Cache Bytes = 2 × Num_Full_Attn_Layers × Num_KV_Heads × Head_Dim × Context_Length × Bytes_Per_Element × Effective_Concurrency
The coefficient 2 represents the two copies of the cache for K and V. When using Grouped-Query Attention (GQA), the formula uses the number of KV heads, not the number of query heads. For example, if a model has 64 query heads and 8 KV heads, the cache is calculated based on 8.
Example: 80 full attention layers, 8 KV heads, head dimension of 128, and FP16 (2 bytes per element). The cache per token is 2 × 80 × 8 × 128 × 2 = 327,680 bytes (approx. 320 KiB). For a single request with a context of 1,000,000 tokens, the cache is 327,680 × 1,000,000 ≈ 327.68 GB (decimal).
Results under different context lengths and concurrency levels are shown below (FP16, in GB):
| Context Length | Concurrency 1 | Concurrency 8 | Concurrency 32 |
|---|---|---|---|
| 8k | 2.62 | 20.97 | 83.89 |
| 128k | 41.94 | 335.54 | 1342.18 |
| 1M | 327.68 | 2621.44 | 10485.76 |
When stored in FP8, the results are halved; a single 1M token request requires approximately 163.8 GB. If only 20 out of the 80 layers are full attention layers, the FP16 cache for a single 1M token request is about 327.68 × 20 / 80 ≈ 81.9 GB.
The formula provides a theoretical lower bound. Actual usage includes allocator fragmentation and alignment padding. When beam search is enabled, each beam occupies a copy of the cache, so the number of beams should be included in the effective concurrency. The concurrency numbers in the table refer to the number of active requests being processed simultaneously, not the number of connections.
Estimation Steps:
- Read the number of layers, KV heads, and head dimension from the model configuration file, and identify which layers are full attention layers.
- Determine the storage precision (FP16 or FP8).
- Calculate the cache bytes per token.
- Multiply by the maximum context length allowed by the business and the effective concurrency obtained from stress testing.
- Add the result to the weights and activations to make a VRAM assessment, as detailed in Section 2.
When selecting an approach, evaluate two metrics simultaneously: the long-range retrieval accuracy of the target task, and the VRAM usage and Time-To-First-Token (TTFT) latency for the same input length. Both must meet the business requirements for the configuration to be suitable.
2. Mixture of Experts: Weights, Parallelism, and Offloading
Mixture of Experts (MoE) models can have total parameter counts reaching hundreds of billions, yet only activate a portion of the experts per token. While activated parameters reduce the computation per inference, all weights still need to be stored; storage requirements do not decrease as a result.
Assuming total parameters of 600B and approximately 10B activated per token. The weight footprint is as follows: FP16 requires about 1,200 GB, FP8 about 600 GB, and INT4 about 300 GB.
VRAM demand is estimated using the following formula:
VRAM Demand = (Weights + KV Cache + Activations) × 1.15
Multiplying by 1.15 retains at least a 15% peak margin. Activations cannot be derived by formula and must be measured using the actual framework. The measurement protocol is as follows: record the prefill and decode phases separately, run with the maximum batch size and longest context, and take the worst-case peak between the two phases. In the example, we assume activations are 40 GB.
Example: 600 GB weights (FP8), 128k context, 8 concurrency, and FP16 KV Cache (335.5 GB). The calculation is (600 + 335.5 + 40) × 1.15 ≈ 1,121.8 GB. With 80 GB per GPU, at least 15 GPUs are required. If the KV Cache is switched to FP8 (167.8 GB), the calculation becomes (600 + 167.8 + 40) × 1.15 ≈ 929.0 GB, requiring at least 12 GPUs. These GPU counts are ideal averages based on total capacity; actual distribution depends on how experts and the KV Cache are partitioned.
Steps for choosing a parallelization strategy:
- Calculate the total VRAM demand to determine the minimum number of GPUs, N.
- If N does not exceed the number of GPUs in a single node (e.g., 8), prioritize expert parallelism within the node. Intra-node interconnect bandwidth is high, resulting in lower communication overhead.
- If cross-node deployment is required, estimate the communication volume for expert parallelism. Assuming each token sends a hidden vector to k experts per MoE layer (FP8, 1 byte per element) and receives it back once (BF16, 2 bytes per element). With a hidden dimension h = 7168 and k = 8, the communication volume per token per layer is
3 × 8 × 7168 = 172,032bytes. - Calculating with a batch size of 64 and 60 MoE layers, the communication volume per decode step is approximately
64 × 60 × 172,032 ≈ 0.66 GB. If the effective interconnect bandwidth is 50 GB/s, communication takes about 13 ms. This uses theoretical bandwidth and does not account for overlap with computation. Before going live, measure the actual overlap rate and effective bandwidth to determine bottlenecks. If the target latency per step is 20 ms, this link is a bottleneck; you should reduce the expert parallel group size, lower the batch size, or adopt a topology with higher bandwidth. - If offloading low-frequency experts to CPU memory, calculate the PCIe transfer time. Assuming an effective PCIe 4.0 x16 bandwidth of about 25 GB/s, a single expert FFN (h=7168, intermediate dimension 2048, three matrices, FP8) has about 44M parameters (~44 MB), taking about 1.8 ms to transfer. If a token hits cold experts across all 60 layers, the extra latency can exceed 100 ms. This is a worst-case scenario, not the norm. Actual latency depends on the cold expert hit rate, the degree to which requests in the same batch share experts, and whether prefetching can overlap with computation. Before enabling an offloading strategy, track the hit rate on real traffic to decide if it should be activated.
Offloading is suitable for low-traffic services that can tolerate increased latency. For latency-sensitive services, scaling out or reducing concurrency should be prioritized.
Quantization requires regression validation, with the following steps:
- Extract a calibration set from desensitized production requests, covering short text, long text, multiple images, and various resolutions.
- Run both the FP16 baseline and the quantized version on the same set of samples.
- Compare task accuracy. An example threshold is a drop of no more than 1 percentage point; the specific value should be determined by the business stakeholders.
- For visual tasks, additionally compare Visual Question Answering (VQA) accuracy and OCR Character Error Rate (CER).
- If any metric exceeds the threshold, roll back to the previous precision version and record the reason.
3. Heterogeneous Scheduling Pseudocode and Vision Fallback
When integrating multi-vendor accelerators into the same scheduling system, the first step is to maintain a device capability table. The values in this table should come from vendor documentation and local testing; do not copy the examples directly:
DEVICE_PROFILE = {"class_a": {"mem_gb": 80, "dtypes": ["fp16", "fp8"], "ep_capable": True, "max_batch": 64},"class_b": {"mem_gb": 64, "dtypes": ["fp16"], "ep_capable": False, "max_batch": 32},}TIMEOUT_MS = {"text": 30000, "vision": 60000}MAX_RETRY = 2RETRYABLE = {"OOM", "TIMEOUT", "DEVICE_BUSY"}
The main scheduling flow is as follows:
def schedule(request):ok, err = validate(request) # Validate parameters and modality typeif not ok:return reject(err)variant = select_variant(request.modality, request.context_len)candidates = [d for d in devicesif DEVICE_PROFILE[d.cls]["mem_gb"] >= variant.min_mem_gband variant.dtype in DEVICE_PROFILE[d.cls]["dtypes"]]if not candidates:return reject("NO_CAPACITY")device = least_loaded(candidates) # Sort by queue length and available VRAMfor attempt in range(MAX_RETRY + 1):result = run(device, request, timeout=TIMEOUT_MS[request.modality])emit_metric("attempt", device=device.id, ok=result.ok, error=result.error)if result.ok:return resultif result.error not in RETRYABLE:breakdevice = next_device(candidates, exclude=device)if device is None:breakif variant.fallback is not None: # Fallback: shorten context, reduce resolution, or switch to a smaller modelemit_metric("fallback", reason=result.error)return run(fallback_device, request, timeout=TIMEOUT_MS[request.modality])return reject(result.error or "UNKNOWN_ERROR")
