Originally published on Aivlyn, where we test local AI on real hardware.
Cloud inference bills scale with your success. Every new user, every longer prompt, and every retry lands on the same meter, and that meter runs between $2 and $20 per million tokens on frontier APIs. Meanwhile, a used RTX 4090 generates text from a 27-billion-parameter open model at around 47 tokens per second, fully offline, with zero marginal cost and no data leaving your network. This guide walks through a production-grade Ollama deployment on real hardware: the VRAM math that decides which model fits, the quantization trade-offs that actually matter, an OpenAI-compatible API your existing code can talk to, and the exact point where vLLM takes over.
Key Architectural Takeaways
- Bandwidth Is the Speed Limit: Generation speed at batch size one is memory-bandwidth bound. Expected tokens per second roughly equals memory bandwidth divided by active model weights, and real engines achieve 65 to 78 percent of that ceiling.
- VRAM Is a Formula, Not a Guess: Total memory equals model weights plus KV cache for your context length plus roughly 0.8 GB of compute buffer. A Llama 3.3 70B at Q4_K_M needs about 47 GB at 8K context, so no single 24 GB card runs it at full offload.
- Ollama Speaks OpenAI: The local server exposes /v1/chat/completions with streaming, JSON mode, vision, and tool calling, so existing OpenAI client code works by changing two lines.
- Ollama Is Single-User First: At 32 concurrent requests, vLLM served about 1,730 tokens per second in November 2026 tests where a llama.cpp-class backend plateaued near 680. Route multi-tenant workloads to vLLM.
The Cost Argument: What Self-Hosting Actually Saves in 2026
Self-hosting an open-weight model replaces a per-token API bill with a fixed hardware cost. Claude Opus 5.5 currently bills at $4 per million input tokens and $20 per million output tokens, while Sonnet 5.5 sits at $2 and $10. A used RTX 4090 with 24 GB of VRAM, the workhorse of local inference, costs roughly $3,400 on the secondary market as of November 2026.
Do the arithmetic on a real workload. An agentic pipeline that summarizes support tickets might push 3 million input tokens and 1 million output tokens per day. On Sonnet-class pricing that is about $16 daily, or close to $480 a month. The used 4090 pays for itself in around seven months, and it keeps working after that for the price of electricity. Renting the same card on Vast.ai starts near $0.27 an hour if you want to test the workflow before buying hardware.
Cost is only half the argument. The other half is data gravity. Customer records, internal documents, and proprietary code never touch a third-party server, which settles most compliance reviews before they start. For teams in regulated industries, that property alone justifies the setup effort.
New RTX 4090 listings now sit near $4,899 because NVIDIA's current line is the 50 series and remaining 40-series stock is scarce. The used market and hourly rental are where the value lives; just verify the card's memory health with a 30-minute stress test before you put it into service.
The Hardware Math: VRAM, Bandwidth, and Quantization
The memory a model needs is the sum of three parts: the quantized weights on disk, the KV cache that grows with context length, and a compute buffer of roughly 0.8 GB. Generation speed is then set by memory bandwidth, not compute. Divide your card's bandwidth by the active weight size and you get the theoretical ceiling; Ollama and llama.cpp typically land at 65 to 78 percent of it.
Quantization is the lever that makes this practical. A 4-bit Q4_K_M quant cuts a model's memory footprint by about 70 percent versus FP16, and measured quality on standard benchmarks stays within roughly one percentage point of the full-precision weights. Dropping below 4 bits, into 3-bit and 2-bit territory, is where perplexity climbs and instruction following starts to wobble. Treat Q4_K_M or the newer Q4_K_XL as the default for dense models, and MXFP4 for Mixture-of-Experts releases like OpenAI's gpt-oss family, which ships with it natively.
MoE models break the naive size rule in your favor. gpt-oss-120b carries 117 billion total parameters but activates only 5.1 billion per token, so it generates at 47 tokens per second on a 128 GB M4 Max MacBook, a machine with 546 GB/s of unified memory bandwidth. Dense models of similar total size crawl on the same hardware.
Measured Model and Hardware Matrix (November 2026)
| Model | Quantization | Memory Needed | Hardware | Generation Speed |
|---|---|---|---|---|
| Qwen2.5 7B | 4-bit GGUF | ~5.5 GB | RTX 4090 (1,008 GB/s) | ~159 tok/s |
| Gemma 4 26B (4B active MoE) | 4-bit GGUF | ~16 GB | RTX 4090 | ~150 tok/s |
| Qwen3.8 27B | Q4_K_XL | ~17 GiB | RTX 4090 | ~47 tok/s |
| gpt-oss-120b | MXFP4 (native) | ~65 GB | M4 Max 128 GB (546 GB/s) | ~47 tok/s |
| Llama 3.3 70B | Q4_K_M | ~47 GB @ 8K ctx | M4 Max 128 GB | ~19 tok/s (Ollama), ~25 tok/s (MLX) |
| Llama 3.3 70B | Q4_K_M (partial offload) | 23.4 GB spilled to CPU | RTX 4090 + DDR5 | ~14 tok/s |
Two lessons hide in that table. First, partial CPU offload is a trap: spilling half of a 70B model onto system RAM drags the RTX 4090 down to 14 tokens per second, slower than a Mac running the same weights entirely in unified memory. Second, MoE models like Gemma 4 and gpt-oss punch far above their memory class because only the active experts cross the bus per token.
Installing Ollama for Real Workloads
Ollama is a single binary that wraps llama.cpp and, on Apple silicon, MLX, serving models over a local HTTP API on port 11434. Installation on Linux is one command, and current releases (v0.40.x as of November 2026) ship with tool calling, structured outputs, and thinking control built in. The defaults, however, are tuned for a quick demo, not a deployment.
# Linux install (macOS and Windows use the desktop app) curl -fsSL https://ollama.com/install.sh | sh # Pull a workhorse model: gpt-oss-20b runs in 16 GB of memory ollama pull gpt-oss:20b # Serve with a production-sized context window OLLAMA_CONTEXT_LENGTH=32768 ollama serve # Verify what actually loaded and where it runs ollama ps # NAME ID SIZE PROCESSOR CONTEXT UNTIL # gpt-oss:20b ... 14 GB 100% GPU 32768 4 minutes from now The context default is the failure case that bites hardest. Ollama sizes context by detected VRAM: 4K tokens below 24 GiB, 32K between 24 and 48 GiB, and 256K at 48 GiB and above. Agentic workflows and coding assistants routinely send 20K-token prompts, so a 4K default silently truncates them. The model does not error; it just forgets the beginning of the conversation and hallucinates about the rest. Set OLLAMA_CONTEXT_LENGTH explicitly, or pass num_ctx per request, and size it to the workload. For agents and coding tools, 64K is the practical floor.
The second silent failure is offload. If the PROCESSOR column in ollama ps shows anything other than 100% GPU, some layers landed on the CPU and your throughput dropped by a factor of five to ten. The fix is a smaller quant, a shorter context, or a smaller model, in that order.
Parallel requests multiply context memory. OLLAMA_NUM_PARALLEL=4 with a 32K context allocates KV cache for 128K tokens. If you see 503 overloaded errors, that is the OLLAMA_MAX_QUEUE (default 512) filling up, not a crash. Raise the queue or add parallelism deliberately, and budget the VRAM for it.
One API, Every Client: The OpenAI-Compatible Endpoint
Ollama exposes an OpenAI-compatible API at http://localhost:11434/v1, covering chat completions, streaming, JSON mode, vision inputs, seed-based reproducibility, and function calling. Any application written against the OpenAI SDK, from a LangChain pipeline to an n8n workflow, can switch to a local model by changing the base URL and nothing else of consequence.
from openai import OpenAI client = OpenAI( base_url="http://localhost:11434/v1", api_key="ollama", # required by the SDK, ignored by Ollama ) resp = client.chat.completions.create( model="gpt-oss:20b", messages=[{"role": "user", "content": "Classify this ticket: refund demanded, order late twice."}], response_format={"type": "json_object"}, temperature=0, seed=42, ) print(resp.choices[0].message.content) Three production details matter here. First, temperature 0 plus a fixed seed gives you reproducible outputs, which is how you build regression tests for prompts. Second, JSON mode plus tool calling turns a 20B local model into a reliable extraction and classification worker; schema adherence in the 94 to 98 percent range is typical for 14B-class models and up. Third, reasoning models accept reasoning_effort, so you can dial thinking down for latency-sensitive paths and up for hard problems, per request.
Know the boundary of the compatibility layer. Logprobs, tool_choice forcing, and logit_bias are not supported, so code that depends on them needs the native /api/chat endpoint or a rethink. And if you expose port 11434 beyond localhost, put it behind a reverse proxy with authentication, because Ollama itself performs no access control on the local API.
Where Ollama Stops: Concurrency and the vLLM Handoff
Ollama is engineered for one user or a handful of sequential requests. Its default parallelism is one request per model instance on CUDA backends, and requests beyond that queue. vLLM, built around PagedAttention and continuous batching, exists for the opposite case: many users hitting one model at once. Independent benchmarks from November 2026 make the split concrete.
| Serving Stack | Single Request (tok/s) | 32 Concurrent Requests (tok/s) | Best Fit |
|---|---|---|---|
| Ollama 0.40.x (llama.cpp) | 120.6 | ~680 (with manual slot tuning) | Personal tools, dev machines, single-agent pipelines |
| vLLM 0.33 (AWQ) | 115.3 | ~1,730 | Multi-user APIs, SaaS backends, team servers |
| LM Studio (headless) | 109.7 | Limited to 4 slots in testing | Desktop experimentation and model evaluation |
| Hosted frontier API | Varies by load | Elastic, billed per token | Burst workloads, frontier-quality reasoning |
The tests used a 9B model on an RTX 3090 with identical prompts and temperatures, and the single-request numbers show something important: at batch size one, every serious runtime sits within about 10 percent of each other, because they share the same memory-bandwidth ceiling. You do not pick vLLM for speed on a single stream. You pick it when the second, eighth, and thirty-second user shows up, where its continuous batching roughly triples aggregate throughput over a llama.cpp-class server.
The pragmatic architecture is a hybrid. Run Ollama on the workstation or the small office server for development, agents, and automations. When a service graduates to real concurrent traffic, migrate that one model to vLLM behind the same OpenAI-compatible interface, and keep frontier APIs in the routing layer for the hardest queries. The client code never notices any of the three moves.
Frequently Asked Technical Questions
How much VRAM do I need to run a local LLM?
Add the quantized weight size, the KV cache for your context length, and about 0.8 GB of buffer. In practice, 16 GB runs 7B dense models or MoE models like gpt-oss-20b, 24 GB covers dense models up to roughly 32B at 8K context, and 70B-class models need 48 GB or more. Does 4-bit quantization hurt model quality?
At Q4_K_M, measured benchmark scores typically land within about one percentage point of full precision, and most users cannot tell the difference in real tasks. Quality degrades noticeably below 4 bits. For extraction and classification workloads, quantized 14B-class models hold 94 to 98 percent schema adherence. Can Ollama handle tool calling and JSON output for agents?
Yes. Both the native /api/chat endpoint and the OpenAI-compatible /v1/chat/completions endpoint support function calling, JSON mode, and seed-based reproducibility. Reasoning models also accept a reasoning_effort parameter per request. Logprobs and forced tool_choice are the main unsupported fields. When should I move from Ollama to vLLM?
Switch when you serve more than a few concurrent users. Single-request speed is nearly identical across runtimes, but at 32 simultaneous requests vLLM's continuous batching delivered about 1,730 tokens per second in November 2026 tests, versus roughly 680 for a llama.cpp-class backend on the same GPU. 