Pidoku

The Device Landscape and Its Limits

Module 29 Lesson 29.a 1h Difficulty 3/5

Prerequisites 2.e, 2.f, 7.f, 12.f, 15.e


Before you start: words you need#

WordPlain meaning
On-device inferenceRunning the model on the user’s own phone, laptop, car or board, not on a server.
EdgeAny computer outside the data centre that sits close to where data is made: a phone, a factory box, a camera, a robot.
SoC“System on a chip”: one chip that holds the CPU, GPU, NPU, memory controller and more. Every phone and Apple Mac uses one.
Unified memoryOne pool of RAM shared by CPU, GPU and NPU, so none of them has to copy data to the others.
LPDDR“Low-power DDR”, the memory used in phones and thin laptops. Cheap on power, modest on bandwidth.
Memory budgetHow much RAM your app may actually use before the operating system kills it or other apps suffer. Always less than the RAM on the box.
Thermal throttlingThe chip slowing itself down because it is getting too hot. Phones do this within minutes of heavy work.
Joules per tokenThe energy one generated token costs. On a battery it matters as much as tokens per second.

1. What is it?#

The device landscape is the set of machines people run models on outside the data centre, and the limits each one sets. This module goes deeper than the overview in 15.e: how the engines work inside (29.b), Apple silicon (29.c), mobile runtimes (29.d), NPUs (29.e), quantization for small devices (29.f) and splitting work between device and cloud (29.g). This first lesson builds the mental model they all use.

Five classes of device matter in 2026:

ClassExamples (2026)MemoryBandwidthSustained power
Microcontrollers and tiny boardsArm Cortex-M with Ethos-U NPU, Raspberry Pi 5KB to 16 GB~17 GB/s (Pi 5)0.01–10 W
PhonesiPhone 17 Pro (A19 Pro), iPhone 18 Pro (A20 Pro), Snapdragon 8 Elite Gen 5 phones, Pixel 11 (Tensor G6)8–16 GB~70–120 GB/sa few W
Laptops (“AI PCs”)MacBook with M5, Snapdragon X2 Elite, Intel Core Ultra series 3, AMD Ryzen AI 40016–128 GB~120–256 GB/s15–60 W
Desk machinesMac Studio M5 Max / M5 Ultra, Ryzen AI Max+ 395 boxes, DGX Spark96–512 GB0.25–1.2 TB/s100–300 W
Embedded and roboticsJetson Orin Nano Super, Jetson AGX Thor (7.f), automotive SoCs8–128 GB~100–275 GB/s10–130 W

Facts checked on 13 November 2026.


2. Why does it matter?#

Three forces push inference onto devices:

  1. Privacy and data rules. Messages, photos, health data and on-screen content never leave the device. This is the reason Apple, Google and Microsoft all ship an on-device model with the operating system (Apple Foundation Models, Gemini Nano, Phi Silica).
  2. Latency and availability. No network round trip, no outage, works in a lift or on a plane. A keyboard suggestion or a voice wake word cannot wait 300 ms for a server.
  3. Cost. The user paid for the silicon. Every token generated on a phone is a token the provider does not pay for in a data centre. At billions of users that changes the economics (23.c).

But the device sets hard limits that a data-centre engineer rarely meets:

  • Memory is small and shared. A 12 GB phone also runs the OS, the camera and the browser.
  • Bandwidth is low. A phone reads memory at about one-hundredth of a B200’s 8 TB/s.
  • Power and heat are capped. A phone cannot dissipate more than a few watts for long.
  • The hardware is fragmented. Thousands of chip and OS combinations, each with different accelerators and drivers.
  • You cannot upgrade it. The model must fit the devices people already own.

3. Simple analogy#

A data centre is a restaurant kitchen: big fridges, many cooks, power from the grid, and when it gets hot someone turns up the air conditioning. A phone is a camping stove in a backpack: one small pot (memory), a thin gas pipe (bandwidth), a fuel canister that runs out (battery), and if you cook too long the stove gets too hot to touch and you must turn the flame down (throttling). You can still cook a good meal, but only with a recipe designed for that stove.


4. Tiny example: one model, three devices#

