On-Device Multimodal Models: Revisiting the Encoder-Decoder Architecture

    This article examines why encoder-decoder architectures deserve a second look for on-device multimodal applications. It covers the practical bottlenecks of decoder-only models (hallucination risk, long multimodal sequences, and KV cache growth), the structural advantages of encoder-decoder designs such as T5/mT5, selection criteria for small models under 10B parameters, deployment practices including quantization, on-device/cloud routing, cloud-native orchestration, monitoring, and a pre-launch checklist.

    1. Three Practical Bottlenecks of Decoder-Only Architectures

    Most mainstream LLMs use a decoder-only structure trained on next-token prediction, which works reliably for general conversation, code generation, and text summarization. Once these models move into enterprise scenarios and edge devices, three problems recur.

    1. Outputs that drift from the input evidence
    A decoder-only model can only attend to previously generated tokens during generation; there is no separate encoding stage between the input material and the output. For tasks that require answers strictly grounded in the source material—such as contract clause Q&A or financial statement interpretation—the model may fill in content that does not exist in the material. In practice, teams have to add retrieval augmentation, answer citation checks, and fact verification on top, all of which increase latency and cost.

    2. Multimodal inputs inflate sequence length
    The common approach is to split images into patches, encode them as visual tokens, and concatenate them with text tokens into one long sequence. A single image can produce hundreds of tokens. Full attention computation scales roughly quadratically with sequence length, so longer sequences mean heavier compute and larger in-memory caches.

    3. The decode cache grows with generation length
    During generation, a decoder-only model must store the historical keys and values of every layer—the KV cache. The longer the generation, the larger the cache. On a phone or edge box with only a few gigabytes of memory, long answers directly consume the memory available to the system.

    2. Structural Advantages of the Encoder-Decoder Architecture

    The classic encoder-decoder architecture consists of two components: an encoder and a decoder. T5 and its multilingual variant mT5 are typical examples.

    1. Bidirectional attention on the input side
    In the encoder, every position can see the full context of the input, producing a complete representation of it. The decoder then reads the encoded result through cross-attention and generates output step by step. Input understanding and output generation are separate responsibilities, which makes it easier for the model to confine generated content to the scope of the input. This structure helps reduce certain hallucinations, but it does not eliminate them. Outputs on knowledge-intensive tasks still require fact checking.

    2. Clear division of labor for multimodal inputs
    The encoder can receive text tokens and visual features simultaneously for joint encoding, while the decoder focuses on generating answers. With clear module boundaries, debugging is easier: when an answer is wrong, you can evaluate the visual encoder and the adapter layer separately to determine whether the error came from perception or generation.

    3. Two directions for modernization
    The first is positional encoding. RoPE and its variants—for example, methods that scale the base frequency—can improve model behavior beyond the training length. The actual effect depends on training length, scaling factor, and the specific task, so long-text accuracy must be measured on a validation set.

    The second is attention structure. Grouped-query attention (GQA) lets multiple query heads share fewer key and value heads, shrinking the cache. Sliding-window attention or sparse attention can reduce computation on long sequences, but at the cost of long-range dependencies. Which approach to choose depends on whether the task requires global context.

    3. Selecting Small Models and Understanding Their Limits

    Models under 10 billion parameters are the main candidates for on-device multimodal deployment. When comparing options, consider the following dimensions:

    • Parameter count vs. target device memory: after INT4 quantization, weights occupy roughly 0.5 bytes per parameter, with additional headroom needed for caches and runtime overhead.
    • Task type: visual question answering, receipt recognition, and short-text rewriting have very different capability requirements.
    • Output length: the longer the output, the larger the decode-side cache.
    • License: confirm whether the model permits commercial use and whether attribution is required.

    On some tasks, a small encoder-decoder model of the same parameter count may follow complex instructions more reliably, but this must be confirmed through benchmarking on your own task data—conclusions from published papers should not be applied directly.

    Regarding memory, two parts must be distinguished. The encoder-side cross-attention cache length is determined by the input and stays constant during decoding, so it can be allocated in advance. The decoder-side autoregressive cache still grows with output length. Fixing the encoder length therefore only controls part of the memory; you also need to cap the output length and apply quantization or paged management to the cache.

    The common multimodal paradigm is “visual encoder + adapter layer + text encoder-decoder.” The visual encoder extracts image features, the adapter layer projects those features into the text encoder’s input space, and the encoder then jointly encodes them with the text. Adapter training typically happens in two stages. First, freeze the visual encoder and the language module, and train only the adapter on image-text pairs, usually with cross-entropy loss on the decoder side. Second, perform a small amount of full-parameter fine-tuning on instruction data. For evaluation, public datasets such as VQA and TextVQA can be used, supplemented with in-house samples, since the distribution of public datasets usually differs from real-world scenarios.

    4. Common Practices for On-Device Deployment

    1. Quantization and compilation

    • Tooling: choose an inference framework per target platform, such as ONNX Runtime, TensorRT, TFLite, Core ML, or MNN.
    • Quantization method: post-training quantization methods such as GPTQ or AWQ can be used for weight quantization. Test both INT8 and INT4 rather than only one.
    • Calibration set: use 300 to 1,000 samples representative of real workloads, covering short questions, long questions, and various image types.
    • Acceptance metrics: record the accuracy delta versus FP16, time to first token, per-token latency, and peak memory. If the accuracy drop exceeds the business threshold, fall back to higher bit-widths or change the model architecture.
    • Operator fusion: compilers merge adjacent operators to reduce memory reads and writes of intermediate results. Whether fusion actually took effect should be verified through compile logs and measured latency.

    2. On-device/cloud routing
    Routing rules can be based on three checks:

    • The local model’s confidence falls below a threshold, e.g., the mean generation probability is below a set value.
    • The request involves questions requiring up-to-date information or long-tail knowledge.
    • Local inference exceeds a timeout, e.g., 800 ms, in which case the request is forwarded to the cloud.

    When the cloud is unavailable, the system should return the local result with a notice that it may be incomplete, rather than letting the request fail outright. Before uploading, sensitive fields such as faces, ID numbers, and phone numbers should be masked or cropped locally; only the text or features necessary to complete the task should be uploaded.

    3. Cloud-native orchestration
    Container platforms (such as Kubernetes) can manage multiple model instances and support canary releases by device group. Message queues (such as Kafka or RabbitMQ) absorb traffic spikes by queuing multimodal requests by priority. The gateway handles authentication, rate limiting, and routing. Message queues add latency, so real-time interactive requests should connect directly to the model; only offline parsing-type tasks should go through the queue.

    4. Monitoring and iteration

    • Logging: record latency distributions, peak memory, thermal throttling events, and routing outcomes.
    • Feedback: hallucination cases flagged by users enter an annotation queue and, after human confirmation, become training samples.
    • Releases: perform small-scale fine-tuning of the adapter layer or decoder in the cloud, then push to devices as versioned canary rollouts. Each release must be evaluated against the previous version, and rolled back immediately if metrics regress.

    5. Pre-Launch Checklist

    1. Define the task type and acceptable error rate.
    2. Test on target devices, not only on server GPUs.
    3. Set an upper bound on output length.
    4. Keep a fallback path so a cloud service or previous model version can take over requests.
    5. Build an evaluation set from business data and update it regularly.

    6. Conclusion

    Decoder-only remains the mainstream choice for general-purpose generation. The encoder-decoder architecture offers clear advantages in input grounding, module separation, and certain long-sequence scenarios, while also having its own limits around caching and length. Developers should benchmark on their own hardware and data before deciding which architecture to adopt.