A Practical Guide to Running Open-Source LLMs Offline on Phones and Computers

    This article is a practical guide for readers looking to run open-source Large Language Models (LLMs) offline on their phones or computers. It covers six key areas: estimating device memory capacity, choosing the right model formats and tools, downloading and verifying models, measuring inference speed and memory usage, troubleshooting common issues, and understanding the boundaries of offline usage. Software names, versions, and model tags mentioned will be continually updated, so always refer to the official documentation and model pages for actual operations.

    1. Estimate Memory First: Which Model Can Your Device Run?

    The primary limitation for offline inference is memory. Once model weights are loaded, they reside in memory, and inference requires additional space. The estimation formula is as follows:

    Required Memory ≈ Weight Size + KV Cache + Runtime Overhead

    • Weight Size: Approximately equal to the number of parameters (in billions) multiplied by the bits per parameter, divided by 8, in GB. For a 4B model, the theoretical value at 4-bit quantization is 4 × 4 ÷ 8 = 2 GB. In practice, the Q4_K_M format retains higher precision for key layers, averaging about 4.5 to 5 bits per parameter, making the file size around 2.5 GB.
    • KV Cache: Grows linearly with context length. If the context expands 8 times, the KV cache expands about 8 times, so reserve extra space for long document analysis.
    • Runtime Overhead: Varies significantly across applications; estimate between 0.5 to 1.5 GB.

    As a rule of thumb, available memory (after deducting system and other app usage) should be at least 20% higher than the estimated value. With insufficient margin, the system will frequently page, and the inference process might be terminated directly.

    Below is a rough reference table for Q4_K_M quantization (actual file sizes are subject to model pages):

    Parameter Size File Size (approx.) Recommended Available Memory Suitable Devices
    0.6B–1.7B 0.4–1.2 GB 4 GB or more Entry-level phones
    3B–4B 2–2.6 GB 6–8 GB Mid-to-high-end phones, entry-level laptops
    8B About 5 GB 12 GB or more Laptops with 16 GB RAM
    12B–14B About 8–9 GB 16 GB or more PCs with 16 GB+ RAM
    30B-class MoE About 18 GB 32 GB or more High-memory PCs

    How to Choose Quantization Bits: Lower bits mean smaller files but more noticeable quality loss. If memory is sufficient, Q5 or Q6 is a good choice. Q4_K_M is the default and strikes a balance between size and quality. Only consider Q3 or Q2 when memory is extremely tight, though error rates in reasoning, coding, and math will significantly increase.

    Common Open-Source Model Series:

    • Qwen3 series: Available in 0.6B, 1.7B, 4B, 8B, 14B, 32B sizes, plus Mixture of Experts (MoE) versions.
    • Gemma 3 series: Available in 1B, 4B, 12B, 27B sizes. The 4B and above support image input.
    • Llama 3.2 series: 1B and 3B are text-only models, while 11B is a vision version.

    If image processing is required, choose versions labeled with vision or multimodal capabilities, such as Gemma 3 4B and above, or the Qwen2.5-VL series. Text-only models cannot read images.

    MoE Models have a large total parameter count, but only activate a subset of experts during inference, making the speed similar to the size of the activated parameters. However, memory must still be calculated based on total parameters, as all experts need to be loaded into memory.

    Base vs. Instruct: Models with “Base” in the name are pre-trained and suitable for fine-tuning or text completion. For daily conversations, choose the Instruct version (often labeled Instruct or Chat).

    2. Choosing Formats and Running Tools

    The most common format for local execution is GGUF, widely supported by the llama.cpp ecosystem across Windows, macOS, Linux, and Android. Apple Silicon Macs can also use the MLX format, run via mlx-lm. Google’s on-device solution uses the LiteRT format, corresponding to Google AI Edge applications.

    Common tools categorized by platform include:

    • llama.cpp: An open-source C/C++ inference engine that provides the llama-cli command-line program and the llama-server OpenAI API-compatible server. Suitable for users who want fine-grained parameter control.
    • Ollama: A desktop tool supporting macOS, Windows, and Linux. Pull and run models with a single command. Fastest to get started.
    • LM Studio: A GUI tool that allows direct searching and downloading of GGUF models. Ideal for desktop users who want to avoid the command line.
    • mlx-lm: For Apple Silicon Macs, installed via pip, leveraging unified memory effectively.
    • PocketPal AI: An open-source mobile app supporting iOS and Android, capable of directly downloading GGUF models.
    • Google AI Edge Gallery: A mobile sample app provided by Google for offline running of Gemma series models.

    Before installation, verify whether the app is open-source and comes from the official app store or repository. Open-source app code can be audited, while closed-source apps cannot guarantee how your data is processed locally.

    3. Deployment Steps

    Step 1: Verify Device Environment

    • Phones: Refer to the system version and memory requirements on the app store page. Models on phones are typically 0.6B to 4B in size.
    • Mac: Apple Silicon models offer significantly better inference speeds than Intel models. Prioritize using MLX or llama.cpp’s Metal acceleration.
    • Windows and Linux: With an NVIDIA GPU, use the CUDA version of llama.cpp or Ollama to offload model layers to VRAM for acceleration. Without a dedicated GPU, the CPU version works, albeit slower.
    • Storage Space: Reserve free space at least 1.2 times the model size. The download process generates temporary files; insufficient space will cause the download to fail.

    Step 2: Download and Verify Model

    1. Search for the model name plus GGUF on Hugging Face, e.g., “Qwen3-4B GGUF”. Select repositories maintained by well-known quantization publishers and confirm that a Q4_K_M file is available.
    2. Check if the file size is close to the estimated value in the table above. If the file is noticeably too small or too large, reconfirm the selected quantization format.
    3. Find the SHA256 checksum on the file page, calculate it locally after download, and compare:

      • macOS and Linux: shasum -a 256 filename (Linux can also use sha256sum filename)
      • Windows: certutil -hashfile filename SHA256

      If the checksums do not match, do not use the file; download it again.

    4. Check the model’s license, such as Apache 2.0, Gemma Terms of Use, or Llama Community License. Licenses may restrict commercial use, redistribution, etc.
    5. Use download tools that support resuming, such as the Hugging Face official command-line tool (hf or the legacy huggingface-cli). Downloading large files over mobile networks consumes significant data; connecting to Wi-Fi is recommended.

    When using Ollama, ollama pull automatically downloads and verifies the model, eliminating the need for manual checksum calculation. Models are saved by default in the .ollama folder under the user directory.

    Once the model is saved locally, it can be used offline. To verify true offline capability, turn on Airplane Mode after downloading and send a test prompt.

    Step 3: Run and Benchmark

    Using llama.cpp as an example, on Mac or Linux:

    1. brew install llama.cpp
    2. llama-cli -m ./models/model.gguf -c 4096 -t 6 -ngl 99 -cnv

    Parameter meanings: -c sets the context length, -t sets the number of threads, -ngl 99 offloads as many model layers to the GPU as possible, and -cnv enters conversation mode.

    To call the model via a local API, use the server program:

    1. llama-server -m ./models/model.gguf -c 8192 --port 8080

    Once started, programs on the local network can access the model via http://localhost:8080.

    Using Ollama, run the following command (tags are based on the model library name):

    1. ollama run qwen3:4b --verbose

    After the first run, it is recommended to perform three types of tests:

    1. Basic Q&A: Ask a common sense question to confirm normal responses.
    2. Multimodal Input: If using a vision version, upload a local image and ask it to describe the content.
    3. Multi-step Reasoning: Provide a problem requiring step-by-step calculation to check if the reasoning process is complete and the conclusion is correct.

    4. Speed Measurement and Parameter Tuning

    Metrics to Record

    • First Token Latency: The time from submitting the prompt to the appearance of the first token. This is mainly affected by prompt length and device computing power.
    • Generation Speed (token/s): The number of tokens output per second, reflecting the fluency of the response.
    • Peak Memory: The maximum memory used by the application during inference.

    Measurement Methods: llama-cli outputs speed statistics at the end of generation, while Ollama displays the eval rate with the --verbose parameter. Peak memory can be monitored using Windows Task Manager, macOS Activity Monitor, or /usr/bin/time -v on Linux.

    Use the same set of prompts to measure multiple times and record the average as the local baseline. When adjusting parameters later, compare them against this baseline.

    Parameter Tuning Strategies

    • Threads (-t): Set to the number of physical CPU cores, not all logical cores. Too many threads will slow down due to resource contention. Test sequentially with 4, 6, 8, and choose the fastest.
    • Context Length (-c): Set only to the minimum actually needed. Every time the context length doubles, the KV cache usage roughly doubles.
    • GPU Offload Layers (-ngl): Set as high as possible when VRAM is sufficient to run the entire model on the GPU. If VRAM is insufficient, gradually decrease it to leave some layers on the CPU.
    • Temperature: Controls the randomness of responses. Set lower for factual Q&A and code generation (typically 0.3 to 0.7). It can be appropriately higher for creative writing.

    Continuous high-load operation on phones will cause heat, and the system may throttle performance. For long generation tasks, it is recommended to plug in the power and limit the length of a single response.

    5. Common Issues Troubleshooting

    Issue Possible Cause Solution
    Download interrupted Network instability, system suspended app Re-download using a tool that supports resume; verify SHA256 after completion
    Crashes or process killed on load Insufficient memory Switch to a smaller model or lower quantization bits, close other apps, reduce context length
    Very slow generation, frequent stuttering Memory swapping, too many threads, or system restricting background execution Reduce thread count; set battery optimization to unrestricted for the app in Android settings
    Repetitive or garbled responses Quantization bits too low, using a Base model, or chat template mismatch Use Q4_K_M or higher quantization; ensure using an Instruct model; lower the temperature parameter
    Cannot recognize images Selected model does not support images, or missing vision projection file Switch to a vision model; load the corresponding mmproj file in llama.cpp
    Responses slow down or get truncated after a long chat Context window is full Clear the session or ask in segments; if longer context is needed, increase memory or reduce other usage
    Phone overheats noticeably Sustained high-load operation Use while plugged in, shorten single generation length, lower thread count

    6. Boundaries of Offline Usage

    The main benefit of offline inference is that data never leaves the device. Prompts and responses are saved locally and are not uploaded to the model provider’s servers. However, this benefit has prerequisites: the application itself must be trustworthy, and the device’s storage must be protected. Chat logs are often saved in plaintext within the app directory; when sharing a device, enable the system’s lock screen and disk encryption.

    Offline models also have clear limitations:

    • The capability ceiling is limited by parameter size. Small models generally underperform cloud-based flagship models on long-text reasoning, niche knowledge, and complex coding.
    • The model’s knowledge is frozen before its training cutoff date. Offline status prevents querying real-time information; separate data must be provided if the latest information is needed.
    • Runtime consumes battery and memory. Prolonged use will affect the device’s battery life and the responsiveness of other applications.

    Conclusion

    The key to running open-source LLMs offline on phones or computers comes down to three things: estimating model size using the memory formula, choosing a balanced quantization format like Q4_K_M, and verifying via benchmarking that both speed and memory are within acceptable limits. When issues arise, troubleshoot systematically in the order of memory, threads, context, and templates—this will usually lead to the root cause.