Skip to content

Edge AI and on-Device Inference

Under the Hood 6 min read

In Short

Edge AI runs machine learning models directly on phones, IoT sensors, and browsers instead of sending data to a remote server. The primary drivers are latency, privacy, and offline availability. Making models small enough to run on constrained hardware requires quantization, pruning, distillation, and purpose-built runtimes.

01. What It Is

Edge AI is the practice of running trained ML models on the device where data is generated, rather than transmitting that data to a cloud server for processing. "The edge" refers to any compute resource outside a centralized data center: a smartphone, a microcontroller, a browser tab, an IoT sensor, an in-car computer, or a hospital workstation operating in an air-gapped network.

The distinction is architectural. In cloud inference, the user's device sends raw data (an audio clip, a photo, a sensor reading) over a network connection, a large model runs in the cloud and returns a result. In on-device inference, a model resident on the device processes the data locally and the result is produced without a network round-trip.

02. Why It Matters

Latency:
Network round-trips add tens to hundreds of milliseconds. Applications that require immediate responses (keyboard autocomplete, real-time translation, face unlock, object detection in a moving vehicle) benefit from inference times measured in single-digit milliseconds on the local neural engine.

Privacy:
On-device inference means raw sensor data, photos, voice recordings, and health metrics never leave the device. Apple's on-device Face ID processing and Google's on-device speech recognition for Gboard are the canonical examples. The data required to answer the query never transits a network.

Cost:
Cloud inference at scale is expensive. A consumer app with millions of daily active users that runs inference 50 times per session generates enormous API costs. Shifting inference to the user's device offloads this cost entirely.

Offline availability:
Devices in low-connectivity environments (aircraft, rural areas, industrial facilities, submarines) cannot rely on cloud access. On-device models work without any connectivity.

Regulatory compliance:
Some industries (healthcare, defense, finance) prohibit or restrict sending certain data types to third-party cloud providers. On-device inference can satisfy data residency requirements that cloud inference cannot.

03. How It Works

A model trained in a research or cloud environment (PyTorch, TensorFlow, JAX) must be converted, compressed, and packaged for the target runtime. The general pipeline:

  1. Train a model at full precision (typically 32-bit floats) on a cloud cluster.
  2. Apply compression techniques (quantization, pruning, distillation) to reduce size and computation.
  3. Convert to a runtime-specific format (Core ML, TFLite/LiteRT, ONNX, GGUF).
  4. Deploy to the device. The runtime dispatches work to CPU, GPU, or a dedicated neural processing unit (NPU).

Quantization

Post-training quantization reduces the precision of weights and activations from 32-bit floats to 8-bit integers (INT8) or 4-bit integers (INT4), cutting memory footprint by 4-8x and accelerating arithmetic on hardware that has optimized integer units. Dettmers et al. (2022, arXiv:2208.07339) demonstrated that LLMs up to 175 billion parameters can be served in INT8 with negligible accuracy loss using mixed-precision decomposition (LLM.int8()).
For full treatment see Quantization.

Knowledge Distillation

A smaller "student" model is trained to reproduce the output distribution of a larger "teacher" model. The student inherits much of the teacher's knowledge at a fraction of the parameter count.
See Knowledge Distillation for full detail.

Pruning

Weights close to zero are removed (set to zero and stored in sparse format, or the corresponding neurons/heads are deleted entirely). Structured pruning removes entire channels or attention heads, producing a dense smaller model that runs efficiently on standard hardware. Unstructured pruning produces sparse weight matrices that require special hardware or software support to accelerate.

Small Language Models

Recent research has demonstrated that a small model trained on extremely high-quality or synthetic data can match a much larger model trained on raw web data. Microsoft's phi series showed that a model under 4 billion parameters trained on curated "textbook-quality" synthetic data outperformed models 5-10x its size on many benchmarks. Mistral 7B (Jiang et al., 2023, arXiv:2310.06825) outperformed Llama 2 13B on most benchmarks at half the parameter count, using grouped-query attention and sliding window attention for efficient inference.

