Home › Running an LLM on a phone
Running an LLM on an Android phone: memory is the whole problem
Updated
Onira writes a self-hypnosis session on the phone with a 2-billion-parameter model. Speed turned out to be the easy part.
The short answer A 2B model quantized to 4 bits runs on a mid-range Android phone with about 5 GB of RAM, but only if the weights stay file-backed. Onira uses llama.cpp with the GGUF memory-mapped, generates one 300-500 word block per call while the previous block is narrated, and unloads the model as soon as the last block is written. On a 6 GB Galaxy S20 FE that means about 1.6 GB resident while generating, 0.31 GB of it anonymous, and 111 MB once the model is gone.
The first runtime did not fit
The first version ran stock Gemma 4 E2B through LiteRT-LM on the CPU. That runtime maps the 2.6 GB model file only while loading it, copies the weights into the native heap, then unmaps the file. Anonymous memory cannot be dropped by the kernel, only swapped to zram.
Measured with /proc/<pid>/smaps every two seconds: on a Pixel 7 (7.6 GB RAM), mid generation, about 6 GB PSS, zram 100 % full and kswapd at 72 % CPU. Generation slowed to a crawl and the low-memory killer took the app as soon as it left the foreground. On a 6 GB Galaxy S20 FE it never got that far: killed mid-load, in the foreground, three runs out of three. A warm weight cache changed nothing.
What fixed it: keep the weights file-backed
The current engine is llama.cpp with a Q4_K_M GGUF, over a small JNI bridge. The settings that mattered, each measured on a phone rather than assumed:
- mmap stays on. With it off, the weights become 1.7 GB of memory the kernel can never reclaim, which is the LiteRT situation again.
- The large per-layer embedding table is read lazily: same speed, 676 MB fewer file pages resident, nine times less swap.
- Weight repacking (a second, anonymous copy of the weights laid out for faster ARM kernels) costs 1.13 GB. On the 6 GB phone: 5.0 words/s repacked with 1.29 GB anonymous, 3.8 words/s without it at 0.32 GB. So it is only switched on from 7 GB of RAM; below that a block takes about 40 seconds longer, hidden behind narration.
- Threads: the performance cores minus one. More is slower: 8 threads ran at a third of the speed of 3, and 4 threads gave 8.8 tokens/s against 10.7 for 3. Pinning threads to cores did not help (within 4 %).
- On unload, the allocator is purged explicitly. Without it about 1.2 GB of freed model memory stayed in the process: 1,280 MB resident after closing the model, 74 MB with the purge.
Generate in blocks, narrate while generating
A session is 30 to 40 minutes of narration, several thousand words. Asking a 2B model for all of it in one call takes too long before anything plays, so the script is an ordered list of blocks: a pre-written induction, then deepening, metaphor, suggestions and anchoring, generated one by one, then a pre-written return to alertness.
Because the opening is pre-written, narration starts as soon as the model is loaded. Block N+1 generates while block N is read aloud; on the S20 FE a body block arrives about every 100 seconds, faster than it takes to narrate. A block that fails or takes more than five minutes is replaced by a short pre-written bridge, so the listener is never left in silence.
Each block is a single-turn prompt with the KV cache cleared, not a growing conversation. The model was fine-tuned on single-turn prompts, and in a simulated four-block session the accumulated conversation produced 6.3 duplicated sentences against 0.9 for single-turn. It also keeps the context at 2,048 tokens instead of 10,000.
And the model is closed the moment the last block is written: the remaining half hour of narration, exactly when people lock their phone, runs with nothing loaded.
Budget by duration, not by words
An early version sized the script by word count. Narration speed and the pause between phrases are listener settings, and together they swing the real length by more than three times: some people got 90-minute sessions. The plan is now built from a target duration, converted to words at the listener's own speed and pause setting, minus the exact length of the pre-written parts.
Rules a small model will not follow on its own
Some listeners ask for no breathing cues (tightness in the throat when told to watch their breath) or have limited mobility. Written as prompt rules alone, the model broke them in roughly 10 to 40 % of restricted prompts. The fix was to ban the tokens themselves with a logit bias in the llama.cpp sampler: zero violations on a 120-prompt held-out set. The banned ids belong to the model's vocabulary, so the list is regenerated whenever the model file changes.
Lower sampling temperatures made repetition loops more frequent, not less, so Onira samples like Gemma does: temperature 1.0, top-k 64, top-p 0.95, no repetition penalty.
Safety does not rest on the model either. A deterministic check in English, French and Spanish runs on what the listener types before anything is generated, and a 2B model is treated as a second layer, never the first.
The model is public
The fine-tune, hypnos-e2b-enfres, is Gemma 4 E2B trained on the exact prompts the app sends and pruned to English, French and Spanish (a 58,488-token vocabulary). It is published under Apache-2.0 on Hugging Face as oytaub/hypnos-e2b-enfres-GGUF, with the training and evaluation details in its model card.
Phones that cannot run it, or anyone who prefers, can choose Onira Cloud, where the same kind of session is written on Onira's own server and never stored. On a phone that can, nothing typed or generated leaves the device and the app works in airplane mode.
Try it tonight

