Choosing and Fine-Tuning Open-Source LLMs for On-Device Deployment: Key Considerations

    A practical guide to selecting open-source large language models for edge devices. This article compares dense and MoE architectures, examines the engineering value of native multimodal input, explains position encoding design for long contexts, and introduces per-layer conditional embeddings—helping developers make informed decisions before fine-tuning.

    1. Background

    Open-source LLMs now come in an ever-growing range of sizes. A single model generation is often released in dense, mixture-of-experts (MoE), and small-parameter variants targeting edge devices. For developers, model selection can no longer rely on leaderboard scores alone; it must also weigh inference cost, memory footprint, multimodal capabilities, context length, and headroom for later fine-tuning.

    This article starts from the publicly available specifications and community feedback on a new generation of open-source models, and abstracts product-specific details into several general technical questions, explaining the underlying principles and engineering implications of each. Since community benchmarks have not yet converged on a unified standard, the judgments here are based mainly on architectural principles rather than single-run experiences.

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

    Mainstream large models today fall into roughly two architectural categories.

    Dense models activate all parameters in every forward pass. Their structure is straightforward, training and fine-tuning behavior is relatively predictable, and for a given parameter count their capability ceiling is usually higher. The downside is that inference compute scales roughly linearly with total parameter count.

    Mixture-of-experts (MoE) models split the feed-forward layers into multiple expert subnetworks, with a router selecting a small number of experts for each token. Total parameter count can be very large, but only a subset is activated per inference, giving higher knowledge capacity per unit of compute. The trade-off: all experts must still fit in memory, and routing imbalance and training stability require extra handling.

    Dimension Dense MoE
    Inference compute per pass Proportional to all parameters Proportional to activated parameters
    Memory footprint Roughly equal to parameter count Must hold all experts
    Capability ceiling More stable at equal activated scale Depends on routing quality and expert training
    Fine-tuning complexity Lower Requires attention to routing and expert load

    A common industry saying goes: MoE favors cost-efficiency, while dense models favor capability ceilings. In practice, however, each team’s spec mix is usually determined by deployment goals. Server-side batch inference may suit MoE better, while scenarios requiring stable fine-tuning and predictable behavior may favor dense architectures. Clarify your business scenario first, then decide on the architecture.

    3. The Engineering Value of On-Device Multimodal Input

    Traditional on-device voice interaction pipelines chain multiple modules together: audio capture, a standalone speech recognition model, a text understanding model, and reply generation. Every added module means one more model loaded into memory, an extra inference delay, and one more point where errors propagate downstream.

    If the model natively supports audio input, the pipeline simplifies to feeding audio directly into the model. This brings three benefits:

    1. Simplified deployment: the device no longer needs to keep multiple models resident, reducing memory and power pressure.
    2. Lower latency: intermediate text conversion steps are eliminated.
    3. Information preservation: non-textual cues in speech—tone, pauses—no longer get lost in transcription.

    Note that native audio capability typically has a per-input duration limit. Short commands and single-turn requests after wake-up are well suited to direct input, while long recordings still need to be segmented or handled by a dedicated transcription solution. Image and video input likewise requires attention to resolution strategy. Variable resolution means the model can choose different numbers of visual tokens based on image content and device compute, trading off accuracy against speed.

    4. Position Encoding Design for Long Contexts

    A Transformer is inherently order-agnostic; position encoding supplies this information. Rotary position embedding (RoPE) applies position-dependent rotations to query and key vectors, so attention scores naturally contain relative position information—making it the most common approach today.

    For long contexts, the problem arises from a mismatch between training and inference position ranges. During training, the model only sees a limited range of positions; at inference, the further along a position is, the more the rotation angle distribution drifts from the training distribution, degrading attention quality. Common mitigation approaches fall into three categories:

    • Adjusting the rotation base frequency, or scaling position indices proportionally, to extend the representable position range;
    • Applying different position encoding strategies to different layers;
    • Continuing pretraining or fine-tuning on long texts so the model adapts to longer position ranges.

    One approach is a per-layer division of labor. Sliding-window layers only attend to nearby tokens and can use standard position encoding; global attention layers must span the full sequence and use a scaled encoding variant. Since the two layer types serve different roles, giving each an appropriate positional representation is more sensible than applying a single uniform encoding to all layers. The following configuration sketch illustrates this layered approach (fields are illustrative, not a real model’s configuration):

    1. # Illustrative: choosing position encoding strategy per attention layer type
    2. layer_configs = [
    3. {"type": "sliding_window", "rope": "standard", "window": 1024},
    4. {"type": "sliding_window", "rope": "standard", "window": 1024},
    5. {"type": "global", "rope": "scaled", "scale": "computed from target context length"},
    6. ]

    When assessing long-context capability, don’t rely on configuration parameters alone. A more reliable approach is to design retrieval- and reasoning-style tests, measure the model’s information recall at different positions, and compare results against short-context performance.

    5. Per-Layer Conditional Embeddings: Injecting Token Information on Demand

    A standard Transformer assigns each token an embedding vector at the input, after which layers progressively refine the residual stream. This means the initial embedding must carry all information the token might need across every downstream layer—concentrating the informational burden at the entry point.

    Per-layer conditional embedding adds a parallel low-dimensional pathway. For each token, the model generates a dedicated small vector for every decoder layer, composed of two parts:

    • Token identity signal: a stable representation corresponding to the vocabulary entry;
    • Context-aware signal: a modulation term computed from the current hidden state.

    Each layer reads its own vector when needed, injecting token-specific information layer by layer. Early layers no longer need to carry details only required later, improving parameter efficiency. For on-device deployment, the low-dimensional identity tables can also be placed in larger, slower storage and fetched on demand, easing memory pressure. The following pseudocode shows this combination:

    1. # Illustrative pseudocode: composing and injecting per-layer conditional vectors
    2. def layer_condition(token_id, hidden_state, layer_idx):
    3. identity = per_layer_table[layer_idx][token_id] # token identity signal, low-dimensional
    4. context = proj[layer_idx](hidden_state) # context-aware signal
    5. return identity + context
    6. def decoder_layer(h, token_id, layer_idx):