What if AI didn't need the cloud?
Right now, when you ask ChatGPT a question, your words travel from your phone β through the internet β to a data center in Iowa β hit an NVIDIA H100 GPU β the answer travels back. Round trip: 500ms to 3 seconds. And you need WiFi.But what if the model ran on your phone? No internet. No latency. No sending your private messages to a server. Your data never leaves your device.
That's edge deployment β running AI models on consumer hardware instead of cloud GPUs. And it's not a future concept. It's happening right now, on devices you already own.
Why Edge Matters
The cloud is powerful. But it has problems that edge deployment solves:
Problem Cloud Edge
| Privacy | Your data goes to someone else's computer | Data stays on your device |
|---|---|---|
| Latency | 500ms - 3s network round trip | 0ms network, instant |
| Cost | $0.01 - $0.10 per query, forever | Free after model download |
| Offline | No internet = no AI | Works in airplane mode |
| Bandwidth | Streaming tokens over network | Zero bandwidth needed |
For some use cases, edge isn't optional β it's the only option:
Medical devices that can't send patient data to external servers
Military/defense systems that operate without connectivity
Industrial IoT in factories with no reliable internet
Privacy-sensitive apps where users won't accept cloud processing
Developing regions with unreliable or expensive internet
Running Models on Phones
Modern smartphones are surprisingly capable AI devices.
Apple Silicon (iPhone/iPad)
Apple's Neural Engine is specifically designed for ML inference:
Device Neural Engine RAM What It Can Run
| iPhone 15 Pro | 35 TOPS (A17 Pro) | 8 GB | Llama 3.2 1B, Phi-3 Mini, Gemma 2B |
|---|---|---|---|
| iPhone 16 Pro | 38 TOPS (A18 Pro) | 8 GB | Llama 3.2 3B, Mistral 7B (Q4) |
| iPad Pro M4 | 38 TOPS (M4) | 16 GB | Llama 3.1 8B (Q4), Phi-3 Medium |
Apple's Core ML framework lets you convert and run models natively:
bash
Convert a Hugging Face model to Core ML format
pip install coremltools
python -c "
import coremltools as ct
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('microsoft/phi-3-mini-4k-instruct')Convert to Core ML with quantization
mlmodel = ct.convert(model, compute_precision=ct.precision.FLOAT16)mlmodel.save('phi3-mini.mlpackage')
"
Apple Intelligence runs a ~3B parameter model entirely on-device for writing tools, notification summaries, and Siri's understanding layer. No cloud required for those features.
Android (Qualcomm/MediaTek)Android's AI story is more fragmented but rapidly improving:
| Chip | AI Performance | RAM (typical) | What It Can Run |
|---|---|---|---|
| Snapdragon 8 Gen 3 | 73 TOPS | 12-16 GB | Llama 3.2 3B, Gemma 2B |
| Snapdragon 8 Elite | 100 TOPS | 12-24 GB | Llama 3.1 8B (Q4) |
| MediaTek Dimensity 9300 | 46 TOPS | 12-16 GB | Phi-3 Mini, Gemma 2B |
Google's MediaPipe LLM Inference API provides a unified way to run models on Android:
kotlin
// Android β MediaPipe LLM
val llmInference = LlmInference.createFromOptions(
context,
LlmInference.LlmInferenceOptions.builder()
.setModelPath("/path/to/gemma-2b-it-gpu-int4.bin")
.setMaxTokens(1024)
.build())
val response = llmInference.generateResponse("Explain quantum computing simply")
Real-World Performance on Phones
What does "running a model on a phone" actually feel like?
Model Device Tokens/sec Feel
| Gemma 2B Q4 | iPhone 15 Pro | 25-30 | Fast, usable |
|---|---|---|---|
| Phi-3 Mini Q4 | iPhone 16 Pro | 20-25 | Good, slight delay on first token |
| Llama 3.2 1B | Pixel 8 Pro | 30-40 | Snappy |
| Llama 3.2 3B Q4 | Samsung S24 Ultra | 15-20 | Acceptable |
| Mistral 7B Q4 | iPad Pro M4 | 12-18 | Slower but works |
For context: reading speed is ~4 tokens/second. Anything above 10 tok/s feels real-time.
π§
Raspberry Pi: The Cheapest AI Server
A Raspberry Pi 5 costs βΉ5,000 ($60). It has 8GB RAM and runs Linux. That's enough to run small language models.
Setup with llama.cpp
bash
On Raspberry Pi 5 (8GB)
sudo apt update && sudo apt install -y cmake build-essential
Clone and build llama.cpp
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
cmake -B build
cmake --build build --config Release -j4
Download a small quantized model
wget https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf
Run it
./build/bin/llama-cli -m tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf \
-p "You are a helpful assistant.\n\nUser: What is photosynthesis?\nAssistant:" \
-n 256 -t 4What Actually Runs on a Pi
Model Quantization RAM Usage Tokens/sec Verdict
| TinyLlama 1.1B | Q4_K_M | 1.2 GB | 8-12 | β Usable |
|---|---|---|---|---|
| Phi-2 2.7B | Q4_K_M | 2.5 GB | 3-5 | β οΈ Slow but works |
| Gemma 2B | Q4_K_M | 2.0 GB | 4-6 | β οΈ Okay for simple tasks |
| Llama 3.2 1B | Q4_K_M | 1.5 GB | 6-8 | β Best quality at this size |
| Mistral 7B | Q4_K_M | 5.5 GB | 1-2 | β Too slow for interactive |
Best use case for Pi: Always-on local AI for home automation, IoT classification, smart home assistants. Not for interactive chat with big models.
Pi Use Case: Local Smart Home AI
python
Home automation assistant on Raspberry Pi
from llama_cpp import Llama
llm = Llama(
model_path="./llama-3.2-1b.Q4_K_M.gguf",
n_ctx=2048,
n_threads=4)
def classify_command(text):
"""Classify voice commands for home automation"""
response = llm.create_chat_completion(
messages=[{
"role": "system",
"content": "Classify the user command into: lights, thermostat, music, alarm, other. Reply with ONLY the category."
}, {
"role": "user",
"content": text
}],
max_tokens=10,
temperature=0.1
)
return response['choices'][0]['message']['content'].strip()Fast classification β doesn't need a big model
print(classify_command("turn off the living room lights")) # β "lights"
print(classify_command("set temperature to 22")) # β "thermostat"π
WebLLM: AI in Your Browser
This is the wildest one. WebLLM runs full language models inside your web browser using WebGPU β no server, no installation, no downloads (well, one big download).
How WebGPU Makes This Possible
WebGPU is the successor to WebGL. It gives JavaScript direct access to your GPU β the same GPU that renders your web pages can now run neural networks.
Traditional: Browser β HTTP β Server β GPU β Response β Browser
WebLLM: Browser β WebGPU β Your GPU β Response (never leaves browser)
Running WebLLM
html
import { CreateMLCEngine } from "https://esm.run/@mlc-ai/web-llm";
// First load downloads the model (~1-4 GB) into browser cache
const engine = await CreateMLCEngine("Llama-3.1-8B-Instruct-q4f16_1-MLC", {
initProgressCallback: (progress) => {
console.log(`Loading: ${(progress.progress * 100).toFixed(1)}%`);
}});
// Now it runs entirely in your browser
const response = await engine.chat.completions.create({
messages: [
{ role: "user", content: "Explain edge computing in 3 sentences" }
],
temperature: 0.7,});
console.log(response.choices[0].message.content);
WebLLM Performance
Model Browser GPU Download Size Tokens/sec
| Llama 3.1 8B Q4 | Chrome | RTX 4090 | 4.3 GB | 80-100 |
|---|---|---|---|---|
| Llama 3.1 8B Q4 | Chrome | M2 MacBook | 4.3 GB | 40-60 |
| Phi-3 Mini Q4 | Chrome | RTX 3060 | 2.1 GB | 50-70 |
| Gemma 2B Q4 | Chrome | Integrated GPU | 1.4 GB | 10-20 |
The catch: First load downloads the full model (1-4 GB). After that, it's cached in the browser. WebGPU requires Chrome 113+ or Edge 113+. Safari support is still experimental.
When to Use WebLLM
Good for:
Privacy-first applications (nothing leaves the browser)
Demos and prototypes (no backend needed)
Offline-capable web apps
Client-side text processing (summarization, classification)
β Not good for:
Users with weak GPUs or old browsers
Models larger than 8B (VRAM limits)
Mobile browsers (WebGPU support is spotty)
Production apps needing consistent performance across all users
ONNX Runtime: The Universal Edge Format
ONNX (Open Neural Network Exchange) is a model format designed for portability. Convert once, run anywhere.PyTorch Model β ONNX Export β Run on:
βββ Windows (DirectML)
βββ macOS (Core ML)
βββ Linux (CUDA / CPU)
βββ Android (NNAPI)
βββ iOS (Core ML)
βββ Browser (WASM)
βββ Raspberry Pi (ARM CPU)Converting and Running
python
Step 1: Export PyTorch model to ONNX
import torch
from transformers import AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
dummy_input = torch.randint(0, 1000, (1, 128))torch.onnx.export(
model,
(dummy_input,),
"distilbert.onnx",
input_names=["input_ids"],
output_names=["logits"],
dynamic_axes={"input_ids": {0: "batch", 1: "seq_len"}})
Step 2: Run with ONNX Runtime (any platform)
import onnxruntime as ort
session = ort.InferenceSession("distilbert.onnx")
result = session.run(None, {"input_ids": input_ids.numpy()})ONNX Runtime vs Other Options
Feature ONNX Runtime llama.cpp Core ML TensorRT
Platforms Everything CPU/Metal/CUDA Apple only NVIDIA only
| Model types | Any ONNX model | LLMs (GGUF) | Any Core ML | Any TensorRT |
|---|---|---|---|---|
| Best for | Cross-platform | LLM chat | iOS/macOS apps | Max GPU perf |
| Quantization | INT8, INT4 | Q2-Q8 variants | FP16, INT8 | FP16, INT8, INT4 |
| Setup complexity | Low | Low | Medium | High |
The Edge Deployment Decision Tree
Do you need >13B parameter models?
βββ Yes β Cloud (edge can't handle it well yet)
βββ No
β
Is privacy critical (data can't leave device)?
βββ Yes β Edge (mandatory)
βββ No
β
Do you need offline capability?
βββ Yes β Edge (mandatory)
βββ No
β
Is latency critical (<100ms)?
βββ Yes β Edge (no network round trip)
βββ No
β
Budget-sensitive?
βββ Yes β Edge (no per-query cost)
βββ No β Cloud (better models, easier)π¬
Practical Takeaways
Edge AI is real today β phones run 1-3B models comfortably, 7-8B with quantization
Apple is ahead β Neural Engine + unified memory makes iPhones surprisingly good at inference
WebLLM is magic for demos β full LLM in a browser tab, zero server cost
Raspberry Pi works for classification and simple tasks β don't expect interactive chat with 7B+ models
ONNX Runtime is your portability layer β convert once, deploy everywhere
The decision is usually hybrid β edge for simple/private tasks, cloud for complex reasoning
π‘οΈ
What's Next?
Episode 42: Model Gateways β When you're calling multiple LLM providers (OpenAI, Anthropic, Google, local models), how do you manage them all through one API? That's what gateways like LiteLLM and OpenRouter solve β and they're becoming essential infrastructure.
β Previous
Ep 40: Load Balancing Multiple Models
Next β
Ep 42: Model Gateways
Next: Episode 42 β Model Gateways
OpenAI for GPT-4. Claude for coding. Gemini for long context. Self-hosted Llama for cost. Managing all of them is a nightmare.
This is part of a 98-episode series covering AI engineering from tokens to production deployment.