An 8-billion-parameter model at Q4_K_M (about 4.9 bits per weight, 29.b) is 4.9 GB. Its KV cache (12.e) at FP16 is 128 KiB per token, so an 8,192-token context adds about 1.1 GB.

MacBook Air M5, 16 GB, 153 GB/s
  memory: 4.9 + 1.1 + 0.5 runtime = 6.5 GB, budget ~11 GB  → fits
  decode: 153 GB/s ÷ 6.0 GB read per token                 → ≤ 26 tok/s

Flagship phone, 12 GB, ~80 GB/s
  memory: 6.5 GB, but an app gets perhaps half of 12 GB    → does not fit with 8k context
  shrink: 3B model at 4 bits (1.8 GB) + 8k KV (0.9 GB)      → fits, ≤ ~30 tok/s

Raspberry Pi 5, 8 GB, 17 GB/s
  3B model fits, but 17 GB/s ÷ 2.7 GB                       → ≤ 6 tok/s

The arithmetic is the same as in the data centre (2.f); only the numbers are smaller. Two surprises already show: on small models the KV cache is as big as the weights, and the phone’s memory budget, not its RAM, is what decides.


5. Technical explanation#

The four budgets#

Every on-device design is limited by four budgets at once. Running out of any one of them ends the design.

BudgetWhat sets itWhat it limitsTypical fix
Memory capacityRAM minus OS and other apps; per-app limitsmodel size + KV cache + activationssmaller or more quantized model, shorter context, KV quantization, weights streamed from flash
Memory bandwidthLPDDR bus width × speeddecode speed (tokens per second)fewer bytes per token: quantization, MoE, speculative decoding
ComputeCPU/GPU/NPU throughput at sustainable clocksprefill speed (time to first token), vision encodersNPU or GPU tensor units, shorter prompts, prompt caching
Energy and heatbattery capacity, thermal designhow long the device can keep going, sustained clocksdo less work per token, move work off the device (29.g)

Memory capacity: the budget is not the RAM#

On a phone the OS decides how much memory an app may use and kills apps that exceed it. iOS raises the limit for apps that hold the “increased memory limit” entitlement; Android kills background apps under memory pressure. In practice an app on a 12 GB phone can rarely count on more than half of it, and the true figure depends on what else is running. This is why the operating-system vendors run the shared model themselves, inside a system service (Android’s AICore, Apple’s Foundation Models daemon): one copy of the weights serves every app, instead of every app loading its own.

Three tricks stretch capacity:

  • Memory mapping (mmap). The weights file is mapped into memory; the OS pages in what is used and can drop clean pages under pressure without killing the app, then re-read them from flash (29.b).
  • Keep rarely used weights in flash. Gemma 4’s E2B and E4B models keep large per-layer embedding tables memory-mapped from storage, so a model with about 5B stored parameters behaves like 2.3B in RAM. Apple’s AFM 3 Core Advanced (June 2026) stores all 20B parameters in flash and loads only 1–4B “routed experts” into DRAM per prompt (29.c).
  • Shrink the KV cache. Grouped-query attention (12.g), sliding-window layers, KV sharing between layers (Apple’s 2025 on-device model shares caches and saves 37.5%), and 8-bit or 4-bit KV (13.h).

Memory bandwidth: the decode ceiling#

With one user, every decoded token reads every active weight once, plus the KV cache (12.c):

decode tokens/s  ≤  bandwidth  ÷  (active weight bytes + KV bytes read per token)

Device bandwidths, from published specifications (the phone and Pi figures are computed from bus width and memory speed, which vendors do not always publish):

DeviceMemoryPeak bandwidth
Raspberry Pi 5LPDDR4X-4267, 32-bit~17 GB/s
iPhone 17 Pro (A19 Pro)12 GB LPDDR5X-9600, 64-bit~77 GB/s
Snapdragon 8 Elite Gen 5 phoneLPDDR5X at ~10.7 Gb/s per pin, 64-bit~85 GB/s
iPhone 18 Pro (A20 Pro)launch coverage reports “50% more memory bandwidth than A19 Pro”; Apple publishes no GB/s figure~115 GB/s (derived, unconfirmed)
MacBook with M5unified LPDDR5X153 GB/s
Snapdragon X2 Elite / X2 Elite ExtremeLPDDR5X, 128-bit / 192-bit152 / 228 GB/s
Ryzen AI Max+ 395LPDDR5X-8000, 256-bit256 GB/s
DGX Spark (GB10)LPDDR5X273 GB/s
Mac Studio M5 Max / M5 Ultraunified LPDDR5X614 GB/s / 1.2 TB/s

