
Table of Contents
By Khimananda Oli | Last reviewed: August 2026
Self-hosting an LLM gives you data sovereignty, predictable latency, and freedom from API rate limits, but success depends entirely on matching your workload to the right hardware and inference stack. Understanding self-hosting an LLM: options, costs, and GPU requirements prevents the most common failure mode: buying expensive GPUs that still cannot fit your target model in memory. Before provisioning infrastructure, review your baseline server hardening practices as outlined in my guide on securing a fresh Ubuntu VPS, because exposing an unhardened inference endpoint is a critical security risk.
What Are the Best Software Options for Self-Hosting an LLM?
Choosing the right inference engine determines your throughput, ease of deployment, and production viability. The ecosystem has matured significantly by 2026, with three dominant options covering distinct use cases.
Ollama for Development and Small Teams
Ollama remains the fastest path from zero to running model for individual developers and small teams. It bundles model downloading, quantization, and serving into a single binary with minimal configuration.
# Install Ollama on Ubuntu 24.04 LTS
curl -fsSL https://ollama.com/install.sh | sh
# Pull and run Llama 3.1 8B Instruct (Q4_K_M quantization)
ollama pull llama3.1:8b-instruct-q4_K_M
# Serve via REST API on port 11434
ollama serve &
# Test inference
curl http://localhost:11434/api/generate -d '{
"model": "llama3.1:8b-instruct-q4_K_M",
"prompt": "Explain Kubernetes pod scheduling",
"stream": false
}' Ollama excels at local development, prototyping, and low-concurrency workloads. However, it lacks advanced batching, continuous batching, and fine-grained resource controls needed for high-throughput production serving.
vLLM for Production Throughput
vLLM uses PagedAttention to manage KV cache memory efficiently, enabling 2–5x higher throughput than naive implementations. It supports continuous batching, OpenAI-compatible APIs, and tensor parallelism across multiple GPUs.
# Install vLLM with CUDA 12.6 support
pip install vllm==0.6.3.post1
# Serve Llama 3.1 70B with tensor parallelism across 4 GPUs
python -m vllm.entrypoints.openai.api_server \
--model meta-llama/Llama-3.1-70B-Instruct \
--tensor-parallel-size 4 \
--gpu-memory-utilization 0.92 \
--max-model-len 8192 \
--port 8000 For teams building customer-facing applications or internal tools with concurrent users, vLLM is the default choice in 2026. Its memory management directly translates to lower cost per token served.
LocalAI and LM Studio for Specific Niches
LocalAI provides broader model format compatibility (including older GGML variants) and easier Docker-based deployment for heterogeneous environments. LM Studio offers a GUI-driven experience ideal for non-engineers evaluating models before committing to infrastructure. Neither matches vLLM's throughput for production, but both fill important gaps in evaluation and legacy support workflows.
How Much VRAM Do You Need for Different LLM Sizes?
VRAM is the single hardest constraint when self-hosting an LLM. Model weights must fit entirely in GPU memory alongside the KV cache, which grows with context length and batch size. Running out of VRAM causes silent fallback to system RAM, destroying performance by 50–100x.
| Model Size | Quantization | Weight Size | Min VRAM (4K ctx) | Recommended GPU | Avg Tokens/sec |
|---|---|---|---|---|---|
| 7B–8B | Q4_K_M | ~4.5 GB | 8 GB | RTX 4060 Ti 16GB | 45–65 |
| 13B–14B | Q4_K_M | ~8 GB | 12 GB | RTX 4070 Ti Super 16GB | 30–45 |
| 30B–34B | Q4_K_M | ~19 GB | 24 GB | RTX 4090 / RTX A5000 | 18–28 |
| 70B | Q4_K_M | ~40 GB | 48 GB | 2× RTX 4090 / A6000 | 12–20 |
| 70B | FP16 | ~140 GB | 160 GB | 2× A100 80GB / H100 | 25–40 |
| 405B | Q4_K_M | ~230 GB | 260 GB | 4× H100 80GB | 8–14 |
Always add 20–30% headroom above weight size for KV cache. A 70B Q4 model at 40GB weights needs ~52GB VRAM for comfortable 8K context serving. If you are containerizing your inference stack, follow the patterns in my Docker containerization guide to ensure GPU passthrough and resource limits are configured correctly.
What Does Self-Hosting an LLM Actually Cost in 2026?
Total cost of ownership extends far beyond GPU sticker price. Budget accurately across four categories to avoid mid-project surprises.
- Hardware acquisition: Consumer RTX 4090 ($1,600–$1,800) suits single-user 30B models. Professional RTX A6000 ($4,200) or A100 ($10,000+) enables multi-user 70B serving. Used enterprise GPUs from decommissioned training clusters offer 30–40% savings with acceptable warranty trade-offs.
- Electricity and cooling: A dual-4090 workstation draws 700–900W under load. At Nepal's average commercial rate of NPR 12/kWh (~$0.09 USD), continuous operation costs ~$55/month. Add 20–30% for cooling in Kathmandu's summer heat; inadequate ventilation throttles GPUs and reduces lifespan.
- Networking and storage: NVMe SSDs (2TB minimum) prevent model loading bottlenecks. For remote teams, factor in dedicated fiber or leased line costs; LLM inference over shared broadband introduces unacceptable latency for interactive use.
- Operational overhead: Monitoring, updates, security patching, and incident response consume 4–8 engineering hours monthly. If your team lacks GPU operations experience, budget for consulting or managed services during the first quarter.
Compare this against API costs: GPT-4o-class performance via OpenAI runs $2.50–$10 per million output tokens. At 10M tokens/month, break-even versus a dual-4090 setup occurs around month 8–12. Below 5M tokens/month, APIs usually win on total cost unless data residency or customization demands self-hosting.
How Do You Optimize Performance and Reduce Costs?
Raw hardware is necessary but insufficient. These optimizations routinely deliver 2–3x effective throughput without additional spend.
- Quantize aggressively: Q4_K_M retains 97–99% of FP16 quality for instruction-tuned models while halving VRAM. Use AWQ or GPTQ for better accuracy at equivalent bit depths. Avoid Q2/Q3 except for experimentation; quality degradation becomes user-visible.
- Tune context length: Every doubling of max context increases KV cache linearly. Default to 4K unless your use case demonstrably requires longer windows. Implement retrieval-augmented generation (RAG) instead of brute-force context expansion.
- Enable speculative decoding: Pair a small draft model (1B–3B) with your primary model. vLLM and SGLang support this natively, yielding 1.5–2.5x speedup on structured outputs like code and JSON with negligible quality loss.
- Right-size concurrency: Continuous batching shines at 8–32 concurrent requests. Below 4 concurrent, Ollama's simpler scheduler often matches vLLM. Profile your actual traffic patterns before over-engineering.
- Monitor and autoscale: Track VRAM utilization, queue depth, and time-to-first-token. Set up alerts as described in my Prometheus and Grafana monitoring guide to catch saturation before users experience degradation.
Making Your Self-Hosted LLM Deployment Production-Ready
Understanding self-hosting an LLM: options, costs, and GPU requirements gets you to a working prototype; operational discipline keeps it running reliably. Start with accurate VRAM sizing using the table above, select Ollama for development or vLLM for production, and budget honestly across hardware, power, and engineering time. Apply quantization and context tuning before purchasing additional GPUs—most teams leave 30–40% performance on the table through suboptimal configuration alone. Treat your inference stack like any other production service: automate deployments with infrastructure-as-code principles from my Terraform practical guide, enforce least-privilege access, and maintain observable metrics from day one. If your team needs hands-on guidance architecting a compliant, cost-efficient private LLM deployment, reach out to discuss your specific requirements.