Created by Ali Moustafa — mustafa30102001@gmail.com
Run large language models entirely on your iPhone or iPad. No internet required, no subscriptions, no data leaves your device.
OnDeviceAI uses llama.cpp with Metal GPU acceleration to run GGUF models locally on Apple Silicon, delivering fast and private AI conversations.
- 100% On-Device Inference - All processing happens locally using Metal GPU acceleration
- 14+ Open Source Models - Download and switch between models from the built-in catalog
- Streaming Responses - See tokens appear in real-time as the model generates
- Conversation History - All chats are persisted locally with SwiftData
- Model Management - Download, delete, and switch models with background downloads
- Customizable Generation - Adjust temperature, top-p, max tokens, and context size
- Custom System Prompts - Define how the AI assistant behaves
- Theme Support - Light, dark, and system themes with 8 accent color options
- Privacy First - Zero network calls during inference, all data stays on device
- Universal App - Optimized for both iPhone and iPad with adaptive layouts
| Model | Parameters | Size (Q4) | Best For |
|---|---|---|---|
| TinyLlama 1.1B | 1.1B | ~670 MB | Quick responses, testing |
| DeepSeek R1 Distill | 1.5B | ~1.1 GB | Reasoning tasks |
| Gemma 2 2B | 2B | ~1.6 GB | Instruction following |
| Phi-2 | 2.7B | ~1.8 GB | Reasoning, code |
| StableLM Zephyr 3B | 3B | ~1.8 GB | General chat |
| Llama 3.2 3B | 3B | ~2.0 GB | Mobile-optimized chat |
| Qwen 2.5 Coder 3B | 3B | ~2.1 GB | Code generation |
| Phi-3 Mini 3.8B | 3.8B | ~2.4 GB | Best small model |
| Yi 6B | 6B | ~3.8 GB | Bilingual (EN/ZH) |
| Llama 2 7B Chat | 7B | ~4.1 GB | Reliable general chat |
| Mistral 7B Instruct | 7B | ~4.4 GB | High quality responses |
| Qwen 2.5 7B | 7B | ~4.7 GB | General purpose |
| Meta Llama 3 8B | 8B | ~4.9 GB | Latest generation |
| Meta Llama 3.1 8B | 8B | ~4.9 GB | Multilingual, tool use |
Note: 7B+ models require iPhone 15 Pro / iPad with M-series chip (8+ GB RAM). Smaller models (1-3B) run well on iPhone 12+ and most iPads.
- iOS 17.0+
- Xcode 15.0+
- Swift 5.9+
- Physical device recommended (Metal GPU acceleration)
git clone https://github.com/YOUR_USERNAME/OnDeviceAI.git
cd OnDeviceAIopen OnDeviceAI.xcodeproj- Select the OnDeviceAI target
- Go to Signing & Capabilities
- Select your Development Team
- Update the Bundle Identifier if needed
The project uses llama.cpp via Swift Package Manager:
- In Xcode, go to File > Add Package Dependencies
- Enter:
https://github.com/ggerganov/llama.cpp - Select the
llamaproduct - Add to the OnDeviceAI target
Select your physical device and press Cmd+R.
The app works on Simulator but inference performance requires a physical device with Metal support.
OnDeviceAI/
├── App/
│ ├── OnDeviceAIApp.swift # App entry point, SwiftData container
│ └── ContentView.swift # Root TabView with theme support
├── Models/
│ ├── ChatMessage.swift # SwiftData message model
│ ├── Conversation.swift # SwiftData conversation model
│ └── ModelInfo.swift # Model catalog definitions
├── Services/
│ ├── LLMEngine.swift # llama.cpp inference bridge
│ ├── LLMService.swift # High-level inference orchestration
│ ├── ModelManager.swift # Downloaded model management
│ ├── DownloadManager.swift # Background download handling
│ └── ThemeManager.swift # Theme & accent color management
├── ViewModels/
│ ├── ChatViewModel.swift # Chat logic & state
│ └── ModelCatalogViewModel.swift # Catalog filtering & actions
└── Views/
├── Chat/
│ ├── ChatView.swift # Main chat interface
│ ├── MessageBubble.swift # Message bubble component
│ ├── ConversationListView.swift # Sidebar conversation list
│ └── ModelSelectorView.swift # In-chat model picker
├── ModelCatalog/
│ └── ModelCatalogView.swift # Model download catalog
└── Settings/
└── SettingsView.swift # App settings & theme picker
- SwiftData for conversation persistence (iOS 17+)
- MVVM architecture with
@Observable/ObservableObject - llama.cpp for inference (C++ library with Swift bridge)
- Metal GPU acceleration for fast token generation
- URLSession background downloads for model files
- ChatML prompt format for broad model compatibility
Edit OnDeviceAI/Models/ModelInfo.swift and add entries to the catalog array:
ModelInfo(
id: "your-model-id",
name: "Your Model Name",
fileName: "model-file.gguf",
downloadURL: "https://huggingface.co/.../model-file.gguf",
sizeBytes: 4_000_000_000,
family: .llama,
parameterCount: "7B",
quantization: "Q4_K_M",
description: "Description of the model."
)The LLMEngine.swift file contains commented-out llama.cpp integration code. To enable real inference:
- Add the llama.cpp Swift package dependency
- Import llama in
LLMEngine.swift - Uncomment the llama.cpp calls in
loadModel()andgenerate() - Build with the
llamaproduct linked
- Use Q4_K_M quantization for the best balance of quality and speed
- Start with smaller models (1-3B) to verify your setup
- Set context size to 2048 or lower for faster inference
- Close other apps to free RAM for larger models
- iPhone 15 Pro and M-series iPads offer the best experience
OnDeviceAI is designed with privacy as a core principle:
- All AI inference runs entirely on-device
- No data is sent to any server
- No analytics or tracking
- No account required
- Conversations are stored locally in SwiftData
- Models are downloaded from HuggingFace (the only network call)
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Ali Moustafa — mustafa30102001@gmail.com
This project is licensed under the MIT License - see the LICENSE file for details.
- llama.cpp - C/C++ LLM inference engine by Georgi Gerganov
- HuggingFace - Model hosting and community
- Meta AI - Llama model family
- Mistral AI - Mistral models
- Microsoft - Phi model family
- Google - Gemma models
- Alibaba - Qwen models
- DeepSeek - DeepSeek R1