Two levers reduce bytes per token: fewer bits per weight (29.f) and fewer active weights (mixture-of-experts models, 14.g; or speculative decoding, 12.n, which verifies several tokens per weight read).

Compute: the prefill ceiling#

Prefill (reading the prompt) is matrix-matrix work and is limited by compute, not bandwidth (12.c). On a laptop a 4,000-token prompt on a 14B model can take several seconds; on a phone, longer. This is what NPUs and GPU tensor units help with (29.e). Apple measured the M5’s GPU neural accelerators cutting time to first token by 3.3–4.1x against M4 in MLX, while decode improved only 19–27%, in line with the bandwidth gain (29.c). Prefill is compute; decode is bandwidth.

Agents, retrieval and long chat histories make prompts long, so on devices time to first token is often the user-visible problem, not tokens per second.

Energy and heat#

A phone can draw 10 W or more for a burst, but its case can only shed a few watts continuously. After a minute or two of heavy generation the SoC lowers its clocks. So:

  • Benchmarks on a cold phone are optimistic. Measure after five minutes of continuous load.
  • Energy per token is power ÷ tokens per second. At 5 W and 20 tokens per second, a token costs 0.25 J; a 1,000-token answer costs 250 J, about 0.07 Wh, or roughly 0.4% of a 17 Wh phone battery. Cheap once; expensive as a background agent that runs all day.
  • NPUs exist mostly for energy: they do the same matrix work at a fraction of the GPU’s power (29.e).

Fragmentation#

A data-centre team picks one or two GPU types. An app team ships to every phone its users own: several CPU generations, Adreno, Mali, Apple and PowerVR GPUs, NPUs from Qualcomm, MediaTek, Samsung, Google and Apple, each with its own compiler and operator coverage. The practical answer is layers:

  • a portable baseline that runs everywhere (CPU kernels: XNNPACK, KleidiAI, llama.cpp’s CPU backend),
  • accelerated paths for the devices most users own (GPU through Metal, OpenCL or Vulkan; NPU through vendor delegates),
  • the OS model where it exists (Gemini Nano, Apple Foundation Models), and
  • the cloud as the fallback for everything else (29.g).

6. Under the hood: a fit-and-speed calculator#

This program checks which models fit which devices, with an 8,192-token KV cache at FP16, and prints the decode ceiling. The per-app budget fractions are assumptions, not vendor numbers: change them for your target.

Go
// fit.go — which models fit which devices, and how fast can they decode?
package main

import "fmt"

type device struct {
	name   string
	ramGB  float64 // total memory
	budget float64 // share of it one app can realistically use (assumption)
	bwGBs  float64 // peak memory bandwidth
}

type model struct {
	name     string
	totalB   float64 // parameters stored (billions)
	activeB  float64 // parameters read per token (billions)
	bits     float64 // average bits per weight, scales included
	kvKiBTok float64 // KV cache per token at FP16 (KiB)
}

func main() {
	devices := []device{
		{"Raspberry Pi 5 (8 GB)", 8, 0.75, 17},
		{"iPhone 17 Pro (A19 Pro)", 12, 0.5, 76.8},
		{"Snapdragon 8 Elite Gen 5 phone", 12, 0.5, 85},
		{"MacBook Air M5 (16 GB)", 16, 0.7, 153},
		{"Ryzen AI Max+ 395 (128 GB)", 128, 0.75, 256},
		{"Mac Studio M5 Max (128 GB)", 128, 0.75, 614},
	}
	models := []model{
		{"3B dense, 4-bit", 3.2, 3.2, 4.5, 112},
		{"8B dense, Q4_K_M", 8.0, 8.0, 4.89, 128},
		{"30B-A3B MoE, 4-bit", 30.5, 3.3, 4.5, 96},
		{"70B dense, Q4_K_M", 70.6, 70.6, 4.89, 320},
	}
	const ctx = 8192 // tokens of context held in the KV cache

	for _, m := range models {
		weightsGB := m.totalB * m.bits / 8
		kvGB := m.kvKiBTok * 1024 * ctx / 1e9
		readGB := m.activeB*m.bits/8 + kvGB // bytes touched per decoded token (full context)
		fmt.Printf("%s: weights %.1f GB + KV(8k) %.1f GB, reads %.1f GB per token\n",
			m.name, weightsGB, kvGB, readGB)
		for _, d := range devices {
			need := weightsGB + kvGB + 0.5 // +0.5 GB runtime and activations
			have := d.ramGB * d.budget
			if need > have {
				fmt.Printf("    %-32s does not fit (needs %5.1f GB, budget %5.1f GB)\n", d.name, need, have)
				continue
			}
			fmt.Printf("    %-32s fits; decode ceiling %4.0f tok/s\n", d.name, d.bwGBs/readGB)
		}
	}
}

