Local Models with llama.cpp
pig supports the llama.cpp router server. The router discovers multiple GGUF models and loads or unloads them on demand.
Install llama.cpp
#- Mac and Windows: install the Llama app, a small desktop app that sits in the system tray.
- Linux, or the command line only: one command:
curl -LsSf https://llama.app/install.sh | sh
Verify the installation:
llama --version
See the official install page for other installation methods, including package managers and building from source.
Start the router
#If you installed the desktop app, llama serve is already running: the model list is at localhost:9931.
Otherwise start llama serve without --model, -m, or -hf. Passing a model starts single-model mode instead of router mode. See the llama.cpp server guide for router configuration.
There are two ways to load models:
- Automatic loading, the default: a model loads on its first request.
- Manual loading: add
--no-models-autoload, then load models with/llamabefore selecting them.
For automatic loading:
llama serve
The defaults are reasonable in most cases. Some options for advanced use:
-ngl alloffloads all layers to the GPU. Omit it to use automatic GPU offloading.-c 32768sets the context size in tokens. Use-c 0for the model's full context window, which may require substantially more memory. Context is shared across parallel server slots.--models-dir ~/modelsdiscovers local GGUF files in a directory of your own.--models-max 0controls how many models can be loaded at the same time.
By default, models are stored in the standard Hugging Face cache directory. Multimodal and multi-shard models work out of the box:
~/.cache/huggingface/hub/
├── models--google--gemma-4-E2B-it-qat-q4_0-gguf/
│ └── snapshots/<rev>/
│ ├── gemma-4-E2B_q4_0-it.gguf
│ └── gemma-4-E2B-it-mmproj.gguf
└── models--ggml-org--Inkling-2-Mini-GGUF/
└── snapshots/<rev>/Inkling-2-Mini-IQ4_NL.gguf
The router also supports preset files via --models-preset, as described in the server guide.
Configure pig
#Start pig and configure the provider:
/login llama.cpp
Enter the router URL and optional API key. The default URL is http://127.0.0.1:9931. pig refreshes the model list once the connection is stored, then points you to /model.
Use /model to select a model for the current session. If you turned automatic loading off, load it with /llama first.
Environment variables can configure the same values without /login:
export LLAMA_BASE_URL=http://127.0.0.1:9931
export LLAMA_API_KEY=optional-secret
pig
If the server uses an API key, start llama serve with the matching --api-key value. Keep --host 127.0.0.1 for local-only access.
Manage models
#Run:
/llama
- Select an unloaded model to load it.
- Select a loaded model to unload it.
- Select Download model…, search Hugging Face, then choose a repository and quantization. Exact
owner/repository[:quant]values also work. - Press Escape during a load or download to confirm cancellation.
Hugging Face search uses HF_TOKEN when set, then checks $HF_TOKEN_PATH, $HF_HOME/token, $XDG_CACHE_HOME/huggingface/token, and ~/.cache/huggingface/token. Search also works without authentication, subject to lower rate limits. pig warns before downloading gated repositories and links to their access page. The llama.cpp server performs the download, so its process must also have HF_TOKEN when the selected repository requires access.
If other models are loaded, pig asks whether to unload them first or keep them loaded. pig does not silently unload models and never deletes model files. The router may be shared with other clients, so /llama always displays the router's current state.
Loaded and sleeping models appear in /model. Sleeping models wake automatically when selected. With router autoload enabled, unloaded models (presets, the Hugging Face cache and --models-dir) also appear and load on their first request; until then pig uses the context the model was trained with. With --no-models-autoload, load a model through /llama before selecting it.
If the router disconnects, /llama shows Retry and Close. Retry reconnects and refreshes model state without replaying the interrupted operation.
Classification
#Every model listed for chat is also listed as a classifier model with the same ID and the llama-cpp-classify API. Classifier models answer typed choice, bool, and score questions about JSON state, like TypeSafe's Jev models. The model reaches them from codemode scripts, and extensions through $ctx->modelRegistry->classify(); see Classifier models.
The model does not generate an answer. Each question becomes one chat prompt: the state, every question of the request, the state again, and then the question with its answers under single-token labels. Labels are letters for a choice (up to 62 options), Yes/No for a bool, and digits for a score (up to 10 levels). The second copy of the state is read with the questions in view, which improved accuracy on JevBench with small models. pig reads the probabilities of the labels as the next token and normalizes them. A choice returns every option's probability and a confidence of (n * peak - 1) / (n - 1); a score returns the expected level.
- Raw label probabilities are usually overconfident. The per-request
temperatureoption divides the label logits before normalizing; values above 1 soften the distribution. It changes no answer. - Questions run one after another. Everything before the final question is the same for all questions of a request, so the server's prompt cache evaluates it once. The state appears twice, so it needs twice its size in context.
- Small models may follow instructions written inside the state. The prompt tells the model to judge the state as data, but that is not a guarantee.
- Hybrid models such as Qwen3.5 cannot rewind a partially cached prompt without context checkpoints. If each question reprocesses the whole state, start the router with
--ctx-checkpoints 32 --checkpoint-min-step 0.
Troubleshooting
#Check that the router is reachable:
curl http://127.0.0.1:9931/health
curl http://127.0.0.1:9931/models
- No models in
/llama: Check--models-dir, the directory layout, and restart the router. - Model missing from
/modelwith--no-models-autoload: Load it with/llamafirst. - Load fails or uses too much memory: Lower
-cor unload another model. - Server is not in router mode: Start it without
--model,-m, or-hf.
To remove the llama.cpp provider and /llama, disable llama.cpp under Built-in in pig config, or set "extensions": ["-builtin:llama.cpp"] in settings.