You’ve invested in an absolute beast: the NVIDIA RTX 4090. You bought it for its raw power, its 24GB of VRAM, and the promise of running large language models locally with blazing speed. Yet, you might find yourself staring at your terminal, wondering why your “blazing speed” sometimes feels more like a gentle simmer, or why a model that should fit is pushing your VRAM to its absolute limit. The frustration is real, the benchmarks you see online often don’t translate directly to your specific setup, and the sheer volume of options – GGUF, AWQ, PagedAttention, continuous batching – can feel like navigating a minefield. You want clarity, performance, and the confidence that you’re squeezing every last drop of potential from your hardware.
This isn’t just about raw numbers; it’s about making informed decisions that impact your development workflow, your project’s responsiveness, and ultimately, your financial investment in top-tier hardware. You’re not alone in seeking that definitive answer for local LLM inference.
For single-user, interactive chat on an RTX 4090, Llama.cpp (GGUF Q4_K_M) offers superior VRAM efficiency and competitive Time to First Token (TTFT). For API serving, multi-user concurrency, or maximizing throughput with larger models via advanced quantization (AWQ/FP8), vLLM’s PagedAttention and continuous batching deliver significantly higher Tokens Per Second (TPS) and better VRAM utilization under load, albeit with a slightly higher baseline VRAM footprint.
Why Your RTX 4090 Might Not Feel as Fast as You Expect for Local LLMs
You’ve got the hardware, but sometimes the software side of local LLM inference feels like a black box. Many practitioners, even experienced ones, fall into the trap of chasing peak Tokens Per Second (TPS) without fully understanding the underlying mechanisms that drive those numbers, or more importantly, how those mechanisms align with their actual use case. The “costly trap” here is assuming a one-size-fits-all solution, or that the fastest engine for one metric is the fastest for your specific needs.
The truth is, the world of local LLM inference is a nuanced matrix. Your RTX 4090, while powerful, has finite VRAM (24GB) and a specific architecture. How an inference engine manages that VRAM, handles the model weights, and processes requests makes all the difference.
The “Costly Trap”: Ignoring Your Workload Profile
Most people focus on raw TPS. “Engine X gets 100 TPS, Engine Y gets 80 TPS, so Engine X is better!” This is often misleading. Are you building:
- A personal, interactive chat assistant? Here, Time to First Token (TTFT) and low latency for a single user are paramount. You want the model to start responding immediately.
- A local API endpoint serving multiple concurrent users or applications? Throughput (total TPS across all requests) and efficient VRAM sharing (KV cache management) become critical. You need to handle many requests simultaneously without degrading performance for any single user.
Llama.cpp and vLLM are optimized for fundamentally different scenarios, even though both can technically serve both roles. Not understanding this distinction is where many engineers waste time, VRAM, and ultimately, performance.
Understanding the Core Differences: Llama.cpp’s GGUF vs. vLLM’s PagedAttention
Let’s pull back the curtain on what makes these two inference powerhouses tick, and why their performance characteristics diverge.
Llama.cpp: The Pragmatic Pioneer
Llama.cpp, built on the ggml library, is renowned for its incredible flexibility and efficiency on consumer hardware. Its core strength lies in its ability to run large models with aggressive quantization, even leveraging the CPU when VRAM is insufficient.
- GGUF Quantization: This is Llama.cpp’s secret sauce. GGUF (GGML Universal Format) models are highly quantized, meaning their weights are stored using fewer bits (e.g., 4-bit, 5-bit, 8-bit) compared to the original 16-bit (FP16) or 8-bit (FP8) formats.
- Q4_K_M: A popular 4-bit quantization that offers an excellent balance between model size, VRAM footprint, and inference quality. It’s often the sweet spot for the RTX 4090.
- Q8_0: A higher-fidelity 8-bit quantization, offering better accuracy but requiring more VRAM and slightly slower inference than Q4_K_M.
- CPU Offloading (
--n-gpu-layers): A killer feature for the 4090. If a model’s weights or KV cache exceed 24GB, Llama.cpp can offload specified layers to the CPU, allowing you to run models that would otherwise be impossible on a single GPU. While slower for offloaded layers, it’s a fantastic fallback. - Simple Batching: Llama.cpp primarily handles requests sequentially or with basic static batching. It’s designed for one request at a time, or a small, fixed number of requests processed together. Its KV cache management is simpler, reserving a contiguous block of VRAM for each active context. This is efficient for single-user scenarios but less so for high concurrency.
vLLM: The Throughput Titan
vLLM is a newer, highly optimized inference engine specifically designed for high-throughput serving of LLMs. Its innovations are geared towards maximizing GPU utilization under concurrent loads.
- PagedAttention: This is vLLM’s game-changer. Unlike traditional KV cache management that reserves a contiguous block of VRAM for each sequence, PagedAttention breaks the KV cache into fixed-size “blocks” (similar to virtual memory paging in operating systems). These blocks can be non-contiguous and shared across different requests. This dramatically reduces memory fragmentation and allows for much more efficient VRAM utilization, especially when handling many concurrent requests with varying sequence lengths.
- Continuous Batching: Instead of waiting for a full batch of requests to accumulate before processing, vLLM continuously processes requests as they arrive. When one request finishes, its allocated GPU resources are immediately freed and reallocated to pending requests. This minimizes idle GPU time and maximizes throughput.
- Advanced Quantization (AWQ, FP8): vLLM supports various advanced quantization techniques like AWQ (Activation-aware Weight Quantization) and FP8 (8-bit floating point). These often offer better performance and VRAM efficiency than FP16 while maintaining high accuracy, especially when combined with PagedAttention. FP8, in particular, leverages the Tensor Cores on the RTX 4090 for extremely fast matrix multiplications.
- Dynamic VRAM Allocation: vLLM dynamically manages VRAM, allocating only what’s needed for active requests and the KV cache, making it highly efficient for multi-user scenarios where KV cache sizes fluctuate.
The Nuance Matrix: Benchmarking Llama.cpp vs. vLLM on RTX 4090
Let’s dive into some empirical metrics. These numbers are illustrative, based on typical performance observed on an RTX 4090, and highlight the core trade-offs. We’ll look at Time to First Token (TTFT), Tokens Per Second (TPS) for single-user (batch size 1) and multi-user (batch size 8), and VRAM footprints.
Test Setup:
- GPU: NVIDIA RTX 4090 (24GB VRAM)
- CPU: High-end consumer CPU (e.g., Intel i9-13900K or AMD Ryzen 9 7950X)
- Models:
- Llama 3.1 8B (Base model, not instruction tuned for raw performance comparison)
- Qwen 2.5 14B (Base model)
- Qwen 2.5 32B (Base model)
- Quantization:
- Llama.cpp: GGUF Q4_K_M, GGUF Q8_0
- vLLM: AWQ (4-bit), FP8 (8-bit)
- Prompt Length: 512 tokens
- Generation Length: 256 tokens
| Engine & Model | Quantization | VRAM Footprint (GB) | TTFT (ms) | TPS (Batch 1) | TPS (Batch 8) |
|---|---|---|---|---|---|
| Llama.cpp – Llama 3.1 8B | GGUF Q4_K_M | ~6.5 GB | ~120 ms | ~180-200 | ~160-180 |
| vLLM – Llama 3.1 8B | AWQ 4-bit | ~7.5 GB | ~150 ms | ~170-190 | ~450-500 |
| Llama.cpp – Qwen 2.5 14B | GGUF Q4_K_M | ~10.5 GB | ~180 ms | ~100-120 | ~90-110 |
| vLLM – Qwen 2.5 14B | FP8 | ~12.5 GB | ~220 ms | ~110-130 | ~280-320 |
| Llama.cpp – Qwen 2.5 32B | GGUF Q4_K_M | ~20.5 GB (GPU) | ~350 ms | ~40-50 | ~35-45 |
| vLLM – Qwen 2.5 32B | AWQ 4-bit | ~22.0 GB | ~400 ms | ~45-55 | ~120-140 |
Key Observations from the Data:
- VRAM Footprint:
- Llama.cpp generally boasts a slightly smaller baseline VRAM footprint for the model weights themselves due to its highly optimized GGUF format and efficient KV cache for single users. This is crucial for fitting larger models like Qwen 2.5 32B onto the 4090.
- vLLM’s initial VRAM usage might be a bit higher due to its PagedAttention block allocation and framework overhead, but its effective VRAM utilization under high concurrency is superior because it avoids fragmentation and shares KV cache blocks.
- For Qwen 2.5 32B, both engines push the 24GB limit. Llama.cpp might require some CPU offloading for the largest models or very long contexts, whereas vLLM might struggle to fit the largest models without extremely aggressive quantization or a slightly larger GPU.
- Time to First Token (TTFT):
- Llama.cpp often has a slight edge in TTFT for single-user requests. Its simpler architecture and direct loading of GGUF models can sometimes result in quicker initial response times, especially for smaller models.
- vLLM’s TTFT is competitive but can be slightly higher due to its more complex setup and the overhead of its continuous batching scheduler. However, this difference is often negligible in real-world interactive scenarios.
- Tokens Per Second (TPS) – Batch 1 (Single User):
- For a single, isolated request, both engines perform remarkably well. Llama.cpp is often neck-and-neck with vLLM, sometimes even slightly outperforming it for smaller models due to its streamlined execution path.
- This is where the “costly trap” lies: if you only benchmark batch size 1, you might conclude Llama.cpp is always better or equal, missing vLLM’s true strength.
- Tokens Per Second (TPS) – Batch 8 (Multi-User/Concurrent):
- This is where vLLM truly shines. Its PagedAttention and continuous batching mechanisms allow it to process multiple requests concurrently with significantly higher aggregate throughput. The GPU is kept busy, minimizing idle cycles.
- Llama.cpp’s performance degrades more noticeably with increasing batch sizes in a concurrent scenario because its KV cache management is less optimized for sharing resources across many active contexts. It’s designed more for sequential processing or small, static batches.
The Bottom Line on Nuance:
- Llama.cpp: Your go-to for maximum model size on limited VRAM (leveraging CPU offloading), and excellent single-user interactive performance where TTFT and low latency are key. It’s simpler to set up and get running.
- vLLM: The undisputed champion for API serving, multi-user applications, and maximizing overall throughput. If you need to handle many requests simultaneously and keep your RTX 4090 saturated, vLLM’s architectural innovations are indispensable. It requires a bit more setup but pays dividends in scalability.
Your Actionable Playbook: Choosing & Deploying Your Local LLM Engine
Now that we understand the nuances, let’s lay out a concrete, step-by-step playbook to help you make the right decision and get your RTX 4090 humming.
Step 1: Define Your Primary Workload & Priorities
Before touching any code, clarify your use case. This is the most critical step.
- Scenario A: Personal AI Assistant / Interactive Chatbot / Local Development Sandbox.
- Priority: Low latency (fast TTFT), maximum model size (even if it means some CPU offloading), ease of use.
- Recommendation: Lean towards Llama.cpp.
- Scenario B: Local API Server / Multi-User Application / High-Throughput Batch Processing.
- Priority: High aggregate TPS, efficient VRAM utilization under concurrency, robust API.
- Recommendation: Lean towards vLLM.
Step 2: Assess Your Model Size & Quantization Strategy
Your RTX 4090 has 24GB. This dictates what models you can run and how.
- For Llama.cpp:
- Start with GGUF Q4_K_M. This offers the best balance of size and quality.
- If you need higher fidelity, try Q5_K_M or Q8_0, but be mindful of VRAM.
- For models larger than ~20-22GB (e.g., 32B models with Q4_K_M, or 14B models with Q8_0), plan to use CPU offloading (
--n-gpu-layers).
- For vLLM:
- Prefer AWQ 4-bit or FP8 if available for your chosen model. These are highly optimized for vLLM’s architecture and the 4090’s Tensor Cores.
- vLLM’s VRAM footprint for the model weights themselves can be slightly larger than Llama.cpp’s GGUF for the same bit-depth, so factor that in. For 32B models, you’ll be pushing the 24GB limit even with AWQ/FP8.
Step 3: Setting Up Llama.cpp for Interactive Use
This is typically the quickest path to getting a model running.
- Install Dependencies: Ensure you have
cmake,build-essential(Linux) or Xcode Command Line Tools (macOS), andCUDA Toolkit(for GPU acceleration on Windows/Linux). - Clone & Build:
“`bash
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
make LLAMA_CUBLAS=1 # For NVIDIA GPU acceleration
“` - Download a GGUF Model: Find your desired model (e.g., Llama 3.1 8B Q4_K_M) on Hugging Face (search for “GGUF” in the files tab). Place the
.gguffile inllama.cpp/models/. - Run Inference:
“`bash
./main -m models/your-model.gguf -p “Tell me a story about a dragon.” -n 256 –temp 0.7 –n-gpu-layers 999
“`-m: Path to your GGUF model.-p: Your prompt.-n: Max tokens to generate.--n-gpu-layers 999: Crucial for the 4090. This attempts to offload all layers to the GPU. Adjust downwards if you encounter VRAM issues with very large models or long contexts.
- For Python Integration: Use
llama-cpp-python.
“`bash
pip install llama-cpp-python[server] # Or [full] for more features
“`
Then you can run a local OpenAI-compatible API server:
“`bash
python3 -m llama_cpp.server –model models/your-model.gguf –n_gpu_layers 999 –host 0.0.0.0 –port 8000
“`
Step 4: Setting Up vLLM for High-Throughput Serving
vLLM requires a bit more preparation but offers significant scalability.
- Install Dependencies: Ensure you have
CUDA ToolkitandPyTorchinstalled with CUDA support. - Install vLLM:
“`bash
pip install vllm
“`
Note: vLLM often requires specific CUDA versions. Check their documentation for compatibility. - Download a Model (Hugging Face): vLLM works directly with standard Hugging Face
transformersmodels (FP16, AWQ, FP8). Download your chosen model (e.g., Llama 3.1 8B AWQ) to a local directory. - Run an API Server:
“`bash
python -m vllm.entrypoints.api_server –model /path/to/your/hf_model –tensor-parallel-size 1 –gpu-memory-utilization 0.9 –max-model-len 2048 –quantization awq –dtype auto –port 8000
“`--model: Path to your Hugging Face model directory.--tensor-parallel-size 1: For a single RTX 4090.--gpu-memory-utilization 0.9: Tells vLLM to use up to 90% of your VRAM for the KV cache and model weights. Adjust carefully.--max-model-len: Maximum context window size.--quantization awq: Specify AWQ quantization if your model supports it. Usefp8for FP8 models.--dtype auto: Let vLLM automatically detect the best data type.
- Client-Side Interaction (Python Example):
“`python
from openai import OpenAI
client = OpenAI(api_key=”EMPTY”, base_url=”http://localhost:8000/v1″)
response = client.chat.completions.create(
model=”your-model-name”, # This can be anything, vLLM ignores it if only one model is loaded
messages=[{“role”: “user”, “content”: “Explain PagedAttention in simple terms.”}],
max_tokens=256,
temperature=0.7,
stream=False
)
print(response.choices[0].message.content)
“`
Step 5: Benchmarking Your Own Setup
The numbers in the table are a guide. Your specific system (CPU, RAM, OS, exact CUDA version) will influence performance.
- For Llama.cpp: Use the built-in benchmarking tools or simply time
mainruns with varying prompt/generation lengths. - For vLLM: Use
ab(ApacheBench) or a custom Python script to send multiple concurrent requests to your vLLM API server to measure aggregate TPS. Monitor VRAM usage withnvidia-smi.
Step 6: Advanced Optimization & Tuning
Once you have a baseline, consider these refinements:
- Quantization: Experiment with different GGUF quantizations (Q4_K_M, Q5_K_M, Q8_0) for Llama.cpp to find the best balance of performance and quality for your specific model. For vLLM, always prioritize AWQ or FP8 if available.
- KV Cache Management:
- Llama.cpp: If running very long contexts, consider reducing
--n-ctxif not needed, or increasing it if you have VRAM to spare. - vLLM: Tune
--gpu-memory-utilizationto balance model size vs. KV cache capacity. A higher value allows more concurrent requests or longer contexts, but risks OOM errors if pushed too far.
- Llama.cpp: If running very long contexts, consider reducing
- Batching (vLLM): While vLLM handles continuous batching automatically, understanding the
max_num_seqsand `max_

