Local AI cheat sheet
The commands and flags you keep forgetting for Ollama, llama.cpp and LocalAI, with copy buttons, plus a GGUF quantization chooser. Print it as one page.
Last checked 2026-11-07. Flags, defaults and model names change between versions: check the project docs (ollama.com, github.com/ggml-org/llama.cpp, localai.io) for the version you installed. Run ollama --help, llama-cli --help to see yours.
Ollama
Everyday commands
ollama pull llama3.2 # download a model ollama run llama3.2 # chat (type /bye to leave) ollama run llama3.2 "Hi" # one question, then exit ollama list # downloaded models ollama show llama3.2 # details of a model ollama ps # models loaded in memory ollama stop llama3.2 # unload from memory ollama rm llama3.2 # delete a model ollama cp llama3.2 my-copy # copy / rename a model ollama serve # start the server by hand
Create a model from a Modelfile
# file named Modelfile FROM llama3.2 PARAMETER temperature 0.3 PARAMETER num_ctx 8192 SYSTEM """You are a concise assistant. Answer in plain language."""
ollama create my-helper -f Modelfile ollama run my-helper
Lower temperature = steadier answers; num_ctx = context window in tokens (more uses more memory).
Environment variables
OLLAMA_HOST | Address the server listens on and the client talks to, e.g. 127.0.0.1:11434 |
OLLAMA_MODELS | Folder where models are stored |
OLLAMA_KEEP_ALIVE | How long a model stays loaded after use, e.g. 10m, -1 for always |
OLLAMA_HOST=127.0.0.1:11500 ollama serve # Linux / macOS OLLAMA_KEEP_ALIVE=30m ollama serve
API on http://localhost:11434
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"prompt": "Why is the sky blue?",
"stream": false
}'
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": [{"role": "user", "content": "Hello"}],
"stream": false
}'
curl http://localhost:11434/api/tags # list local models
llama.cpp
Runs GGUF model files. Binary names: llama-cli (terminal chat), llama-server (HTTP server with OpenAI-style API).
llama-cli -m model.gguf -p "Write a haiku" -n 128
llama-cli -m model.gguf -c 8192 -ngl 99 -t 8
llama-server -m model.gguf --port 8080 -c 8192 -ngl 99
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Hello"}]}'
| Flag | Meaning |
|---|---|
-m | Path to the GGUF model file |
-c | Context size in tokens |
-ngl | Layers to offload to the GPU (a large number = as many as fit) |
-t | CPU threads (try your physical core count) |
-n | Max tokens to generate |
--port | Server port (llama-server) |
Quantize a model
llama-quantize model-f16.gguf model-Q4_K_M.gguf Q4_K_M
Takes a full-precision GGUF and writes a smaller one. Converting original model files to GGUF uses the project's convert_hf_to_gguf.py script.
LocalAI
Self-hosted server, OpenAI-compatible API. Image names and tags change: copy the current command from localai.io.
docker run -p 8080:8080 --name local-ai -ti localai/localai:latest
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"MODEL_NAME","messages":[{"role":"user","content":"Hello"}]}'
Models live in a models folder (mount it into the container); each model can have a YAML file:
name: my-model parameters: model: model.gguf context_size: 4096
The exact YAML keys depend on the backend and version: check the LocalAI docs.
GGUF quantization chooser
Bits per weight are approximate averages; real file sizes differ by model. File size ≈ parameters (billions) × bits ÷ 8, in GB.
| Type | Bits per weight | 8B model size | When to use |
|---|---|---|---|
Q2_K | about 2.6-3.4 | about 3 GB | Last resort when memory is very tight; quality drops visibly |
Q3_K_M | about 3.9 | about 3.9 GB | Squeeze a bigger model into limited memory |
Q4_K_M | about 4.85 | about 4.9 GB | The usual default: best size and quality balance |
Q5_K_M | about 5.7 | about 5.7 GB | A bit more quality if you have the room |
Q6_K | about 6.6 | about 6.6 GB | Close to the original quality |
Q8_0 | about 8.5 | about 8.5 GB | Practically lossless; use when memory is plentiful |
F16 | 16 | about 16 GB | Unquantized reference; mostly for conversion and testing |
Rule of thumb: prefer a larger model at Q4_K_M over a smaller one at Q8_0. Use the model-fit calculator to see what fits your hardware.
Ruggi.Site