Latest AI news

Home  /  Guides  /  Llama 3 vLLM Local Deployment: Step‑by‑Step Guide for RTX 4090 and Other Consumer GPUs

Llama 3 vLLM Local Deployment: Step‑by‑Step Guide for RTX 4090 and Other Consumer GPUs

You can run Llama 3 on a consumer‑grade GPU like an RTX 4090 by installing vLLM 0.5, loading a quantised 8‑B model, configuring GPU‑layers, and hooking a simple vector store for retrieval‑augmented generation, all on a single workstation without any cloud dependency.

By AI Decodes Editorial  ·  Published  ·  Last verified 30 November 2026

Diagram of a workstation running Llama 3 with vLLM on a RTX 4090.
A single GPU workstation can host a full Llama 3 RAG chatbot.

What hardware and software do I need to run Llama 3 with vLLM?

  • GPU: RTX 4090 (24 GB VRAM) or any NVIDIA card with 8 GB+ and CUDA 12.x. The 24 GB memory lets you load the 8‑B model in 4‑bit Q4_K_M format and keep a reasonable KV cache for long contexts.
  • OS: Linux (Ubuntu 22.04 preferred) or Windows Subsystem for Linux. macOS support exists via Metal but the guide focuses on CUDA.
  • Drivers: Latest NVIDIA driver (≥525) and CUDA toolkit 12.x.
  • Python: 3.10+ with a virtual environment.
  • vLLM version: 0.5.0 – the release adds FP8 quantisation, bitsandbytes support, and automatic prefix caching, which improve speed and lower VRAM use on consumer GPUs. See the release notes for details.
  • Model files: Llama 3.1 8B quantised to Q4_K_M (≈4.7 GB) or Q8_0 (≈9 GB) from the Ollama library or Hugging Face. The Q4_K_M version fits comfortably on a RTX 4090 with headroom for KV cache.
  • Optional RAG stack: A lightweight vector store (e.g., FAISS) and a text splitter. The code uses LangChain but any Python wrapper works.

Why these choices?

  • Quantisation reduces weight size, freeing VRAM for the KV cache.
  • vLLM’s bitsandbytes integration lets you apply Q4/K and Q8 quantisation without custom model conversion.
  • Automatic prefix caching cuts the prefilling cost for repeated prompts, which is valuable for a chatbot.

Internal links for context: see /guides/automate-ticket-triage-gpt4o/ for a similar local‑API setup and /how-to/llama-3-langchain-integration/ for LangChain basics.

How do I install vLLM and load Llama 3 on an RTX 4090?

  1. Create a clean Python environment
  2. bash python3 -m venv vllm-env source vllm-env/bin/activate

  1. Upgrade pip and install required wheels
  2. bash pip install --upgrade pip setuptools wheel

  1. Install vLLM 0.5.0 with GPU support
  2. bash pip install "vllm==0.5.0" --extra-index-url https://download.pytorch.org/whl/cu121

The extra index provides the CUDA‑compatible PyTorch build required by vLLM.

  1. Install bitsandbytes for quantisation
  2. bash pip install bitsandbytes

vLLM 0.5 supports bitsandbytes‑based Q4_K_M and Q8_0 formats out of the box.

  1. Download the quantised Llama 3 model
  2. - Using Ollama (fastest for most users): bash curl -fsSL https://ollama.com/install.sh | sh # installs Ollama CLI ollama pull llama3.1:8b-instruct-q4_k_m # 4‑bit model ~4.7 GB

- Or manually from Hugging Face (if you prefer a local folder): bash pip install huggingface_hub huggingface-cli download bartowski/Meta-Llama-3.1-8B-Instruct-GGUF \ --include "*Q4_K_M*" --local-dir./models

  1. Start the vLLM server
  2. bash python -m vllm.entrypoints.openai.api_server \ --model./models/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf \ --gpu-memory-utilization 0.9 \ --swap-space 8 \ --disable-log-requests

- --gpu-memory-utilization 0.9 tells vLLM to keep 90 % of VRAM for the model, leaving the rest for KV cache. - --swap-space 8 enables a modest CPU swap for overflow; on a RTX 4090 you rarely need more than 8 GB. - The server listens on http://localhost:8000/v1/chat/completions, compatible with OpenAI SDKs.

Verification Run a quick curl test: bash curl http://localhost:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"model":"llama3","messages":[{"role":"user","content":"Explain diffusion models in one sentence"}]}'

You should receive a JSON response with a short answer.

Tip: Enable FP8 inference (experimental) for a 1.5× speed boost if your GPU driver supports it – set --quantization fp8 when launching the server.

Flowchart of the retrieval‑augmented generation pipeline.
RAG pipeline: retrieve relevant chunks then generate with Llama 3.

How can I add Retrieval‑Augmented Generation (RAG) to the local Llama 3 chatbot?

RAG consists of three parts: (1) a document store, (2) a retriever that turns a query into relevant chunks, and (3) a generator that receives the retrieved text as part of the prompt.

Step‑by‑step code (Python, works with the vLLM OpenAI endpoint): python import os, json, requests from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.vectorstores import FAISS from langchain.embeddings import HuggingFaceEmbeddings

# 1️⃣ Load your documents (plain txt, pdf, etc.) with open('knowledge/base.txt', 'r', encoding='utf-8') as f: docs = f.read().split('\n\n')

# 2️⃣ Split into manageable chunks (4‑k characters ≈ 1 k tokens) splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200) chunks = splitter.create_documents(docs)

