Skip to main content
Start with LFM3-1.7B for a new application and llama.cpp v0.8.0 (b11960) or later. Download the model and use its chat template and sampling settings from the main guide. The native examples and Android cookbook apps below retain their tested LFM2.5 checkpoints. They are a smaller-footprint reference path. Test a new checkpoint’s bindings, memory fit, and conversation handling on the target device before replacing a bundled model; a desktop server check does not certify a mobile app. llama.cpp is a dependency-free C/C++ library, so it links straight into a mobile app. Every LFM checkpoint ships as GGUF on Hugging Face (LiquidAI), and upstream llama.cpp supports the LFM2 architecture, LFM2-VL projectors, and LFM2/LFM2.5 tool-call parsing. No wrapper SDK is required.
On a phone, run the library in-process through the C API as shown here. llama-server is the right tool on laptops, desktops, and servers — see Desktop & Server Apps.

1. Add llama.cpp to your project

Every llama.cpp release publishes a prebuilt llama.xcframework with slices for iOS (device and simulator), macOS, visionOS, and tvOS. It is built with Metal enabled and includes the mtmd multimodal library.
  1. Download llama-<build>-xcframework.zip from llama.cpp releases and unzip it.
  2. In Xcode, drag llama.xcframework into your target’s Frameworks, Libraries, and Embedded Content.
  3. import llama in Swift. The C API is exposed directly; no bridging header is needed.
The prebuilt framework targets iOS 16.4+ and macOS 13.3+. To build it yourself (for example, to change the minimum OS version or drop slices):
The upstream llama.swiftui example is a complete SwiftUI chat app built this way.

2. Get a model onto the device

Download a GGUF from Hugging Face at first launch and keep it in app-private storage. llama.cpp memory-maps the file, so it must be a real file on disk — not a compressed asset.
  • Use URLSessionConfiguration.background(withIdentifier:) on iOS and WorkManager (or DownloadManager) on Android so downloads survive backgrounding.
  • Q4_0 is the best default on phones: it is the smallest quantization and llama.cpp repacks it into Arm-optimized kernels at load time. Use Q4_K_M when you want slightly better quality on capable devices. See Model Library for every GGUF repository.
  • For vision models also download the matching mmproj-*.gguf from the same repository (see Vision & Audio).
For development you can push a file directly:

3. Load the model and stream a response

The generation loop is the same on every platform: load the model, create a context, build a sampler chain with the model’s sampling parameters, format the prompt with the chat template, then decode and sample one token at a time.
Usage from a view model:
For multi-turn conversations, prompt-cache reuse, and how to keep the KV cache aligned with the chat template, see Chat & Streaming.

4. Tune for mobile

  • Memory. Weights are memory-mapped by default (use_mmap = true), so they count as file-backed pages rather than app RSS — iOS jetsam and Android LMK treat them far more leniently. Keep n_ctx as small as the use case allows; the KV cache scales linearly with it.
  • Threads. Use the performance cores only: n_threads = activeProcessorCount - 2 is a good starting point. More threads than physical big cores usually slows decoding.
  • GPU. On Apple devices set n_gpu_layers = 99 to run on Metal. On Android, CPU is the safe default; Vulkan and OpenCL (Adreno) backends exist but need device-specific testing.
  • Quantization. Q4_0 for the smallest footprint and fastest Arm kernels; Q4_K_M when quality matters more than a few hundred MB.
  • Vision and audio. The XCFramework includes mtmd; on Android enable LLAMA_BUILD_MTMD. See Vision & Audio.
  • Benchmark on hardware. llama-bench -m model.gguf -p 512 -n 128 from the prebuilt Android or macOS binaries gives prefill/decode tokens-per-second before you write any app code. See Hardware Evaluation.

Next steps

Chat & Streaming

Multi-turn conversations, sampling parameters, prompt caching.

Structured Output

Constrain generation to a JSON schema or GBNF grammar.

Function Calling & Agents

Tool use with LFM2.5’s native tool-call parser.

Vision & Audio

Run LFM2.5-VL and LFM2.5-Audio on llama.cpp.
Last modified on November 18, 2026