HB
MLOps & GPU Serving
Freelance client

Self-Hosted LLM Inference on Bare-Metal GPUs

NVIDIA A100 · llama.cpp · GGUF · FastAPI

Hasan Butt
By Hasan ButtPublished: May 2025
82%Reduction in listed monthly charges; hardware and labor excluded
01

The Challenge

The legal research workload needed a review of API spending and data handling. The available servers had to fit the model, runtime allocations, and KV cache. Driver updates also needed a recovery procedure before the servers could be operated reliably.

02

The Approach

Used GGUF Q4_K_M quantization with llama.cpp, a FastAPI gateway, and GPU monitoring. Ansible automation handled driver setup and validation. The serving configuration needed enough memory for concurrent requests as well as model weights.

03

System Architecture

Loading architecture diagram...
04

Interactive Demo

Walk through the system design and data flow for this project step by step.

Interactive Topology HUD

Click any component node in the topology cluster to inspect SRE specifications and telemetry.

NVLINK MESH (96 GB/s)Stream QueueRound RobinNginx SSL & LimitsPUBLIC EDGE PROXYFastAPI GatewayAPI INGRESS ROUTERServer 1 (2x A100)PRIMARY GPU WORKERServer 2 (2x A100)SECONDARY GPU WORKERAnsible PlaybooksPROVISIONING IACPrometheus + DCGMHARDWARE METRICSGrafana DashboardsMLOPS HUD CONSOLE
Node Telemetry HUD
gateway status
FastAPI GatewayAPI INGRESS ROUTER
Metric 01p99 Latency180ms
Metric 02Concurrency48 active streams
Metric 03Load BalancingRound Robin
Telemetry Graph FeedLive
CONFIG SPECIFICATION DETAILS

A custom Python FastAPI gateway coordinates incoming client requests, manages model version hot-swaps, and balances loads across GPU workers.

BenefitEnsures low-latency streaming via Server-Sent Events (SSE) and handles up to 48 concurrent requests before queueing.
Risk Without ThisWithout queue scheduling, concurrent load spikes would cause out-of-memory errors on individual GPU workers.

05

Overview

Built a self-hosted Llama 3.1 70B serving platform on four A100 GPUs across two servers. A FastAPI gateway routes requests to llama.cpp workers using quantized GGUF models.

06

Business Impact

The project records monthly API charges of $18,000 and colocation and power charges of $3,240 after the move, an eighty-two percent reduction in those listed charges. Hardware purchase and operating effort are not included in that comparison. The raw load-test results are not published here.

07

Technical Highlights

  • llama.cpp compiled from source with CUDA 12.2, cuBLAS, and flash attention enabled for maximum GPU throughput
  • GGUF Q4_K_M quantization reducing Llama 3.1 70B from 140GB to 40GB with 97% quality retention on MMLU
  • Tensor parallelism across 4 NVIDIA A100 80GB GPUs using llama.cpp native multi-GPU support with NVLink
  • Continuous batching handling 48 concurrent requests with dynamic batch scheduling based on sequence length
  • Custom FastAPI gateway with health-check-based routing across 2 bare metal servers, graceful draining on GPU worker restart
  • NVIDIA driver and CUDA toolkit upgrade automation with Ansible playbooks, pre-upgrade GPU health checks, and automatic rollback on failure
  • Prometheus metrics exporter for GPU temperature, memory utilization, inference latency histogram, and tokens per second
  • Nginx reverse proxy with rate limiting (60 requests per minute per API key), request buffering, and SSL termination
  • Model hot-swap capability: load a new GGUF model file without restarting the inference server or dropping active connections
  • Automated benchmarking pipeline that runs MMLU and HumanEval after every quantization to catch quality regressions before deployment
08

Frequently Asked Questions

Q: What was the biggest challenge in this self-hosted GPU setup?

Driver upgrades needed a tested recovery procedure. Ansible automation handled setup and validation; the correct driver depends on the CUDA and runtime versions being deployed.

Q: Why choose GGUF Q4_K_M quantization?

Q4_K_M reduced the weight footprint and left more space for runtime allocations and the KV cache. Model quality and concurrency still need evaluation on the intended workload.

Q: What was the concrete financial ROI?

The listed monthly charges changed from $18,000 for API usage to $3,240 for colocation and power. This is an 82% reduction in those charges, excluding hardware purchase and operating effort.

Want results like this for your infrastructure?

I specialize in taking complex AI pipelines and cloud setups from concept to high-availability production. Let's discuss how to optimize your workloads, secure your environment, and reduce cloud costs.