Fitting Large Models on Phones: Balancing Memory, Compute, and Power

    On-device large models are constrained by memory, bandwidth, and thermal limits. This article explains sparse MoE, 4-bit memory estimates, decode-speed upper bounds, and how models, silicon, and inference stacks must work together.

    Why on-device AI is often discussed but rarely ships

    Stronger models usually appear first in the cloud, then shrink through efficiency work until they can run on devices. On-device intelligence is not a new idea. For a long time it stayed theoretical because phone SoCs have limited compute, memory bandwidth, and power budget, so only small models could run locally.

    What changed recently is that some sparse multimodal models became useful in practice. Consider a class of models with about 30 billion total parameters but only about 3 billion activated per token. Compute looks like a small model, while knowledge capacity is closer to a large one.

    One common misunderstanding needs to be cleared up. Even with 4-bit weight quantization, 30 billion parameters still occupy about 15 GB of resident memory (using 1 GB = 10^9 bytes). That is already near the RAM ceiling of current flagship phones, and the OS and other apps need memory too. “Fitting on a phone” is possible only when device, quantization, and model scale match. It is not a claim that every phone can run such a model.

    Speed numbers deserve the same caution. On a specific chip, quantization setup, and short context, these models can generate tens of tokens per second. Change the device, lengthen the context, or run for a few minutes, and throughput can drop sharply. Later sections give a theoretical upper-bound estimate so you can sanity-check numbers before testing.

    Three constraints on on-device inference

    On-device inference is a trade-off among three coupled limits.

    Memory capacity is first. Weights and the KV cache both consume RAM. Theoretical weight size is not free RAM: the OS, background processes, and other apps take a share, so you must leave headroom.

    Compute and bandwidth are second. Decode is usually memory-bandwidth bound. Every generated token requires reading the active weights from memory. Mobile SoC bandwidth is far below datacenter accelerators, so memory access often becomes the bottleneck before arithmetic does.

    Power and thermals are third. Sustained high load triggers frequency throttling, so peak speed falls. Evaluate sustained performance, not the first few seconds after launch.

    “Crossing the line” means all three are in a usable range at once: capability is good enough, memory fits, speed keeps up, and power is acceptable. Only then is on-device intelligence practical.

    How sparse MoE cuts on-device cost

    A dense model activates every parameter for each token, which phones can rarely afford. Mixture-of-Experts (MoE) splits feed-forward layers into experts; a router picks a few experts per token.

    That separates two costs. Total parameters set knowledge capacity and resident memory. Activated parameters set per-token compute and bytes read. MoE can therefore buy larger knowledge capacity at a controlled runtime cost.

    Resident memory still scales with total parameters. Estimating RAM from activated parameters alone undercounts badly. Routing can also unbalance load: hot experts become speed bottlenecks. On device, capacity factors and load-balancing policies can mitigate this.

    Estimating memory after quantization

    Quantization is required to keep a model resident. Weight quantization (INT8, INT4, and similar) sets resident size. KV-cache quantization affects peak memory on long contexts. Mixed precision can keep quality-sensitive layers at higher precision and compress the rest.

    Estimate weights and KV cache separately:

    1. def estimate_weight_gb(total_params_b, bits_per_weight):
    2. """Resident weight memory in GB (1 GB = 10^9 bytes). For MoE, use total parameters."""
    3. return total_params_b * bits_per_weight / 8
    4. def estimate_kv_cache_gb(layers, kv_heads, head_dim, seq_len, bytes_per_elem=2):
    5. """KV cache size in GB. The factor of 2 stores both K and V."""
    6. total_bytes = 2 * layers * kv_heads * head_dim * seq_len * bytes_per_elem
    7. return total_bytes / 1e9
    8. # 30B total params, 4-bit weights
    9. print(estimate_weight_gb(30, 4)) # 15.0
    10. # Hypothetical: 48 layers, 8 KV heads, head_dim=128, context 4096, FP16 KV cache
    11. print(round(estimate_kv_cache_gb(48, 8, 128, 4096, 2), 2)) # ~0.81

    The 48-layer / 8-KV-head figures are assumptions, not a specific model. Use official configs for a real model.

    Three caveats apply. First, tools that report GiB (1 GiB ≈ 1.074 GB) show a number about 7% smaller. Second, the estimate covers only weights and KV cache, not runtime buffers, framework overhead, activations, or fragmentation, so actual use is higher. Third, treat the result as an order-of-magnitude check; measure on the target device.

    A theoretical upper bound on decode speed

    When bandwidth-bound, a rough decode ceiling is:

    theoretical tokens/s ≈ effective memory bandwidth ÷ bytes read per token

    For 3 billion activated parameters at 4-bit, each token reads about 1.5 GB of weights (ignoring embeddings, attention, and other parts). At 60 GB/s effective bandwidth, the ceiling is about 40 tokens/s. Real speed is lower because of scheduling, cache misses, and operator efficiency. Use the formula to judge whether a benchmark is plausible, not as a performance promise.

    Coordinating model, hardware, and infra

    On-device experience is not a single optimization. It is three layers working together.

    The model layer makes the network device-friendly: sparsity, quantization-aware training, and distillation. Hardware maps work to NPU or GPU, fuses operators, and uses memory bandwidth efficiently. Infra is the on-device runtime: operator offload, memory reuse, and streaming output.

    Streaming output drives perceived fluency. A generator with stop conditions:

    1. def stream_reply(model, prompt, stop_tokens, max_new_tokens=512):
    2. """Yield tokens one by one. stop_tokens is the stop set; max_new_tokens caps length."""
    3. for step, token in enumerate(model.stream_generate(prompt)):
    4. if token in stop_tokens or step >= max_new_tokens:
    5. break
    6. yield token