04. Key Terms / Methods

  • NPU (Neural Processing Unit). A chip designed specifically for the matrix multiplications and activation functions that dominate neural network inference. Apple's Neural Engine, Qualcomm's Hexagon DSP, and Google's Tensor chip are common examples.
  • Core ML. Apple's on-device ML framework. Models from PyTorch or TensorFlow are converted using the coremltools Python package. Core ML dispatches work automatically to the CPU, GPU, or Neural Engine based on layer type and device capability. Models can hold multiple functions and stateful representations for efficient large-language-model execution.
  • LiteRT (formerly TensorFlow Lite). Google's runtime for on-device ML across Android, iOS, Linux, and microcontrollers. LiteRT is the next-generation successor to TFLite, offering hardware-specific optimizations for CPU, GPU, and NPU backends. It supports deployment of generative models such as Gemma for on-device chat.
  • ONNX Runtime. Microsoft's cross-platform inference accelerator. Models are exported to the Open Neural Network Exchange (ONNX) format from PyTorch, TensorFlow, or scikit-learn and then run via ONNX Runtime on CPU, CUDA GPU, DirectML, or any of its execution provider plugins. It powers inference across Office, Azure, and Bing products.
  • llama.cpp. An open-source C++ inference engine for running LLaMA-family models (and many compatible architectures) using highly optimized CPU kernels. Supports 2-bit through 8-bit GGUF quantized models. Allows running a 7B parameter model on a MacBook with no GPU. Widely used as the inference backend for local LLM tools.
  • WebGPU. The browser API for GPU-accelerated compute. WebGPU enables running quantized transformer models directly in a browser tab without installing software, using the host machine's GPU. Libraries such as WebLLM use WebGPU to run Llama 3 and Mistral in-browser.
  • GGUF (GPT-Generated Unified Format). The file format used by llama.cpp and compatible tools. Combines model weights, tokenizer, and metadata in a single file with support for mixed quantization per layer.

05. Examples

  • Apple Face ID. Biometric matching runs entirely in the Secure Enclave and Neural Engine. Raw face geometry data never leaves the device.
  • Gboard next-word prediction. Google trains keyboard language models using on-device federated learning and serves predictions locally using a quantized model.
  • Whisper on device. OpenAI's Whisper speech recognition model has been quantized and packaged for llama.cpp and Core ML, enabling real-time transcription on a MacBook with no internet connection.
  • Gemma on LiteRT. Google's Gemma 2B and 3B models are distributed as LiteRT-compatible packages for on-device Android chat applications.
  • WebLLM. Runs Llama 3, Mistral, and Phi models in a browser using WebGPU, with INT4 quantization fitting a 7B model in under 4 GB of VRAM.

06. Common Pitfalls / Misconceptions

Quantization always degrades accuracy:
For most practical tasks, well-executed INT8 or even INT4 quantization produces accuracy within a fraction of a percent of FP32 baseline. The degradation becomes significant only for tasks that depend on very small activation differences or for models that have not been calibrated for quantization.

On-device means slow:
Modern NPUs (Apple Neural Engine, Qualcomm Hexagon) perform trillions of operations per second specifically for neural network workloads. A 7B parameter model running in 4-bit quantization on an M3 MacBook generates tokens at 60-80 tokens per second, faster than a human reads.

The cloud is always more accurate:
A smaller on-device model is not automatically less accurate than a cloud model. A well-distilled or well-trained small model on a narrow task often matches or exceeds a general-purpose large cloud model. The choice is task-dependent.

Edge and cloud are mutually exclusive:
Hybrid architectures are common. A device handles simple queries with a small on-device model and routes complex queries to a cloud model, balancing cost, latency, and capability.

Pruning is free:
Unstructured sparsity rarely accelerates inference on standard hardware without specialized sparse kernels. Structured pruning produces real speedups but permanently removes capacity that cannot be recovered later.

Verified against primary sources

Every claim traces to a cited source below.

Key terms

Edge AI
Running ML models on the device where data is generated, not in the cloud.
On-device inference
A local model processes data with no network round-trip.
The edge
Any compute outside a central data center: a phone, sensor, or browser tab.

Tags

#edge-ai #on-device #inference #privacy #latency

More in Smaller & Faster