Edge and On-Device Deployment
An on-device model is not a small server placed inside a phone. It is one component of an application that must work across different processors, operating-system versions, memory conditions, battery states, and network conditions. The relevant unit is therefore a versioned device deployment: the model, tokenizer, prompt template, compiled graph, quantization scheme, runtime, routing policy, and supported device class that produced a result.
Local execution is useful when a feature needs an offline path, a short and predictable response loop, or a narrower data boundary. It is justified only when the complete feature also meets its quality, memory, energy, thermal, and support requirements. The model decision from Chapter 81 and the serving contract from Chapter 82 still apply; the difference is that qualification happens on a heterogeneous fleet rather than a controlled server pool.
Freeze the device support envelope
Start with the feature, not a parameter count or a runtime. A device support envelope states where the feature is supported and what “supported” means. It turns “run this model locally” into a claim that can be tested and withdrawn.
| Concern | What the envelope fixes |
|---|---|
| Task and quality | Task class, input and output limits, languages, safety policy, quality threshold, and rejection behavior |
| Data boundary | Data classes allowed locally, data classes eligible for upload, retention, and whether cloud use requires explicit consent |
| Device population | Representative device tier, processor or accelerator requirements, minimum OS and runtime versions, and available storage |
| User experience | Cold-start and warm-start latency, time to first token, time per output token, cancellation, partial output, and accessibility behavior |
| Resource limits | Peak resident memory, sustained energy, thermal state, background-load assumptions, and concurrency |
| Availability | Model installation state, offline behavior, fallback policy, and behavior when neither route is available |
| Lifecycle | Artifact owner, rollout cohort, telemetry boundary, rollback target, retirement date, and requalification triggers |
The support envelope is narrower than “all recent phones.” A useful device tier names the properties that affect execution: OS build, runtime version, system-on-chip family, memory class, storage headroom, and available backend. Marketing names alone are insufficient because devices sold under one family can have different memory or thermal behavior.
Represent the envelope as an acceptance matrix. Rows are supported device tiers; columns are relevant states such as cold and warm process, model absent and installed, normal and low storage, normal and low battery, foreground and background load, offline and weak network, and cool and thermally constrained. Each cell records pass, fail, or unsupported against the same feature contract. This makes gaps visible before a rollout turns them into user reports.
Count what must fit
Raw parameter size is only the first term in the memory budget. For a decoder model, a useful planning approximation is
Here is the stored weight footprint; is the number of parameters; is the average stored bits per parameter; the constant converts bits to bytes; and covers quantization scales, zero points, block headers, tensor alignment, and other format data. The inequality is deliberate: the packed-tensor calculation is a lower bound, not an installed-size or resident memory guarantee.
is the uncompressed planning size of the key-value cache; the factor accounts for keys and values; is the number of concurrent sequences; is the number of transformer layers; is the number of key-value heads per layer; is the head dimension; is the number of cached tokens per sequence; and is the stored bits per cache element. Runtime-specific padding, cache layout, sliding windows, or cross-layer sharing can change the measured value.
covers activations, temporary buffers, compiled kernels, and backend workspaces. is the inference runtime and its loaded libraries. is everything else the application needs while inference runs. Their sum is peak resident memory , which must remain below the memory available to the feature, . The budget is not the device's advertised RAM: the OS, other processes, graphics, media, and the application already consume it.
A 3-billion-parameter model at four bits has a raw packed-weight payload of 1.5 GB. That arithmetic is useful for rejecting an impossible candidate, but it does not prove the candidate fits. Quantization metadata, tensor alignment, context-dependent cache growth, runtime allocations, and memory pressure can move the actual peak materially. Measure the exported artifact in the real process, including its longest supported context and its worst supported input.
KIVI illustrates why the cache deserves its own line item: its authors found different distributions in keys and values and evaluated per-channel key and per-token value quantization rather than treating the cache as ordinary model weights (Liu et al. 2024). The result belongs to the evaluated models and runtime; it is evidence for testing cache quantization, not permission to assume that a two-bit cache is lossless everywhere.
# Illustrative planning values; replace them with the candidate artifact.
params = 3_000_000_000
weight_bits = 4
batch = 1
layers = 28
kv_heads = 8
head_dim = 128
cached_tokens = 4096
kv_bits = 8
other_gb = 1.1 # runtime, app, workspaces, and measured format overhead
weights_gb = params * weight_bits / 8 / 1e9
kv_gb = 2 * batch * layers * kv_heads * head_dim * cached_tokens * kv_bits / 8 / 1e9
peak_gb = weights_gb + kv_gb + other_gb
print(f"packed weights: {weights_gb:.2f} GB")
print(f"planned KV cache: {kv_gb:.2f} GB")
print(f"planning total: {peak_gb:.2f} GB; verify peak RSS on every device tier")
Measure the path and the device state
The local and remote paths have different latency components. For an installed local artifact,
where is model load and specialization time; processes the input; is the number of output tokens; is the time for output token ; and covers validation, rendering, and any feature-specific post-processing. A remote path instead includes upload, network, provider queue, remote execution, and download time. Neither path is inherently faster. A cold local load can lose to a warm remote service, while a warm local model can avoid variable network delay.
For batch-one autoregressive decode, a bandwidth estimate can expose an upper bound:
Here is generated tokens per second; is effective memory bandwidth in bytes per second under the measured device state; and is bytes moved from memory per generated token. This is a bandwidth ceiling, not a prediction. Prefill can be compute-bound, some weights or cache blocks may be reused, and unpacking, dequantization, unsupported operators, synchronization, or small kernels can become the bottleneck. Roofline analysis is a way to form a hypothesis about a specific workload. It is a measurement, not a promise that lower precision must increase speed (Yuan et al. 2024).
Measure at least cold start, warm start, time to first token, time per output token, end-to-end latency, peak resident memory, error rate, and quality on the same task set. Report p50 and p95 rather than one best run. Also measure energy per accepted task, not energy per token alone. A useful device-side estimate is
where is incremental task energy; and bound the complete feature interaction; is measured device power at time ; and is the comparable idle baseline. If the platform exposes only energy proxies, label them as proxies and keep the measurement method stable across candidates.
Short bursts hide the device's central failure mode. Run a sustained run until latency, power, and temperature reach thermal steady state or the test limit. Record battery state, charging state, ambient condition, power mode, screen state, background load, and frequency throttling. Both Android and Apple expose thermal-state signals that applications can observe; those signals should be part of a controlled test and, where appropriate, a runtime admission decision (Android Developers n.d.; Apple n.d.). MLPerf Mobile likewise treats the model, software stack, device, accuracy target, and run rules as one benchmarked system (Reddi et al. 2022).
Compression is a system choice
Compression is valuable only when the resulting artifact retains task quality and the target backend executes its representation efficiently. Keep the weight format, activation format, and KV-cache format separate in the decision record. They affect different memory regions and require different kernel support. Chapter 34 develops the underlying representations and kernels; the concern here is qualifying their exported device artifact.
| Mechanism | What changes | What it can buy | What must be checked |
|---|---|---|---|
| Small-by-design architecture | Depth, width, attention layout, embeddings, or weight sharing | A better quality/latency point within a small parameter budget | Task transfer, supported operators, cache size, and measured latency |
| Distillation | A student learns from teacher outputs or distributions | More capability in a smaller student for the trained task distribution | Teacher errors, coverage gaps, safety behavior, and independent evaluation |
| Structured pruning | Heads, channels, layers, or blocks are removed | A smaller graph that may map to existing kernels | Retraining cost, quality loss, and whether the backend accelerates the new shape |
| Post-training quantization | A trained checkpoint is calibrated and encoded at lower precision | Lower storage and often lower weight traffic without full retraining | Calibration set coverage, task-specific evaluation, kernel availability, and dequantization cost |
| Quantization-aware training | Quantization effects are simulated during training or adaptation | Better recovery at aggressive precision | Training cost, exact deployment format, and export parity |
| Low-bit pretraining | The model is trained for a low-bit or discrete representation from the start | A representation designed around the target arithmetic | Lack of a simple conversion path, immature kernels, and evidence at the intended scale |
| KV-cache quantization | Attention keys and values use fewer bits | Longer context or lower peak memory | Cache layout, accuracy across context lengths, and attention-kernel support |
MobileLLM is useful evidence for designing within a small budget: its authors studied deep-and-thin sub-billion models, embedding sharing, grouped-query attention, and adjacent-block sharing rather than merely compressing a much larger checkpoint (Liu et al. 2024). That result motivates architecture search in the intended regime; it does not establish one universal mobile shape.
For post-training quantization, the calibration set is part of the artifact. It should cover real prompt lengths, languages, modalities, tool schemas, and rare but important request classes. AWQ uses observed activations to protect salient weight channels in a weight-only method (Lin et al. 2024). SmoothQuant moves some quantization difficulty from activations into weights to support W8A8 execution (Xiao et al. 2023). These methods solve different problems, so a paper's aggregate benchmark does not substitute for task-specific evaluation on the exact artifact and exact backend.
Quantization-aware training and low-bit pretraining become relevant when post-training quality is insufficient. One published Apple model used two-bit quantization-aware training and KV-cache sharing for an approximately 3-billion-parameter on-device model (Li et al. 2025). BitNet b1.58 reports ternary weights in for models trained in that representation (Ma et al. 2024). In the mathematical dot product, a ternary weight replaces a general weight multiplication with selection, sign change, or zero. A deployed system still has scales, activation processing, attention, normalization, packing, and memory traffic. Zero-valued weights are not automatically structured sparsity, and a backend saves work only if its kernel exploits the representation. Smaller does not automatically mean faster.
Build a deployable artifact
A source checkpoint is not a mobile artifact. Export and lowering specialize a graph to an operator set, memory plan, tensor layout, precision, and backend. ExecuTorch, for example, separates export and ahead-of-time lowering from its device runtime and produces programs for selected backends (PyTorch Foundation n.d.). Core ML can schedule supported work across CPU, GPU, and Neural Engine, but the actual compute plan and compatibility still depend on the converted model and target OS (Apple n.d.). A container such as GGUF can carry tensors and model metadata, yet a runtime build must still implement the architecture, tokenizer semantics, quantization types, and required operators (ggml-org n.d.). Format is not compatibility.
Record a deployment fingerprint with at least:
- source checkpoint and immutable revision;
- tokenizer, special tokens, and prompt template;
- adapter set and merge state;
- export graph and exporter version;
- quantization configuration and calibration-set revision;
- compiled artifact format and cryptographic digest;
- runtime version and linked operator set;
- backend delegate, fallback partitions, and compute policy;
- supported OS build, ABI, and device class; and
- routing, safety, context, and sampling policies.
The fingerprint prevents a common diagnostic failure: comparing “the same model” when one build changed its template, exporter, quantization, or backend. It also supplies the key for every quality result and device metric.
Before performance testing, establish semantic parity. Run golden prompts through the source graph and compiled artifact; compare tokenization, structured output, stop handling, and task results within declared tolerances. Inspect the partition plan for unsupported operators. A silent CPU fallback may preserve correctness while destroying latency or energy, so the capability probe must report the actual backend delegate and every CPU fallback.
Make hybrid routing explicit
Hybrid execution is a policy decision, not a catch-all exception handler. Define the route before execution as
where is the request and its task class; is its data classification; is current device state, including model availability, memory, thermal, battery, and connectivity; is the versioned product policy; and is the selected route. “Decline” includes asking the user to download the model, wait, change a setting, or perform the task elsewhere.
For a local-only request, model unavailable, low storage, or thermal pressure must lead to a local error or decline path; never upload it. For a cloud-eligible request, require the declared legal and product basis and any explicit consent before transmission. If permission is absent, there is no silent fallback. If both routes are allowed, choose using measured quality and the remaining deadline, not a vague estimate that the request is “hard.”
Route before execution whenever possible. Falling back after partial output can duplicate text, change semantics, or expose data the user expected to remain local. If a local run fails after producing a partial output, terminate it with a typed reason and let the product contract decide whether the user may start a new cloud attempt. Never append a cloud continuation invisibly. Return execution provenance (local, cloud, or declined) so the UI, telemetry, and support tools can explain what happened.
Local execution is not automatically private
Keeping inference in the app can reduce transmission and server retention, but it is not, by itself, a privacy guarantee. Input or output may still reach temporary files, clipboard history, backups, keyboard services, shared caches, analytics SDKs, crash reports, telemetry, tools, or a cloud fallback. The model and its personalization data can also reveal sensitive behavior if stored without the app sandbox and platform protections.
Draw a data-flow map for the complete feature. For each surface, record purpose, data class, retention, protection, recipient, deletion path, and whether the surface works offline. Apply the same security review used for other mobile data: app sandbox boundaries, secure storage, authenticated network transport, least privilege, log redaction, and dependency review. The OWASP Mobile Application Security Verification Standard separates storage, network, platform, code, resilience, and privacy controls precisely because “processed locally” addresses only part of the system (OWASP Foundation n.d.). See Chapter 56 for the broader trust and authorization model.
Default fleet telemetry to content-free metrics: deployment fingerprint, route and reason, device tier, timing buckets, peak-memory bucket, thermal state, load error, cancellation, and quality outcome when it can be collected without content. Do not collect prompt or completion content by default. If a debugging program needs examples, make it separately authorized, narrowly sampled, redacted, access-controlled, time-bounded, and removable. OpenTelemetry's generative-AI conventions warn that model inputs and outputs are likely to contain sensitive information (OpenTelemetry n.d.).
Deliver model versions safely
Large artifacts are often downloaded separately from the application. That creates a software-update problem: incomplete downloads, corrupt storage, rollback attacks, incompatible runtimes, low disk, and mixed versions of model, tokenizer, and adapter. Treat the bundle as immutable and activate it only as a complete set.
Each release needs a signed compatibility manifest containing artifact names, sizes, cryptographic digest values, signature information, deployment fingerprint, supported app and runtime versions, target device classes, and expiry or retirement policy. The Update Framework formalizes signed metadata, hash and size verification, version progression, and defenses against rollback, freeze, and mix-and-match attacks; it is a useful model even when a platform's asset service performs the transport (The Update Framework n.d.).
Download beside the active bundle. Before activation, check free space and disk quota, verify size, cryptographic digest, signature, compatibility manifest, and license notices, then run a minimal load and golden-output smoke test. Use atomic activation so a process sees either the old complete bundle or the new complete bundle. Retain a last-known-good version until the rollout is healthy. Garbage collection must not delete the active or rollback target, and it must cope with an interrupted download.
Use a staged rollout by representative device tier, not only by account percentage. Stop or rollback when load failures, crashes, quality rejection, p95 latency, peak memory, energy, or thermal events cross their declared thresholds. A server-side kill switch can disable eligibility, but offline behavior must remain defined: an installed unsafe version may require local disablement encoded in the app or an expiry policy rather than a network response that never arrives.
Operate the fleet
The operating loop is short enough to make explicit:
- Freeze the envelope. Record the task class, data boundary, quality threshold, supported device tiers, minimum OS, offline behavior, and fallback policy.
- Build the fingerprint. Version the source checkpoint, tokenizer, prompt template, export graph, quantization configuration, compiled artifact, runtime, backend, and policy as one candidate.
- Qualify the complete artifact. Check source-to-device parity, task quality, operator coverage, CPU fallback, storage, peak resident memory, and every acceptance-matrix cell.
- Benchmark sustained behavior. Measure cold and warm latency, p50 and p95, energy per accepted task, memory pressure, and thermal steady state on representative device tiers.
- Inject device failures. Exercise model unavailable, offline start, weak network, low storage, corrupt download, backend rejection, cancellation, background load, and thermal throttling.
- Stage delivery. Verify the inactive bundle, activate atomically for a small device-tier cohort, and compare against the last-known-good release.
- Observe and rollback. Monitor content-free route, quality, reliability, latency, energy, and thermal signals; rollback on the recorded thresholds.
- Register each requalification trigger. Repeat the affected matrix when the model, tokenizer, template, quantization, exporter, runtime, backend, operating system, device policy, or feature contract changes.
NIST's generative-AI profile treats deployment-context evaluation, post-deployment monitoring, incident response, change management, and decommissioning as lifecycle work rather than one-time release checks (Autio et al. 2024). The same framing applies here. Chapter 87 provides the quality and observability method, while Chapter 89 develops staged release and rollback in more detail.
The output is a deployment decision record: the envelope, exact fingerprint, acceptance matrix, measured results, privacy data flow, routing policy, delivery plan, rollback thresholds, owner, and requalification triggers. It supports a local release, a hybrid release, or a documented decision not to ship on-device.
Three boundaries remain empirical. First, local versus cloud is a feature-level choice: device capability can improve while remote models and networks improve too. Second, accelerator portability remains limited by operator coverage, compiler behavior, and vendor runtimes; a common source model does not imply one common executable. Third, very-low-bit training can change the quality-memory frontier, but published model-level gains do not guarantee system-level latency or energy gains on a target device. Keep these as measured alternatives in the acceptance matrix rather than forecasts in the architecture.
The device budget reaches backward through the entire stack. Memory and thermal limits influence model architecture and context length. Kernel availability influences quantization. Export and operator coverage influence training-time choices. Privacy and offline policy influence routing and telemetry. The device therefore constrains not only where inference runs, but which model can be trained, represented, delivered, observed, and safely updated.
Further reading
- Liu et al., “MobileLLM: Optimizing Sub-billion Parameter Language Models for On-Device Use Cases” (Deep-and-thin sub-billion models, embedding sharing, grouped-query attention, and adjacent-block sharing), 2024. proceedings.mlr.pressMobileLLM studies architecture within a sub-billion-parameter device budget and reports gains from deep-and-thin models plus memory-conscious sharing mechanisms.
- Lin et al., “AWQ: Activation-aware Weight Quantization for On-Device LLM Compression and Acceleration” (Activation-aware low-bit weight-only post-training quantization), 2024. proceedings.mlsys.orgAWQ uses activation observations to identify and protect salient weight channels while quantizing model weights for edge-oriented inference.
- Xiao et al., “SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models” (Post-training W8A8 quantization by migrating activation difficulty into weights), 2023. proceedings.mlr.pressSmoothQuant applies an equivalent per-channel transformation that makes activation quantization easier while moving difficulty into weights.
- Liu et al., “KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache” (Per-channel key-cache and per-token value-cache quantization), 2024. proceedings.mlr.pressKIVI studies KV-cache distributions and applies different two-bit granularities to keys and values in the evaluated Llama, Falcon, and Mistral deployments.
- Ma et al., “The Era of 1-bit LLMs: All Large Language Models are in 1.58 Bits” (Ternary-weight language models trained in a low-bit representation), 2024. arXiv:2402.17764BitNet b1.58 studies language models trained with ternary weights and reports model-level quality, memory, latency, and arithmetic-energy comparisons under its evaluated setup.
- Li et al., “Apple Intelligence Foundation Language Models: Tech Report 2025” (A reported 3B on-device model using KV-cache sharing and 2-bit quantization-aware training), 2025. arXiv:2507.13575The report describes Apple's approximately 3B-parameter on-device model and its architecture, quantization-aware training, evaluation, and deployment-specific adaptations.
- Yuan et al., “LLM Inference Unveiled: Survey and Roofline Model Insights” (Roofline analysis of compute and memory limits in language-model inference), 2024. arXiv:2402.16363The survey uses roofline analysis to distinguish compute and memory bottlenecks across inference phases, models, and hardware rather than assuming one universal limit.
- Reddi et al., “MLPerf Mobile Inference Benchmark: An Industry-Standard Open-Source Machine Learning Benchmark for On-Device AI” (Device, software-stack, performance, and quality measurement for mobile inference), 2022. proceedings.mlsys.orgMLPerf Mobile defines common tasks, quality targets, run rules, and device-side measurement to make results across heterogeneous mobile stacks interpretable.
- Android Developers, “Thermal API” (Device thermal status and thermal-headroom APIs), n.d.. developer.android.comAndroid's Thermal API exposes thermal status and headroom signals that applications can use to observe and adapt sustained workloads.
- Apple, “Process Information: Responding to Thermal State Changes” (Runtime thermal-state reporting on Apple platforms), n.d.. developer.apple.comApple's process-information APIs expose thermal-state changes so applications can reduce expensive work before thermal pressure becomes critical.
- PyTorch Foundation, “ExecuTorch: Architecture and Components” (Ahead-of-time export, lowering, runtime preparation, and device execution), n.d.. docs.pytorch.orgExecuTorch documents separate program-preparation, runtime-preparation, and execution phases, with target-specific lowering and linked backend support.
- Apple, “Core ML” (Model conversion and execution across Apple device compute units), n.d.. developer.apple.comCore ML provides a device model representation and can use CPU, GPU, and Neural Engine resources according to model and platform support.
- ggml-org, “GGUF File Format Specification” (Tensor and metadata container used by compatible GGML-family runtimes), n.d.. github.comGGUF defines an extensible binary container for tensors and metadata; runtime support for the encoded architecture and tensor types remains a separate requirement.
- OWASP Foundation, “Mobile Application Security Verification Standard” (Mobile controls for storage, cryptography, authentication, network, platform, code, resilience, and privacy), n.d.. mas.owasp.orgMASVS organizes mobile security and privacy requirements across the complete application rather than treating local computation as sufficient protection.
- OpenTelemetry, “OpenTelemetry Generative AI Semantic Conventions” (Telemetry attributes and warnings for sensitive model content), n.d.. opentelemetry.ioThe OpenTelemetry registry defines generative-AI telemetry attributes and warns that model inputs and outputs are likely to contain sensitive or personally identifiable information.
- The Update Framework, “The Update Framework Specification” (Signed metadata, hash and size verification, expiry, and rollback protection), n.d.. theupdateframework.github.ioTUF defines signed versioned metadata and client verification rules designed to resist rollback, freeze, mix-and-match, and repository-compromise attacks.
- Autio et al., “Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile” (Generative-AI evaluation, monitoring, incident response, change management, and decommissioning), 2024. nist.govNIST AI 600-1 frames generative-AI risks and controls across design, deployment-context evaluation, ongoing monitoring, incident response, change, and retirement.
Comments
Log in to comment