Running Multimodal Models On-Device: Memory and KV Cache Estimation

    As large models move from the cloud to phones, dev boards, and IoT devices, running multimodal models on-device becomes a practical question. This article explains the three key constraints, shows how to estimate effective parameters and KV cache memory, compares deployment options, and provides a pre-deployment checklist for edge developers.

    As large models move from the cloud to phones, development boards, and IoT devices, the need to run multimodal models on-device is becoming clear. Privacy, offline availability, and response speed are the main motivations. But compute and memory on the edge are limited. Whether a model can be deployed depends on controlling compute cost, cache footprint, and the deployment complexity of multimodal components at the same time. This article is written for edge developers. It first covers three types of constraints, then explains how to estimate effective parameters and KV cache usage, compares two multimodal deployment approaches, and ends with a pre-deployment checklist.

    How Much Memory Is Actually Available

    Phones are commonly advertised with 8GB, 12GB, or 16GB of RAM. These are nominal device specs, not the space a model can actually use. The operating system, background processes, and other apps all consume memory, and actual availability varies by device and usage state—it can be well below the nominal figure. When estimating, measure the available memory on the target device under typical usage conditions directly. Do not substitute the nominal spec.

    Why KV Cache Can Exceed the Weights

    Autoregressive models must read the Key and Value states of all previous tokens each time they generate a new one. These states are cached per layer, so the footprint grows with sequence length. With long contexts, the KV cache can approach or even exceed the memory used by the model weights. Looking only at the weight file size will therefore underestimate peak memory usage.

    Effective Parameters: Compute and Memory Must Be Calculated Separately

    Dense models use all parameters on every forward pass, so compute grows roughly in step with parameter count. Effective-parameter designs let each token pass through only a subset of parameters; common implementations include sparse activation and Mixture of Experts (MoE). Both are forms of on-demand computation, though terminology and details vary across implementations.

    The most common mistake is assuming “fewer activated parameters” means “lower memory usage.” The two must be calculated separately:

    • Compute: the forward compute per token can be roughly estimated as 2 × P_active FLOPs, where P_active is the number of parameters actually involved in computing each token.
    • Storage: the weight file and loaded memory depend on all parameters: M_w ≈ P_total × b_w, where P_total is the total parameter count and b_w is the bytes per parameter. FP16 is 2, INT8 is 1, and INT4 is about 0.5. Actual usage also includes quantization metadata (such as scale and zero point) and runtime overhead.
    • Decoding speed upper bound: in autoregressive decoding with batch size 1, generating each token requires reading the weights and KV needed for that step from memory. The speed ceiling can be estimated as BW_eff ÷ (P_active × b_w + KV bytes read per step), where BW_eff is the effective memory bandwidth measured under sustained load on the target device—not the chip’s theoretical bandwidth. Routing layers and shared layers that are read every step should be included in P_active. This formula gives an upper bound; actual speed will only be lower due to compute scheduling, dequantization overhead, and cache misses.

    Here is a hypothetical example. Suppose an MoE model has 30B total parameters, 3B activated parameters, and uses INT4 quantization. The weights alone need about 15GB (30×10^9 × 0.5 bytes), and compute per token is about 6 GFLOPs. This is still too large for most phones, so fewer activated parameters do not make it runnable on a phone. If the device’s effective bandwidth is assumed to be 40 GB/s, each token reads about 1.5GB of weights (3×10^9 × 0.5 bytes), giving a decoding speed ceiling of about 27 tokens/s. This shows the bottleneck is memory capacity, not speed. This example only demonstrates the formulas; the numbers are hypothetical, exclude quantization metadata, runtime overhead, and KV cache, and do not represent any real model’s performance.

    Shared KV Cache: Formula, Estimation, and Boundaries

    The memory formula for the KV cache is:

    M_kv = 2 × L_kv × H_kv × d_h × T × B × b_kv

    What each symbol means:

    • 2: two states, Key and Value.
    • L_kv: the number of layers that store the KV cache.
    • H_kv: the number of KV heads per layer.
    • d_h: the dimension of each attention head.
    • T: the number of tokens already cached in the context.
    • B: the number of sequences processed simultaneously, i.e., batch size.
    • b_kv: bytes per cached element—2 for FP16, 1 for INT8.

    The result is in bytes. T grows linearly: doubling the context length doubles the KV cache.

    Here is a hypothetical example. Suppose a 7B-class model has 32 layers, L_kv = 32, H_kv = 8, d_h = 128, B = 1, and the KV cache is stored in FP16 (b_kv = 2). When T is 4096:

    M_kv = 2 × 32 × 8 × 128 × 4096 × 1 × 2 = 536,870,912 bytes, about 0.54GB.

    When T grows to 32768, the KV cache is about 4.29GB—already larger than the model’s INT4 weights at roughly 3.5GB (7×10^9 × 0.5 bytes). These parameters are hypothetical and do not represent any specific real model.

    The boundaries of the formula:

    • The sharing scheme determines H_kv and L_kv. GQA lets multiple query heads share one set of KV heads, while MQA keeps only a single set of KV heads. If H_kv drops from 32 to 8, the KV cache at the same sequence length shrinks to one quarter of its original size.