The session narrates itself, from induction to a clear return.
Free, no account, no subscription. One-time purchase to remove ads.
Common questions
How much RAM does an on-device LLM need on Android?
For a 2B model at 4-bit quantization with memory-mapped weights, about 5 GB of total RAM is enough in our measurements. Runtimes that copy the weights into the heap need far more: the same class of model was killed by the system on a 6 GB phone.
Why llama.cpp rather than LiteRT-LM?
Mostly memory: llama.cpp can keep the weights file-backed through mmap, which the kernel can drop and reload, while the LiteRT-LM CPU backend copies them into anonymous memory. The single-turn prompting and token bans were also easier to control there.
How fast is it?
On a Galaxy S20 FE, 3.8 to 5.0 words per second depending on weight repacking, and a 300-500 word block about every 100 seconds, which stays ahead of narration.
Can I use the model myself?
Yes. It is on Hugging Face under Apache-2.0, as a GGUF file for llama.cpp.
Private by design
Everything can stay on your phone, if your phone can run the model: Onira runs it on the device, offline, and then the theme you pick, the words you type and the session you receive are never uploaded. If you prefer, Onira Cloud writes the session on Onira's own server instead, only after you agree, and the text is not stored. Either way there is no account.

Not a medical treatment
Onira is a relaxation and self-hypnosis tool. It is not therapy, not medical or psychiatric advice, and not a substitute for professional care or emergency services. If you are in distress or in danger, contact a local crisis line or emergency number.
What a session works on
- AnxietyLoosen the grip of anxious thinking and settle the body.
- SleepWind down a busy mind and let sleep arrive on its own.
- ConfidenceRehearse being the version of yourself you already know how to be.
- StressCome down from a demanding day and recover properly.
- Quitting smokingSupport a decision you have already made, craving by craving.
- FocusSettle a scattered mind before work that needs your attention.
- WeightWork on habits and the relationship with food, not on rules.
- FearFace the flight, the drive or the height with a rehearsed calm.
- MemorySettle into the state where studying actually sticks.
- MotivationStart the thing you have been circling for a week.
- Nervous habitsInterrupt nail biting or jaw clenching before it runs.
- PainEase the bracing and the dread that make pain louder.
- IBSCalm the gut-brain loop that keeps flare-ups going.
- Emotional recoverySettle after something hard, without reliving it.
- AngerTake the heat out of the moment before you react.
- BurnoutRecover a little ground when work has emptied you out.
- Waking at nightFall back asleep after waking at 3 a.m.
Questions people ask
- Falling asleepThe method, step by step, for the nights your mind will not stop.
- Hypnosis vs meditationTwo states, two aims — and which one fits what you want tonight.
- Does it work?What the evidence supports, what it does not, and who it fails.
- Street hypnosisReal, not mind control — and the same mechanism works on yourself.
- Is it safe?Safe for most people, with a short list of real exceptions.
- Learning itWhat to practise, in what order, and how long it really takes.
- Compatible phonesWhich phones write your sessions offline, and what happens on the others.
- AI hypnosis apps comparedOnira, Hypnothera, InTheMoment and Hypnova: free tier, account, offline, languages.
- Onira vs HypnotheraCredits or no credits, an account or none: the differences, checked.
- Onira vs InTheMomentTwo sessions a day or no limit, online or on the phone: the comparison.
- Onira vs HypnovaA large library with credits, or sessions written without counting: the comparison.