# 3️⃣ Create embeddings – use a lightweight model like "sentence‑transformers/all‑MiniLM-L6-v2" embed = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2') vectorstore = FAISS.from_documents(chunks, embed)

# 4️⃣ Define a simple retriever function def retrieve(query, k=4): results = vectorstore.similarity_search(query, k=k) return "\n".join([doc.page_content for doc in results])

# 5️⃣ Query the local vLLM server, injecting retrieved text def chat(prompt): context = retrieve(prompt) full_prompt = f"Context:\n{context}\n\nUser: {prompt}\nAssistant:" payload = { "model": "llama3", "messages": [{"role": "user", "content": full_prompt}], "max_tokens": 256, "temperature": 0.7, } resp = requests.post( "http://localhost:8000/v1/chat/completions", headers={"Content-Type": "application/json"}, data=json.dumps(payload) ) return resp.json()["choices"][0]["message"]["content"]

print(chat("What are the safety considerations for deploying AI in hospitals?"))

Explanation of key points

  • The retriever runs on CPU; it is lightweight and does not impact GPU VRAM.
  • By prefixing the prompt with Context: you give the generator explicit grounding, which dramatically improves factuality for domain‑specific queries.
  • The same OpenAI‑compatible endpoint can be swapped with any client (e.g., LangChain’s ChatOpenAI wrapper) without code changes.

Performance notes

  • On a RTX 4090 the generation step runs at ~80 t/s for the 8‑B Q4_K_M model (see benchmarks in the Ollama guide and TechCraze performance table).
  • Retrieval typically finishes in <50 ms for a 10 k‑doc collection using FAISS on CPU.
  • If you need larger corpora, consider a disk‑based index like faiss.IndexIVFFlat or ChromaDB; the code changes are minimal.

Related internal guide: see /guides/vertex-ai-matching-engine-rag-tutorial/ for a cloud‑based RAG example that mirrors this local workflow.

How can I optimise vLLM settings for low‑VRAM GPUs like RTX 3060?

Even though the main guide targets a RTX 4090, many developers have 8‑12 GB cards. vLLM 0.5 provides several knobs to make the model fit:

  • Quantisation: Use Q4_K_M (4‑bit) or Q5_K_M (5‑bit) weights. Bitsandbytes integration makes this a one‑line flag (--quantization bitsandbytes).
  • GPU‑layers: Limit the number of layers that stay on‑device with --gpu-layers. For a 12 GB card, --gpu-layers 30 often balances speed and memory.
  • KV‑cache scaling: Reduce the max_model_len in the request payload (e.g., 4 k tokens) to keep the KV cache small.
  • Swap space: Increase --swap-space to 16 GB if you expect occasional longer contexts; vLLM will spill older KV entries to CPU RAM.
  • FP8 (experimental): If your driver supports it, add --quantization fp8. FP8 halves the weight footprint while keeping near‑full precision, giving a 1.5× speed boost.

Sample launch for RTX 3060 (8 GB VRAM) bash python -m vllm.entrypoints.openai.api_server \ --model./models/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf \ --gpu-memory-utilization 0.75 \ --gpu-layers 25 \ --swap-space 12 \ --quantization bitsandbytes

Testing memory usage Run nvidia-smi while the server starts; you should see roughly 6 GB VRAM used, leaving room for the KV cache.

If you hit out‑of‑memory errors

  1. Lower --gpu-layers by 5.
  2. Increase --swap-space.
  3. Switch to a higher‑bit quantisation (Q5_K_M) which needs slightly more VRAM but may reduce compute pressure.

These adjustments let you run Llama 3 locally even on modest consumer GPUs.

What to do if it does not work

  1. Check CUDA and driver versions – run nvidia-smi. The driver must be ≥525 and match the CUDA toolkit used to build PyTorch.
  2. Verify vLLM installation – execute python -c "import vllm; print(vllm.__version__)". If the import fails, reinstall with the correct PyTorch wheel.
  3. Confirm model path – the error FileNotFoundError means the GGUF file is missing or the path is wrong. Re‑download via Ollama (ollama pull …) or Hugging Face.
  4. Review GPU‑memory flags – if you see RuntimeError: CUDA out of memory, reduce --gpu-layers or lower --gpu-memory-utilization.
  5. Consult vLLM debugging guide – the release notes include a troubleshooting section with export VLLM_LOGGING=debug to get detailed logs.
  6. Check port conflicts – ensure no other service is listening on 8000 (or the port you chose). Change the port with --port if needed.
  7. Re‑run a minimal curl test (see Section 2). If the JSON response still fails, open an issue on the vLLM GitHub with the debug logs.

Following these steps aligns with the official documentation and resolves the most common setup problems.

Menus and names can change as products update. If a step looks different, check the product's own help page.

Frequently asked questions

Can I run the 70‑B Llama 3 model on a single RTX 4090?
Only the quantised Q4_K_M version (~43 GB) fits, and it still exceeds the 24 GB VRAM. You would need to offload part of the model to CPU RAM using vLLM’s --swap-space or run the model on a multi‑GPU system.

Do I need an internet connection after the model is downloaded?
No. Once the GGUF file is on disk and vLLM is running, all inference, including RAG, works completely offline.

Is FP8 quantisation stable for production use?
FP8 is marked as experimental in vLLM 0.5. It gives a speed boost but may produce slightly different numerical results; test it on your workload before deploying.

Can I use the same setup on AMD GPUs?
vLLM supports ROCm, but you must install ROCm 6.x and build vLLM from source. The quantisation flags are identical, though performance may differ.