Running LLMs Offline on Mobile: From Model Selection to First Deployment
Running large language models (LLMs) offline on mobile devices is increasingly viable. This article provides a comprehensive guide on evaluating device capabilities, estimating memory requirements, selecting model quantization formats, choosing inference frameworks, and deploying an LLM on Android using llama.cpp. It also includes smoke testing, troubleshooting checklists, a benchmark record template, and security reminders for developers and advanced users.
1. Can Mobile Phones Run LLMs Offline? Three Key Questions
Running open-source LLMs offline on a mobile phone depends on three main factors: whether the memory can hold the model plus runtime overhead, whether there is sufficient storage space, and whether the system and framework can invoke the device’s computing resources. Only when all three are satisfied is it worth proceeding to the next step.
Cloud-based LLMs are powerful, but there are specific scenarios where it is not appropriate to send data to a server. The first involves privacy-sensitive content such as chat history, health data, and internal corporate documents. The second includes environments with unstable network connections, like airplane mode, underground parking lots, or cross-region business trips. The third involves high-frequency API calls billed by token, which incur continuous costs. Local inference eliminates network round-trips and per-usage fees, though at the cost of increased power consumption and heat generation.
Two things should be noted in advance. First, during a cold start, the model weights must be loaded from storage into memory, making the first response typically slower than subsequent ones; exact figures can only be determined through actual testing. Second, while models in the few-GB range can already handle daily conversations, summarization, and simple code assistance, they still lag behind cloud-based LLMs in complex reasoning and long-text comprehension.
2. Device Inventory: System, Storage, Memory, and Chip
Before deployment, verify the following four conditions one by one.
1. System Version. Inference framework documentation specifies a minimum system version. If the system is too old, it may lack the acceleration interfaces required by the framework. In such cases, upgrade the system first or switch to a framework with better backward compatibility.
2. Storage Space. Storage requirements depend on the size of the chosen model; there is no universal fixed number. During the download phase, you need space for the model file itself, and some tools will also write cache data. It is recommended to reserve free space at least 1.5 times the size of the selected model file. For example, if the model file is about 1.8 GB, you should leave at least 2.7 GB of free space.
3. Memory Capacity and Bandwidth. During inference, model weights are repeatedly read from memory into the compute unit. Memory capacity determines how large a model can be loaded, while memory bandwidth affects generation speed, typically measured in tokens/s (tokens generated per second). Two phones with the same memory capacity but different bandwidths may have noticeably different generation speeds, so you cannot look at memory size alone.
4. Chip Acceleration Capability. Many frameworks support delegating computation to an NPU or GPU, but accelerators usually only support a subset of operators, and coverage varies across models. Before choosing an acceleration solution, check the framework’s compatibility list and confirm that if the accelerator does not support a specific operator, the framework can fall back to the CPU to continue running. Otherwise, errors may occur, or speed may drop sharply.
3. Estimating Peak Memory: Formula and Checklist
Whether it can run depends largely on peak memory. A practical estimation formula is:
Peak Memory ≈ Weight Memory + KV Cache + Runtime Overhead
Weight Memory is approximately: Parameters (in billions, B) × Average bits per weight ÷ 8, with the result in GB. A 4-bit quantization format like Q4_K_M has an average of about 4.8 bits, so a 3B model’s weights would be roughly 3 × 4.8 ÷ 8 ≈ 1.8 GB.
KV Cache grows with conversation length and is approximately: 2 × Number of Layers × Number of KV Heads × Dimension per Head × Context Length × 2 (calculated in FP16, 2 bytes per element). Parameters like the number of layers and KV heads can be found in the model directory’s config.json. For illustrative parameters: 28 layers, 4 KV heads, 128 dimensions per head, and a context length of 4096, the KV cache would be about 0.2 GB.
Runtime Overhead includes the framework itself, thread stacks, and system buffers. Empirically, this is about 0.5 to 1 GB, depending on the framework and device.
Using the example above, the peak memory is about 1.8 + 0.2 + 0.8 ≈ 2.8 GB.
The recommended safety margin in this article is: before loading, the available memory should be no less than 1.3 times the estimated peak. Note that this refers to available memory, not the device’s total nominal memory. You can check the current available memory by running grep MemAvailable /proc/meminfo in Termux; the unit is kB.
If memory is insufficient, two things can happen. First, the system may swap out inactive memory pages, causing a noticeable speed drop, along with increased heat and power consumption. Second, the system may terminate the process directly, manifesting as an app crash or an exit during inference. If your estimate is close to the available memory limit, you should switch to a smaller model size rather than forcefully closing other apps to make room.
Before deployment, check against the following checklist:
- System version meets the framework’s minimum requirements
- Free storage space is at least 1.5 times the model file size
- Current available memory is no less than 1.3 times the estimated peak
- The selected quantization format has been verified on the chosen framework
- The SHA256 checksum of the model file has been verified
4. Selecting Model Size and Quantization Format
Open-source models typically offer multiple parameter sizes and quantized versions. Consider the following guidelines when making your selection.
1. Prefer medium-sized instruction-tuned versions. Model names often include identifiers like instruct, chat, or it, indicating that they have been instruction-tuned, making them more suitable for direct conversation than pure base models. These versions generally offer a good balance in conversation, summarization, and instruction following, making them an ideal default choice.
2. Choose lightweight versions for limited memory. Smaller models generate faster and consume less memory, making them suitable for older devices or scenarios requiring long-term background residency. The trade-off is a decrease in complex reasoning and long-text comprehension capabilities.
3. Do not treat “fits in memory” as the sole criterion. When peak memory approaches available memory, the device will frequently page, slowing down, heating up, and potentially crashing. Always leave sufficient margin.
4. Select quantization format based on memory. Quantization compresses weights from high precision to lower bit widths. It reduces file size and memory usage but introduces some quality loss. Common choices are as follows:
| Quantization Format | Approx. Bits | Characteristics | Recommendation |
|---|---|---|---|
| Q8_0 | ~8.5 | Quality near original precision, largest file size | Use when memory is ample |
| Q5_K_M | ~5.7 | Balanced quality and size | Use with moderate memory |
| Q4_K_M | ~4.8 | Common trade-off between size and quality | Default first choice for mobile |
| Q3 and below | ~3 to 4 | Small size, noticeable quality loss | Try only when memory is extremely tight |
The format must also match the framework. llama.cpp uses the GGUF format, MLX uses the MLX format, and MLC LLM requires files generated by its conversion process. When selecting a model, first confirm which format your framework supports, then find the corresponding version.
5. Choosing an Inference Framework
| Framework | Typical Platform | Model Format | Target Audience | Main Limitations |
|---|---|---|---|---|
| llama.cpp | Android (compiled in Termux), macOS, Linux, Windows | GGUF | Developers and advanced users who want control over details | Requires command-line operation and compilation; parameters must be adjusted manually |
| MLC LLM | Android, iOS, Desktop | MLC format (requires conversion) | Developers looking to integrate models into apps | Models must be converted following the official process |
| MLX | Primarily Apple silicon Macs | MLX format | Mac users | Limited mobile ecosystem |
| Google AI Edge (LLM Inference) | Android | Officially converted format | Android app developers | Limited variety of supported models |
| Ollama | Desktop systems | Proprietary model library | Desktop users | Not intended for mobile platforms; unsuitable for phones |
For most users looking to get their first successful run, llama.cpp offers the most comprehensive documentation and community resources. The following steps will use it as an example.
6. First Deployment Guide: llama.cpp on Android
Step 1: Install Termux. Please obtain it from F-Droid. The version on Google Play is no longer updated.
Step 2: Grant storage permissions. Execute the following command in Termux:
termux-setup-storage
Step 3: Install build tools.
pkg update && pkg upgradepkg install git cmake clang
Step 4: Clone and compile llama.cpp.
git clone https://github.com/ggml-org/llama.cppcd llama.cppcmake -B buildcmake --build build --config Release -j 4
Compilation takes a long time, depending on your device, and the phone will heat up during the process. It is recommended to plug it into a power source and keep it ventilated. The number after -j should not exceed the phone’s core count.
Step 5: Place the model file. Download the GGUF file from the model’s official page and save it to your phone using a browser first. Then move it into the Termux home directory, where read/write speeds are typically faster than shared storage.
mkdir -p ~/modelsmv /sdcard/Download/model_name.gguf ~/models/
Step 6: Verify file integrity. The official page usually provides a SHA256 value.
sha256sum ~/models/model_name.gguf
If the output hash does not match the official value, re-download it. Interrupted downloads or corrupted files often manifest as loading failures or garbled output.
Step 7: Run the first inference.
./build/bin/llama-cli -m ~/models/model_name.gguf -t 4 -n 64 -no-cnv -p "Introduce yourself in one sentence."
Parameter explanations: -t specifies the thread count; it is recommended to not exceed the number of performance cores, starting with 4. -n is the maximum number of tokens to generate. -no-cnv disables conversation mode, which is convenient for a one-off test. Parameters should be verified against the output of ./build/bin/llama-cli --help, as they may vary across versions.
7. Smoke Testing: Three Must-Pass Tests
Smoke tests do not evaluate model quality; they only confirm that the deployment pipeline works correctly. The following three must pass:
- Can load. The model loads completely without errors.
- Can output. The generated text is readable, without large amounts of gibberish, infinite repetition, or empty output.
- Can sustain. Continuous operation for about 10 minutes, generating multiple rounds of content, without crashing.
After testing, record the time to first token, generation speed, and memory changes. At the end of the run, the terminal usually outputs performance statistics, including generation speed, which can be directly transcribed.
Multilingual capabilities should also be tested separately. You can use a prompt like the following:
Please summarize the following content in three sentences: ... (paste about 200 words of text here)
If the output is fluent and the main points are accurate, the capability is acceptable. If there are many typos or irrelevant answers, refer to the troubleshooting checklist in the next section.
8. Troubleshooting Checklist: Heating, Crashing, and Output Quality
| Symptom | Common Cause | Solution |
|---|---|---|
| Download failure or loading error | Incomplete file, hash mismatch | Re-download and verify SHA256 |
| Insufficient space warning | Free storage is less than 1.5 times the model file | Clear cache or choose a smaller model size |
| Crash during inference | Peak memory exceeds available memory | Choose smaller parameters or lower quantization; close background apps |
| Operator not supported error | Accelerator does not support the operator | Run on CPU or change framework version |
| Noticeable speed drop | Thermal throttling or memory paging | Reduce thread count, use intermittently, shorten context |
| Device heating up noticeably | Prolonged full-load inference | Pause, allow cooling, avoid charging during high-load operation |
| Poor output with garbled text | Weak model capability or mismatched chat template | Switch to a better instruction-tuned version; ensure template matches the model |
| Infinite repetition | Generation length too long or model size too small | Reduce generation length, adjust repetition penalty, or switch models |
When troubleshooting, change only one variable at a time and record the results before and after. Modifying multiple settings simultaneously makes it impossible to determine which one caused the effect.
9. Benchmark Record Template
The table below can be copied and used directly. Fill in one row per test; multiple tests make comparison easier.
| Item | Example Entry | Description |
|---|---|---|
| Test Date | 2026-11-24 | For traceability |
| Device Model & OS Version | Specific model, specific Android version | Specify the exact model |
| Available Memory (before load) | Unit: MB | Check with grep MemAvailable /proc/meminfo |
| Model & Quantization Format | 3B Instruct, Q4_K_M | Specify parameter count and quantization format |
| Framework & Version | llama.cpp, release tag or commit hash | Different versions may yield different results |
| Thread Count | 4 | Corresponds to the -t parameter |
| Time to First Token | Unit: seconds | From sending the prompt to the first character output |
| Generation Speed | Unit: tokens/s | Take the statistical value from terminal output |
| Peak Memory | Unit: MB | Sample multiple times during execution; take the maximum |
| Max Device Temperature | Unit: Celsius | Check via system temperature info |
| Continuous Run Duration & Result | 10 minutes, no crash | State whether it crashed and any phenomena |
| Output Quality Evaluation | Mostly normal, occasional typos | Use the test text mentioned above |
All values depend on the device, OS version, and ambient temperature, representing only the conditions of this specific test and cannot be directly generalized to other devices.
10. Security Reminders
- Download only from official channels. Model files should come from official repositories or official pages. Third-party packaged APKs and model files from unknown sources may have been tampered with.
- Verify hash values. Compare the SHA256 after every download to confirm file integrity.
- Pay attention to licenses. Different models have different license terms. Verify the terms before using them for commercial purposes.
- Monitor storage space. Interrupted downloads leave incomplete files that still occupy space; delete them promptly.
- Do not modify system files or delete system partitions to free up memory. Such operations can cause system instability and are difficult to recover from.
- Be aware of the impact of prolonged high loads. Continuous full-load operation increases power consumption and heat. If the battery shows abnormal swelling or the device becomes too hot to touch, stop immediately.
- Protect local data. Chat histories saved locally remain on the phone. Ensure proper access control if the device is shared or lost.
- Keep configuration records. Accidental deletion of a model requires re-downloading. It is recommended to keep the model’s hash value and test records for easy verification and reproduction.
