Deploying On-Device Multimodal LLMs: Memory, Compute, and Evaluation for MoE Systems

    This article provides a practical guide to deploying large multimodal models on edge devices, focusing on the critical constraints of memory, compute, and evaluation. It clarifies the distinction between total and active parameters in Mixture-of-Experts (MoE) models, outlines a structured memory budget, and details the trade-offs of quantization. The discussion also covers inference speed optimization, KV Cache management, and the specific challenges of real-world multimodal tasks like OCR and chart understanding.

    Understanding the Two Key Numbers: Total vs. Active Parameters

    Mixture-of-Experts (MoE) models divide the network into multiple “experts”. During each inference step, a routing network activates only a small subset of these experts for computation. This architecture allows a model to have a large total parameter count while maintaining a relatively small computational load per token.

    Take, for example, a model with 35 billion total parameters and approximately 3 billion active parameters per inference step. Two separate considerations are needed here:

    1. Storage: All expert weights must reside in device storage. The total weight determines the model file size.
    2. Compute: Each token only passes through the selected experts, which defines the actual computational cost.

    A common misconception is that “a 35B model can run with the memory footprint of a 3B model.” This is incorrect. The accurate interpretation is that the computational cost is comparable to that of a ~3B dense model, but the memory footprint is still tied to the ~35B total parameter weight.

    MoE introduces two practical challenges on edge devices. First, load imbalance: some experts are frequently selected while others are rarely used. A common strategy is to keep “hot” experts resident in memory and load “cold” experts on demand. Second, cold start latency: the first invocation of an expert requires reading its weights from storage, increasing the first-token latency. Engineering solutions often involve expert caching, prefetching, and layer-wise sharding to mitigate this.

    On-Device Memory Budget: Weights, KV Cache, and Runtime

    A phone’s available memory is typically only a few gigabytes, shared with the OS and other applications. Therefore, a detailed memory budget is essential before deployment—you cannot simply rely on the model file size.

    Memory usage consists of at least four components:

    • Model weights: The dominant storage cost.
    • KV Cache: This grows linearly with context length and can become surprisingly large in long-conversation or long-document scenarios.
    • Activations and intermediate tensors: Temporary data created during a forward pass.
    • Inference framework runtime overhead: The baseline memory used by the inference engine itself.

    Estimating weight memory. The formula is straightforward: Total Parameters × Bytes per Parameter. Using the 35B total parameter example:

    • FP16: 2 bytes per parameter → ~70 GB
    • INT8: 1 byte per parameter → ~35 GB
    • INT4: 0.5 bytes per parameter → ~17.5 GB

    These figures ignore quantization scale parameters, KV Cache, and runtime overhead, so the actual footprint will be higher. A 35B-parameter model cannot fit in a few gigabytes of memory through quantization alone; deployment requires on-demand expert loading, sharding, or a smaller model.

    To estimate a target: if you want weights resident in memory at roughly 3 GB, at INT4 precision, this corresponds to a total weight of approximately 6 billion parameters (3 GB / 0.5 bytes). This estimate leaves no room for KV Cache or system overhead, so the practical parameter limit is lower.

    A structured memory budget should include:

    • Resident weights: Based on total parameters and quantization bit-width.
    • Active expert cache: Based on the number of experts kept concurrently resident.
    • KV Cache: Based on maximum context length, number of layers, KV heads, and data type.
    • Runtime and intermediate tensors: Based on measured peak values.
    • Peak memory: The sum of the above, plus a system safety margin—we recommend reserving at least 20% above the baseline.

    Quantization: Balancing Compression and Accuracy

    Quantization maps FP16 weights to lower-precision formats like INT8 or INT4. Lower bit-widths reduce storage requirements and memory bandwidth pressure, but they also introduce quantization error.

    There are five key considerations in practice:

    1. Calibration dataset. Quantization scales depend on the numerical distribution of real input data. The calibration set should reflect the target deployment scenario, such as image-based Q&A, OCR-style documents, or math problem images. A practical approach is to use several hundred to a few thousand samples that align with the actual online input distribution.

    2. Quantization granularity. Granularity can be per-tensor, per-channel, or per-group. Finer granularity generally yields better accuracy but requires storing more scale parameters. INT4 models typically use group quantization, where the group size is a trade-off between precision and the overhead of additional scale factors.

    3. Outlier handling. A small number of channels can have significantly larger magnitudes than the rest of the model. Direct quantization of these channels can cause significant error. Solutions include keeping these outlier channels at higher precision or applying transformations before quantization to flatten the numerical range.

    4. Per-module precision. Vision encoders are often more sensitive to detail than text generation. For example, OCR tasks tend to degrade more noticeably with aggressive quantization than general pure-text generation. It may be prudent to assign different bit-widths to the vision components and the language model components.

    5. Accuracy fallback thresholds. Set clear acceptance criteria before deployment—for example, a maximum allowed accuracy drop relative to an FP16 baseline on a curated evaluation set. Any layer or module exceeding this threshold should revert to a higher bit-width. The threshold is task-dependent and should not be copied from other projects.

    Decoding Speed and KV Cache Management

    A common target for on-device token generation is around 30 tokens per second, often considered the threshold for smooth reading. Real-world speed is limited by memory bandwidth, quantization format, and operator implementation. The generation phase is typically memory-bandwidth-bound, so reducing the weight volume read per token is more impactful than simply increasing raw compute capacity.

    Operator fusion reduces the number of intermediate results written to memory. For example, fusing normalization, activation functions, and matrix multiplication into a single operation reduces memory access overhead.

    Effective KV Cache management strategies include:

    • Capping the maximum context length.
    • Summarizing or truncating historical conversation turns.
    • Applying quantization to the KV Cache itself.
    • Evicting least-recently-used session caches under memory pressure.

    The best strategy depends on whether the application genuinely requires long-term memory.

    Multimodal Deployment: Visual Understanding and Long-Form Video

    On-device multimodal models typically consist of a vision encoder, a projection module, and a language model. Images are encoded into a set of visual tokens before being passed to the language model alongside text. Higher image resolution generates more visual tokens, increasing both memory and latency—so resolution is often chosen dynamically based on the task.

    For handwriting recognition in math problems, the model must first accurately identify characters and formula structures before reasoning. If input resolution is too low, symbols will be misread, and even a strong reasoning engine will produce wrong answers. Visual fidelity is a prerequisite for downstream multimodal reasoning.

    OCR and chart understanding come with similar constraints. For document images, region-based cropping is a practical approach. For charts, it is often useful to first extract the underlying data table and then answer questions about it. These approaches reduce the visual token load per inference and improve overall reliability.