Output:

3B dense, 4-bit: weights 1.8 GB + KV(8k) 0.9 GB, reads 2.7 GB per token
    Raspberry Pi 5 (8 GB)            fits; decode ceiling    6 tok/s
    iPhone 17 Pro (A19 Pro)          fits; decode ceiling   28 tok/s
    Snapdragon 8 Elite Gen 5 phone   fits; decode ceiling   31 tok/s
    MacBook Air M5 (16 GB)           fits; decode ceiling   56 tok/s
    Ryzen AI Max+ 395 (128 GB)       fits; decode ceiling   93 tok/s
    Mac Studio M5 Max (128 GB)       fits; decode ceiling  224 tok/s
8B dense, Q4_K_M: weights 4.9 GB + KV(8k) 1.1 GB, reads 6.0 GB per token
    Raspberry Pi 5 (8 GB)            does not fit (needs   6.5 GB, budget   6.0 GB)
    iPhone 17 Pro (A19 Pro)          does not fit (needs   6.5 GB, budget   6.0 GB)
    Snapdragon 8 Elite Gen 5 phone   does not fit (needs   6.5 GB, budget   6.0 GB)
    MacBook Air M5 (16 GB)           fits; decode ceiling   26 tok/s
    Ryzen AI Max+ 395 (128 GB)       fits; decode ceiling   43 tok/s
    Mac Studio M5 Max (128 GB)       fits; decode ceiling  103 tok/s
30B-A3B MoE, 4-bit: weights 17.2 GB + KV(8k) 0.8 GB, reads 2.7 GB per token
    Raspberry Pi 5 (8 GB)            does not fit (needs  18.5 GB, budget   6.0 GB)
    iPhone 17 Pro (A19 Pro)          does not fit (needs  18.5 GB, budget   6.0 GB)
    Snapdragon 8 Elite Gen 5 phone   does not fit (needs  18.5 GB, budget   6.0 GB)
    MacBook Air M5 (16 GB)           does not fit (needs  18.5 GB, budget  11.2 GB)
    Ryzen AI Max+ 395 (128 GB)       fits; decode ceiling   96 tok/s
    Mac Studio M5 Max (128 GB)       fits; decode ceiling  231 tok/s
70B dense, Q4_K_M: weights 43.2 GB + KV(8k) 2.7 GB, reads 45.8 GB per token
    Raspberry Pi 5 (8 GB)            does not fit (needs  46.3 GB, budget   6.0 GB)
    iPhone 17 Pro (A19 Pro)          does not fit (needs  46.3 GB, budget   6.0 GB)
    Snapdragon 8 Elite Gen 5 phone   does not fit (needs  46.3 GB, budget   6.0 GB)
    MacBook Air M5 (16 GB)           does not fit (needs  46.3 GB, budget  11.2 GB)
    Ryzen AI Max+ 395 (128 GB)       fits; decode ceiling    6 tok/s
    Mac Studio M5 Max (128 GB)       fits; decode ceiling   13 tok/s

