GPU OptimizationAdvanced3 hr7 sections

Multi-GPU Inference With vLLM and llama.cpp

Scale a single model across multiple GPUs with tensor parallelism. Configure vLLM and llama.cpp, fix PCIe bottlenecks, double your VRAM.

MyAIHardware EditorialUpdated May 16, 2026
Multi-GPU Inference With vLLM and llama.cpp

Before you start

  • Working Ubuntu 22.04 + NVIDIA driver install on a multi-slot motherboard
  • Two or more NVIDIA GPUs (same model strongly recommended, mixing causes pain)
  • Python 3.11+ and uv or pip
  • Comfort with the command line and Docker

Required hardware

  • 2× NVIDIA RTX 4090 24GB

    Or 2-4× RTX 3090 for budget builds

    Amazon
  • Corsair Vengeance DDR5 64GB

    Amazon
Step 01

Tensor parallel vs pipeline parallel

There are two ways to split a model across multiple GPUs. Tensor parallelism splits each layer's matrices across cards, every card holds a slice of every layer, and they communicate per-token over PCIe or NVLink. This is the fast option but it demands high inter-GPU bandwidth. Pipeline parallelism puts entire layers on different cards, card 0 owns layers 0-39, card 1 owns 40-79, and a token flows through them sequentially. This needs almost no inter-GPU bandwidth but adds latency per token.

vLLM uses tensor parallel by default. llama.cpp historically used pipeline parallel (because it works fine over PCIe), but its recent versions also support tensor parallel for power users. The right choice depends on your hardware: NVLinked cards = tensor parallel always wins. PCIe-only cards = pipeline can be faster for small batch sizes.

Step 02

Step 1: Confirm the kernel sees all GPUs

Before any framework setup, the OS must see every GPU. Run nvidia-smi and check for two-or-more lines in the device table. If only one card shows up, suspect PCIe slot configuration in BIOS, many consumer boards split the lanes when you populate the second slot, and some boards require manually setting 'x8/x8 mode'. The motherboard manual will tell you.

bash
nvidia-smi --list-gpus
# Should print 2+ lines:
# GPU 0: NVIDIA GeForce RTX 4090 (UUID: GPU-...)
# GPU 1: NVIDIA GeForce RTX 4090 (UUID: GPU-...)

# Detailed topology
nvidia-smi topo -m
# Look for PIX (PCIe switch) or NV# (NVLink) between GPUs.
# PHB (host bridge) is the slowest legit topology, works but slow.
Warning

If `nvidia-smi topo -m` shows SYS (system memory) between your GPUs, the inter-GPU traffic is going through CPU memory. Tensor parallel will be glacial. Fix BIOS PCIe settings first.

Step 03

Step 2: Multi-GPU with Ollama (easiest)

Ollama is the lowest-friction path. With no configuration at all, Ollama 0.5+ detects multiple GPUs and uses pipeline parallelism, layers spread automatically. For most home users this is the only multi-GPU setup they ever need. You only graduate to vLLM if you need batching (multiple simultaneous users) or higher throughput.

bash
# With two 24 GB cards, Ollama will use 48 GB of VRAM total.
# This lets you run models that wouldn't fit on one card.
ollama pull llama3.3:70b
ollama run llama3.3:70b

# Verify both GPUs are in use:
nvidia-smi -l 1   # refresh every second, both GPUs should show load
Step 04

Step 3: Multi-GPU with vLLM (highest throughput)

vLLM is the production-grade inference server. It supports continuous batching, paged attention, and tensor parallelism. Use it when you need throughput, say, serving 20 simultaneous chat sessions. Install via pip in a fresh venv (vLLM has many CUDA dependencies and will fight a polluted Python env).

bash
# Install vLLM
python3.11 -m venv ~/vllm-env
source ~/vllm-env/bin/activate
pip install --upgrade pip
pip install vllm

# Serve Llama 3 70B with tensor parallel across 2 GPUs
vllm serve meta-llama/Llama-3.3-70B-Instruct \
  --tensor-parallel-size 2 \
  --gpu-memory-utilization 0.92 \
  --max-model-len 8192 \
  --quantization awq          # if you pulled an AWQ-quantized variant

# vLLM exposes an OpenAI-compatible API on http://localhost:8000

vLLM is OpenAI-API-compatible, so any OpenAI SDK client can hit it.

Step 05

Step 4: Validate tensor parallel actually works

The gotcha with tensor parallel is that it silently downgrades to pipeline parallel if NCCL can't establish a fast peer connection between GPUs. Test peer-to-peer access, if it's not enabled, your tensor-parallel build will run 10x slower than expected.

python
# Check peer-to-peer access
import torch
print("CUDA devices:", torch.cuda.device_count())
for i in range(torch.cuda.device_count()):
    for j in range(torch.cuda.device_count()):
        if i != j:
            can = torch.cuda.can_device_access_peer(i, j)
            print(f"  GPU {i} -> GPU {j}: peer access = {can}")

# If any pair reports False on consumer hardware, you're stuck with PCIe.
# Nothing you can do about it, NVIDIA artificially disables P2P on RTX.
Step 07

Step 6: Quad-GPU and beyond

Going from 2 to 4 GPUs needs a workstation board with enough PCIe lanes (Threadripper Pro or EPYC). Consumer boards split lanes the more cards you add, and below x4 per card tensor parallel suffers. Power: a quad-4090 box pulls 1800W transient under load, you need a 2000W PSU or two PSUs ganged. At that point you have an underpowered datacenter rack, and renting an H100 hour for $2 starts to look smart for occasional training jobs.

Tags

#multi-gpu#vllm#tensor-parallel#nvlink#advanced

Stuck? Share your build?

Hundreds of homelabbers are working through these same tutorials in our community. Drop your config, ask the hard question, or show off what you built.

Join the discussion

Stay Ahead of the AI Curve

Get weekly AI hardware news, benchmark updates, and deals in your inbox. Founding-subscriber list, be one of the first.

✓ No spam✓ Weekly digest✓ Unsubscribe anytime