Fly.ioTutorial
Scaling Large Language Models to zero with Ollama
Summary
Running GPU nodes for language-model inference can be costly because they often sit idle between requests, so this guide configures Ollama on a Fly.io Machine that scales to zero when idle. Ollama is described as a wrapper around llama.cpp, enabling self-hosted models with GPU acceleration, while about 70 lines of Go add authentication to protect the endpoint from unauthorized use. Deployment uses an A100-40GB GPU, a private Flycast address, automatic start and stop settings, and a 100GB persistent volume mounted at /root/.ollama so downloaded models survive stopped Machines. A stopped Machine no longer incurs GPU charges, but scaling to zero suspends it on the same host and may fail to wake during capacity issues. The setup supports CLI and API requests, WireGuard access, custom Modelfiles, and JSON-mode function-calling workflows.
Context
GPU nodes are expensive and commonly remain idle between uses. Ollama does not provide authentication by default, creating a risk that unauthorised internet users could consume GPU time and incur costs. Scaling to zero reduces charges when the Machine is not running, while local model storage avoids repeated downloads after shutdown.
Approach / What changed
The deployment runs the ollama/ollama image on a Fly.io Machine with an A100-40GB GPU, a private Flycast address, automatic start and stop, and zero minimum running Machines. A 100GB volume stores models at /root/.ollama. A small Go shim adds authentication, and clients can access the service through the CLI, API, or WireGuard.
Takeaways
Fly.io scaling to zero stops the Machine on its existing host rather than moving it to new capacity; a stopped Machine may be unable to wake if there is a capacity issue.
A persistent volume mounted at /root/.ollama keeps downloaded Ollama models available across Machine stops, avoiding a re-download on every startup.
Ollama's JSON mode can support function-calling workflows, but handling cases where no function should be called requires LangChain or manual iteration.
Source and freshness
- Source
- fly.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.