How to read it:

  • The 8B model misses the phones by half a gigabyte, and most of the miss is KV cache. Cut the context to 2,048 tokens or quantize the KV cache to 8 bits and it fits. On devices, context length is a memory decision.
  • The MoE model reads as little per token as the 3B model (2.7 GB) but needs 17 GB to hold. Where memory is plentiful and bandwidth is not (Ryzen AI Max, Macs), MoE models are the best fit; on a phone they do not fit at all, which is why Apple streams experts from flash instead.
  • The 70B model fits two desk machines and is slow on both. Holding a model and using it are different questions (8.d).
  • The 43.2 GB for 70B at Q4_K_M matches the 43.1 GB llama.cpp publishes for Llama 3.1 70B; the formula is sound. The ceilings are upper bounds: real engines reach roughly 60–85% of them, and phones less once they throttle.

7. Performance implications#

  • Decode on a device is a bandwidth problem, exactly as in the data centre, but batching cannot rescue it: there is one user. Bytes per token is the only lever.
  • Prefill is the hidden cost. Long system prompts, retrieved documents and chat history make time to first token the number users feel. Cache prompt prefixes across turns (12.m) and keep system prompts short.
  • The KV cache matters more than on servers relative to weights, because the models are small. A 3B model with a 32k context has a bigger cache than its weights.
  • Sustained speed is lower than peak. Expect a phone to lose a meaningful share of its speed under sustained load; measure it.
  • Cold start counts. Loading 2–5 GB of weights from flash takes time and evicts other apps’ memory. Memory-mapped formats (GGUF, .litertlm, MLX safetensors) and OS-resident models help.

8. Production implications#

  • Pick the model for the 25th-percentile device, not your own. Most users do not own this year’s flagship. Decide a minimum device tier and route everyone below it to the cloud (29.g).
  • Ship the model separately from the app. Store size limits and update costs push weights into a separate download (Play Asset Delivery on Android, background assets on Apple platforms), or use the OS model so you ship nothing.
  • Plan for model updates. A model inside 100 million phones is a fleet you cannot hot-patch. Version the weights, the tokenizer and the prompt template together (23.g).
  • Use the OS model where it is good enough. Apple Foundation Models and Gemini Nano cost you no download, no memory of your own and no maintenance; the trade-off is less control over the model.
  • Instrument devices. Log, with consent, device class, time to first token, tokens per second, memory warnings and thermal state. Without field data you will design for the wrong device.

9. Common mistakes#

  1. Planning against total RAM. The OS, other apps and the per-app limit leave far less.
  2. Forgetting the KV cache. On small models at long contexts it can exceed the weights.
  3. Benchmarking a cold, plugged-in flagship. Real users have warm, older, battery-powered phones.
  4. Quoting NPU TOPS as speed. TOPS measure compute; decode is limited by bandwidth (29.e).
  5. Ignoring prefill. A model that decodes at 30 tokens per second but takes 8 seconds to read the prompt feels slow.
  6. Shipping one model file for every device. A file tuned for one NPU often does not run, or runs slowly, on another.

10. Hands-on exercise#

  1. Run fit.go. Change ctx to 2,048 and to 32,768. At which context does the 8B model start to fit the phones, and at which does the 3B model stop fitting the Raspberry Pi?
  2. Add an 8-bit KV option (halve kvKiBTok). How much context does it buy on the phones?
  3. Add the DGX Spark (128 GB, 273 GB/s) and the Mac Studio M5 Ultra (512 GB, 1,200 GB/s). Add a gpt-oss-120b-like MoE: 117B total, 5.1B active, 4.25 bits per weight. Which machines run it, and how fast?
  4. On your own laptop, measure memory bandwidth with a STREAM-style tool, then run any 3B–8B model and compare its decode speed with the ceiling the program predicts.
  5. On a phone, run the same prompt ten times in a row and plot tokens per second against time. When does throttling start?

11. Interview questions#

  1. Why is the memory budget on a phone smaller than its RAM, and what do OS vendors do about it?
  2. Estimate the decode ceiling of a 4-bit 3B model on a phone with 80 GB/s of bandwidth, with and without an 8k FP16 KV cache.
  3. Why do mixture-of-experts models suit 128 GB laptops but not 12 GB phones?
  4. Where does time go in an on-device RAG query, and which part is compute-bound?
  5. A product manager wants “GPT-class quality fully offline on every phone”. What questions do you ask, and what do you propose?

12. Further reading#

Checked on 13 November 2026.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in