On-Device Multimodal Models: Architecture Selection and Deployment Considerations

    Learn how to evaluate on-device multimodal models by balancing output quality, memory requirements, and computational cost. This article covers dense and mixture-of-experts architectures, multimodal input handling, long-context attention and positional encoding, and per-layer conditioning. It also explains why practical deployment decisions require workload-specific testing rather than parameter counts or advertised context lengths alone.

    1. Why On-Device Multimodal Models Matter

    Over the past two years, much of the discussion around large models has focused on cloud deployments with massive parameter counts. As smartphones, edge gateways, and compact workstations gain computing power, demand for running models directly on local devices is growing.

    On-device deployment offers three immediate benefits: data stays on the device, applications depend less on network connectivity, and per-request inference latency becomes more predictable.

    Developers typically evaluate models against three questions:

    • Can the model handle multiple input types, such as images, audio, and video?
    • How large a model can run within the available device memory?
    • Is its performance on complex tasks good enough for the application?

    The following sections examine these questions through the underlying architectural trade-offs.

    2. Dense Models vs. Mixture-of-Experts Models

    Two common architectures in open-source models are dense models and mixture-of-experts models.

    Dense models use all parameters during every forward pass. Their relatively simple structure and fixed inference path make latency and memory consumption easier to estimate. At a comparable total parameter count, dense models can often offer a higher output-quality ceiling, making them a straightforward choice when quality is the priority and hardware resources are sufficient.

    Mixture-of-experts (MoE) models contain multiple feed-forward networks, called experts. A router selects a small number of experts for each token. Although the total parameter count can be large, only a subset is activated for each token, reducing computation.

    The trade-off is that all expert weights still need to fit in memory. Uneven routing can also overload individual experts and introduce additional communication and scheduling overhead.

    A useful rule of thumb is that MoE emphasizes capability per unit of computational cost, while dense models emphasize quality at a comparable total model size. This is an empirical generalization, not a guarantee; actual performance requires testing.

    The following code estimates the fraction of parameters activated:

    1. def active_ratio(total_params_b: float, active_params_b: float) -> float:
    2. """Calculate the fraction of MoE parameters activated per forward pass."""
    3. return active_params_b / total_params_b
    4. # Example: 26 billion total parameters, 4 billion activated per token
    5. print(f"Active ratio: {active_ratio(26.0, 4.0):.1%}") # Approximately 15.4%

    This ratio illustrates the relationship between active computation and total model capacity. It does not directly predict inference speed. Actual throughput also depends on memory bandwidth, batch size, and the inference framework’s implementation.

    Selection guidance: If device memory is sufficient and output quality is the primary goal, a dense model is often the simpler option. If the goal is to balance larger model capacity with lower computational cost—and the deployment environment can accommodate all expert weights—MoE may be more attractive.

    The central distinction is between how many parameters participate in each computation and how many parameters the model stores overall.

    3. Engineering Implications of Multimodal Input

    Multimodal support can simplify the input pipeline.

    Consider speech input. A traditional pipeline first uses a separate speech recognition model to convert audio into text, then passes that text to a language model. This cascade creates two challenges: recognition errors propagate downstream, and loading and scheduling two models increases system complexity.

    When a model natively supports short audio clips, audio can be encoded directly into its context, reducing intermediate processing steps.

    For images, resolution is a key consideration. Variable-resolution processing allows the number of visual tokens to vary with the image content, balancing detail recognition against computational cost.

    Video is typically sampled at a fixed frame rate, with the resulting frames encoded alongside temporal information.

    The following example illustrates how to assemble a multimodal request. It updates duration metadata and adds a warning when the stated audio duration exceeds the limit; it does not itself trim the underlying audio data.

    1. def build_multimodal_request(text, images=None, audio_clip=None, max_audio_sec=30):
    2. """Assemble multimodal input and flag audio that exceeds the duration limit."""
    3. request = {"text": text, "images": images or [], "audio": None}
    4. if audio_clip is not None:
    5. duration = audio_clip["duration_sec"]
    6. if duration > max_audio_sec:
    7. audio_clip = {**audio_clip, "duration_sec": max_audio_sec}
    8. request["warning"] = (
    9. f"Audio exceeds {max_audio_sec} seconds; "
    10. "duration metadata has been capped."
    11. )
    12. request["audio"] = audio_clip
    13. return request

    In production, validate input length, format, and size at the request boundary. This helps prevent oversized inputs from consuming the context window and slowing overall response times.

    4. Positional Encoding for Long Contexts

    Transformers do not inherently represent sequence order. Positional encoding introduces position information into attention calculations.

    Rotary position embedding, or RoPE, is a common approach. It applies rotations to query and key vectors so that attention scores reflect the relative positions of tokens.

    Very long contexts introduce two distinct challenges:

    1. Positions beyond the training length can cause distribution shifts and reduce output quality.
    2. Global attention has computational cost that grows quadratically with sequence length.

    One architectural approach combines different attention patterns across layers:

    • Sliding-window layers attend only to a local neighborhood. For a fixed window size, their computational cost grows approximately linearly with context length. They capture local syntax and structure.
    • Global-attention layers access the full context to capture long-range dependencies. These layers may use scaled or otherwise adjusted positional encoding to reduce distortion beyond the training length.

    This division of responsibilities helps control computational cost while retaining access to distant information where needed.

    Evaluate long-context capability using long documents from the intended workload. The advertised context-window size alone is not a reliable measure of practical performance.

    5. Per-Layer Conditioning: Injecting Token Information Where It Is Needed

    A standard Transformer assigns an embedding vector to each token at the input. Subsequent layers progressively transform that representation, so the initial embedding must carry substantial information. As processing moves through deeper layers, information from the original input may become diluted.

    Per-layer conditioning introduces a parallel, low-dimensional pathway. For each token, the model generates a small vector dedicated to each decoder layer. These vectors combine token-identity information with context-aware signals.

    Each layer can then access its corresponding vector to obtain token-specific information relevant to its computation, rather than relying entirely on the original input embedding.

    The following excerpt shows the embedding-table setup and expected shape of the contextual signal:

    1. import torch
    2. import torch.nn as nn
    3. class PerLayerConditioning(nn.Module):
    4. def __init__(self, vocab_size, num_layers, cond_dim):
    5. super().__init__()
    6. # Store a low-dimensional conditioning vector for each layer.
    7. self.token_table = nn.Embedding(vocab_size, num_layers * cond_dim)
    8. self.num_layers = num_layers
    9. self.cond_dim = cond_dim
    10. def forward(self, token_ids, context_proj):
    11. # context_proj: contextual signal projected from the current hidden states.
    12. # Shape: [B, T, num_layers * cond_dim]

    This is a partial implementation, not a complete runnable module. The conditioning table’s parameter count depends on vocab_size, num_layers, and cond_dim; its size relative to the main embedding table depends on the dimensions chosen.