Local AI
Local AI
Advanced
Run Ollama Reliably
Keep models loaded, monitor resources, and deploy on a server
60 of 66
Keep models in memory
By default, Ollama unloads a model after a few minutes of inactivity. Keep it loaded with:
export OLLAMA_KEEP_ALIVE=24h
Or set it per request:
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"prompt": "Hello",
"keep_alive": "24h"
}'
Set GPU layers and context
In a Modelfile or API call:
PARAMETER num_ctx 8192 PARAMETER num_gpu 35
Match num_gpu to your GPU's layer capacity.
Run as a service
macOS (launchd)
Ollama already runs as a launch agent. To customize:
~/Library/LaunchAgents/com.ollama.olama.plist
Linux (systemd)
Create
/etc/systemd/system/ollama.service
[Unit] Description=Ollama After=network.target [Service] ExecStart=/usr/local/bin/ollama serve Environment="OLLAMA_KEEP_ALIVE=24h" Restart=always [Install] WantedBy=default.target
Then:
sudo systemctl enable --now ollama
Docker Compose for a small team
services:
ollama:
image: ollama/ollama
ports:
- "11434:11434"
volumes:
- ollama:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
volumes:
ollama:
Monitor
ollama ps nvidia-smi
Watch memory usage and unload models if you run multiple services on the same GPU.