Video 9 min
On-Device LLM in React Native: Running Qwen Offline With llama.rn and llama.cpp
How I run a small LLM entirely on the phone in a React Native and Expo app: llama.rn, a Qwen GGUF model at Q4_K_M, streaming, tool calling a small model can manage, and real numbers from an iPhone and a Galaxy S23.
Narrated in English Subtitles: English, 日本語, 한국어, Tiếng Việt, 简体中文
Transcript
I put my phone in airplane mode. No WiFi. No signal. Then I type into an app I build: create a job for Smith. The assistant searches my customers, finds two Smiths, and asks which one I mean.
Nothing has left the phone. The model runs on the phone itself. On an iPhone 14 Pro, about fifteen tokens a second, with no network at all.
This is how I built it, and what it took to make it useful. The app is for estimating. Users create jobs, search customers and manage projects by typing plain English. I built it with llama.rn, React Native bindings for llama.cpp, and Qwen 1.7B, a small model that turned out more capable than I expected. It has since moved to Qwen3.5-2B.
And I now switch off thinking mode properly, instead of smuggling control flags into the prompt.
The standard recipe: the user types a message, the app sends it to a cloud model provider, a response comes back, and the bill ticks up. For tradespeople running a business, that means customer names, addresses and phone numbers going to a third party. Pricing and notes on someone else's servers. Add GDPR and data-residency questions I'd rather not spend time on, and an API bill that grows with every user. The alternative is to run the model on the user's phone.
So that's what I did. A year earlier, I wouldn't have bothered. Then quantised models got small, smaller than most games, downloaded once. Mobile GPUs got fast, with llama.cpp using Metal on iOS and OpenCL on recent Qualcomm Android chips. Plenty for real-time streaming.
And small models got genuinely useful. Structured instructions, JSON, multi-step reasoning. Exactly what business logic needs. Nobody's asking it to write poetry.
I tested four small models. TinyLlama was the fastest, but it kept hallucinating customer IDs and dropping required fields. Phi-3-mini reasons well, but wouldn't shut up. I needed twenty words, and got essays. Gemma-2B was quick at classification, but couldn't consistently produce the action tags my tool system needs.
Qwen3-1.7B hit the sweet spot. Reliable structured output, precise instruction following, and chain-of-thought through think tags. In the Q4 K M format, weights are stored as four-bit values, in blocks with their own scale. The file comes out about seventy percent smaller, for a small quality loss. Setup was the easy part.
On Expo, llama.rn is a native module, so it needs a development build, not Expo Go. The model downloads on first use. Two to three minutes on WiFi. Five to eight on LTE. Then I load it with every layer on the GPU.
Offloading to Metal or OpenCL instead of the CPU is worth about a five times speedup. Nobody wants to stare at a spinner, so responses stream token by token. The first lands in about two hundred milliseconds. After that, it feels instant.
Then, tool calls. Big cloud models lean on JSON schemas for function calling. Small models fall over on them. Malformed JSON, missing fields, the lot. So I use a simpler XML protocol.
The prompt lists the available actions, and the model ends its reply with one action tag. XML won for boring reasons. The tags are unambiguous, it survives extra chatter around them, and a regex is all the parsing you need. Exactly as dumb as it looks. I run each action and feed the result back in.
Ask for a job for Smith, and it searches first, finds Jane and Bob, asks which, then creates the job. Small models also do better when they reason out loud. Before each reply, Qwen notes what the user wants, what it has, what's missing, and what to do. I strip that reasoning before it reaches the screen, but keep it visible while developing. The reliability difference is dramatic.
The model talks itself through the logic before committing to an action. The 8K context window fills up faster than you'd think once tool results pile in. Around thirty turns, I hit the wall. So I ask the model to summarise itself: the goal, the jobs and customer IDs it created, and anything unfinished. It carries on without losing track.
Saved sessions store every assistant message twice. Once cleaned up for display. Once raw, tags and all, so a resumed session gets its full context back.
In production, an iPhone 14 Pro loads the model in about three seconds. Then it streams at fourteen to sixteen tokens a second. A Galaxy S23 manages ten to twelve. An iPhone 11, six to eight, and it occasionally crashes on low memory. My rule of thumb: six gigabytes of RAM or more for a smooth experience.
It runs on four, but you'll probably need to unload the model in the background. iOS will happily kill an app for hoarding memory. So when the app leaves the foreground, I release the model, and reload it when it comes back. Power isn't free either. Heavy use costs about six to eight percent of battery a day.
The GPU draws more, but finishes sooner, and users clearly prefer the instant response.
Two months into the beta, the query breakdown surprised me a little. Sixty-eight percent were one thing: create a job for a customer. Ninety-one percent succeed on the first try. Failures are misspelled names, very long conversations, and the model inventing customer IDs. That last one used to be much worse, until tool results said customer ID equals forty-two, instead of prose.
Small models need that scaffolding spelled out. On-device, it costs nothing to run. The cloud version, by my rough estimate, is about eighteen dollars a month on a budget model, and far more on the top-tier ones. Not ruinous. But on-device paid for itself on day one.
And at ten thousand users, it would still cost nothing.
Qwen 1.7B is great at structured tasks, and terrible at multi-hop reasoning, factual recall, creative writing and nuance. Design around what small models do well. Older phones like the iPhone 8 struggle, so detect that and fall back gracefully. And every new model means users download 1.1 gigabytes again. iOS on Metal is around twenty percent faster.
But the gap between a good and a bad Android phone is bigger than the gap between platforms. Test on both. My real test is simple. Flip on airplane mode and use the app properly. Only the backend saving should fail, gracefully.
Next, maybe vision, for "here's a photo from the site, add it to the job". And a LoRA adapter fine-tuned on past job descriptions.
Should you build this? For sensitive data, offline-first workflows or structured tasks, especially if API costs at scale worry you, yes. This works today. For open-ended chat, knowledge-heavy work, low-end devices, or domain knowledge that changes faster than you can ship models, use a big cloud model. The whole thing took me about twelve hours to build.
It costs nothing a month to run, and it works on a plane. And the customer data never leaves the customer's hand. Hard to argue with. The full post, with all the code and links, is on jared.lynskey.co.nz.



