Mobile AI Assistant on Llama: On-Device and Server Integration
Integrating Llama into a mobile app comes down to two questions: run the model locally or through a server? The choice dictates the entire architecture—from binary size to support costs. We've been through this path with dozens of projects, from medical chat agents to financial advisors. Below are the technical details that will save you months of experimentation.
How to Choose Between On-Device and Server Llama?
On-device — the model lives in the phone's memory, inference works without internet. Feasible for Llama 3.2 1B and 3B in INT4 quantization. Llama 3.2 3B INT4 occupies ~2 GB RAM and on an iPhone 15 Pro delivers 15–25 tokens/sec. This is the option for apps with strict privacy requirements (medical data never leaves the device) or offline use.
Server Llama — the model runs on your GPU server (or rented), the mobile client communicates via API. Allows you to use Llama 3.3 70B or Llama 3.1 405B—full-sized models indistinguishable in quality from GPT-4. Most commercial projects choose the server approach: easier to update the model, no RAM size limitation.
Why Is On-Device Still Relevant?
For scenarios requiring critical privacy (banking transactions, medical recommendations) or unstable internet, a local model is the only option. Moreover, you avoid server infrastructure and API request costs. Savings on server expenses with local deployment can be substantial. However, response quality is lower due to limited model size. For instance, in a medical consultation app for clinicians, we deployed Llama 3.2 3B Q4_K_M on iPad. Inference ran at 12 tokens/sec via Core ML, ensuring patient data never left the device and eliminating server costs. The client saw a 4x reduction in monthly infrastructure expenses compared to their cloud NLP pipeline.
Quantization and Performance Details
On-Device Runtime: llama.cpp, Core ML, ExecuTorch
llama.cpp is the most mature runtime for GGUF models. On iOS: compiled as a C++ library, called via Objective-C++ bridging header. On Android: via JNI. Complexity lies in building for different architectures (arm64-v8a for modern, armeabi-v7a for legacy). The official llama.cpp repository contains ready-to-use build scripts.
// iOS — minimal wrapper over llama.cpp class LlamaContext { private var context: OpaquePointer? init(modelPath: String) { var params = llama_context_default_params() params.n_ctx = 4096 params.n_threads = 4 // fewer threads — less heat let model = llama_load_model_from_file(modelPath, llama_model_default_params()) context = llama_new_context_with_model(model, params) } func generate(prompt: String, maxTokens: Int = 256) -> AsyncStream<String> { // tokenize → sample loop → detokenize } } Apple MLX / Core ML — Apple provides an official converter for Llama to Core ML format. Advantage: Neural Engine is automatically used, inference is faster and cooler than via CPU. Limitation: iOS 17+ only.
ExecuTorch — Facebook's runtime for mobile, officially supports Llama 3. More complex build but better integration with Android Neural Networks API.
On-Device Runtime Comparison
| Runtime | iOS | Android | Performance | Complexity |
|---|---|---|---|---|
| llama.cpp | + | + | High | Medium |
| Core ML | + (17+) | - | Very high | Low |
| ExecuTorch | + | + | High | High |
Quantization: Precision Selection
| Type | Size (3B) | Quality | Speed |
|---|---|---|---|
| FP16 | ~6 GB | Baseline | Slow |
| Q8_0 | ~3.3 GB | ≈FP16 | Moderate |
| Q4_K_M | ~2.0 GB | Good | Fast |
| Q2_K | ~1.3 GB | Noticeably worse | Very fast |
For most mobile tasks, Q4_K_M is the optimal balance. Q2_K can be considered for devices with 4 GB RAM.
Server Llama: Ollama and vLLM
For server deployment — Ollama (simplicity) or vLLM (performance). Ollama provides an OpenAI-compatible API: POST /api/chat, request format identical to OpenAI Chat Completions. A mobile client written for OpenAI works with Ollama unchanged — just change the base URL.
vLLM is preferable for production under load: continuous batching, tensor parallelism on multiple GPUs, throughput several times higher than Ollama.
Fine-Tuning: When and How
Fine-tuning is necessary when base Llama fails at specialized tasks: medical terminology, legal style, industry specifics. LoRA/QLoRA is the standard approach for fine-tuning on a single GPU. Trained adapters (~50–100 MB) are loaded on top of the base model. Deploying on-device reduces operational costs for cloud computing.
What's Included in the Work
- Requirements analysis and architecture selection: on-device or server, model and quantization choice.
- Runtime integration: building llama.cpp/ExecuTorch for iOS/Android, API wrapper.
- Server setup: deploying Ollama/vLLM, load balancing, monitoring.
- Testing: latency metrics, memory consumption, response quality.
- Documentation and training: how to update the model, change parameters.
- Post-launch support: integration warranty, consultation on modifications.
Implementation Process: Step by Step
- Audit requirements: use cases, target devices, budget.
- Choose model and runtime.
- Integration and build.
- Deploy server part (if needed).
- Test metrics.
- Documentation and handover.
- Warranty support.
Time Estimates
Server Llama with Ollama and mobile client — 1–2 weeks. On-device via llama.cpp with builds for iOS/Android — 3–5 weeks. Fine-tuning + deployment — estimated separately. Get a consultation for your project. Leave a request—we will analyze the task and propose the optimal solution.







