MODULE 6  Β·  Model Serving & APIs

Edge Deployment: Running AI on Your Phone, Raspberry Pi, and Browser

Your words travel to Iowa, hit an H100 GPU, and come back. 500ms to 3 seconds. What if the AI ran on your device instead?

πŸ“… Mar 2026
⏱ 10 min read
🎯 Episode 41 of 98
Edge AIMobile AIOn-DeviceDeployment
In this episode

What if AI didn't need the cloud?

snippet
code
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

PrivacyYour data goes to someone else's computerData stays on your device
Latency500ms - 3s network round trip0ms network, instant
Cost$0.01 - $0.10 per query, foreverFree after model download
OfflineNo internet = no AIWorks in airplane mode
BandwidthStreaming tokens over networkZero 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 Pro35 TOPS (A17 Pro)8 GBLlama 3.2 1B, Phi-3 Mini, Gemma 2B
iPhone 16 Pro38 TOPS (A18 Pro)8 GBLlama 3.2 3B, Mistral 7B (Q4)
iPad Pro M438 TOPS (M4)16 GBLlama 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

snippet
code
model = AutoModelForCausalLM.from_pretrained('microsoft/phi-3-mini-4k-instruct')

Convert to Core ML with quantization

snippet
code
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.

snippet
code
Android (Qualcomm/MediaTek)

Android's AI story is more fragmented but rapidly improving:

ChipAI PerformanceRAM (typical)What It Can Run
Snapdragon 8 Gen 373 TOPS12-16 GBLlama 3.2 3B, Gemma 2B
Snapdragon 8 Elite100 TOPS12-24 GBLlama 3.1 8B (Q4)
MediaTek Dimensity 930046 TOPS12-16 GBPhi-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(

example
code
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 Q4iPhone 15 Pro25-30Fast, usable
Phi-3 Mini Q4iPhone 16 Pro20-25Good, slight delay on first token
Llama 3.2 1BPixel 8 Pro30-40Snappy
Llama 3.2 3B Q4Samsung S24 Ultra15-20Acceptable
Mistral 7B Q4iPad Pro M412-18Slower 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 \

example
code
-p "You are a helpful assistant.\n\nUser: What is photosynthesis?\nAssistant:" \
    -n 256 -t 4

What Actually Runs on a Pi

Model Quantization RAM Usage Tokens/sec Verdict

TinyLlama 1.1BQ4_K_M1.2 GB8-12βœ… Usable
Phi-2 2.7BQ4_K_M2.5 GB3-5⚠️ Slow but works
Gemma 2BQ4_K_M2.0 GB4-6⚠️ Okay for simple tasks
Llama 3.2 1BQ4_K_M1.5 GB6-8βœ… Best quality at this size
Mistral 7BQ4_K_M5.5 GB1-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

snippet
code
llm = Llama(
model_path="./llama-3.2-1b.Q4_K_M.gguf",
    n_ctx=2048,
    n_threads=4

)

def classify_command(text):

example
code
"""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

snippet
code
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

WebLLM Demo

WebLLM Performance

Model Browser GPU Download Size Tokens/sec

Llama 3.1 8B Q4ChromeRTX 40904.3 GB80-100
Llama 3.1 8B Q4ChromeM2 MacBook4.3 GB40-60
Phi-3 Mini Q4ChromeRTX 30602.1 GB50-70
Gemma 2B Q4ChromeIntegrated GPU1.4 GB10-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

snippet
code
ONNX (Open Neural Network Exchange) is a model format designed for portability. Convert once, run anywhere.

PyTorch Model β†’ ONNX Export β†’ Run on:

example
code
β”œβ”€β”€ 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

snippet
code
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
dummy_input = torch.randint(0, 1000, (1, 128))

torch.onnx.export(

example
code
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

snippet
code
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 typesAny ONNX modelLLMs (GGUF)Any Core MLAny TensorRT
Best forCross-platformLLM chatiOS/macOS appsMax GPU perf
QuantizationINT8, INT4Q2-Q8 variantsFP16, INT8FP16, INT8, INT4
Setup complexityLowLowMediumHigh
πŸ’‘

The Edge Deployment Decision Tree

Do you need >13B parameter models?

β”œβ”€β”€ Yes β†’ Cloud (edge can't handle it well yet)

└── No

example
code
β”‚
      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.

← Previous Ep 40: Load Balancing Multiple Models: How Production AI Stays…