Termux-LlamaCpp Logo

Termux-LlamaCpp

v1.0.0b1
Foundation
pip / npm
GitHub Founder CV

Advanced Parameters & Security Tuning

Production guidelines for memory sizing, thread scheduling, loopback network security, and cryptographic supply-chain verification.

1. Mobile Context Allocation & Slots (-np 1)

By default on multi-slot servers, context window memory is divided equally across slots (e.g., 256 context / 4 slots = 64 tokens per slot). On single-user mobile devices, this leads to rapid context truncation. Termux-LlamaCpp enforces -np 1 and allocates the entire 2048 token buffer directly to the active session.

Recommended Server Configuration
llama-server \
  -m model.gguf \
  --host 127.0.0.1 \
  --port 18080 \
  -c 2048 \
  -np 1 \
  -t 4 \
  --no-mmap

2. Android Bionic Direct Memory Loading (--no-mmap)

Standard Linux memory-mapping (mmap) on Android flash storage (/data/data/com.termux/files/...) frequently triggers kernel I/O locks, memory thrashing, and process timeouts. The --no-mmap flag instructs the llama.cpp engine to sequentially load model tensors directly into RAM, guaranteeing deterministic cold-start times (~1.8s for 1.92GB models).

3. Ed25519 Cryptographic Manifest Verification

Termux-LlamaCpp implements strict supply-chain security protocols:

Environment Variable Default Value Description
TERMUX_LLAMA_HOME$HOME/.termux-llamaRoot installation directory for binaries and libraries.
TERMUX_LLAMA_MODELS_DIR$HOME/.termux-llama/modelsDefault model download cache directory.
TERMUX_LLAMA_PRESETandroid-arm64-dotprodTarget hardware optimization compiler preset.
TERMUX_LLAMA_FORCE_MMAP0Set to 1 to force mmap (not recommended on Android).