Of course. Running two GPUs in a PCIe 5.0 x16 and a PCIe 4.0 x4 slot is an excellent way to expand your AI capabilities.
Here’s a detailed breakdown of how it works, the performance implications, and how to set it up.
The Short Answer: Yes, It Works, But With a Catch
You can absolutely run two GPUs for LLMs in this configuration. The key is understanding that the PCIe 4.0 x4 slot will be a performance bottleneck, but only for specific tasks.
- PCIe 5.0 x16 Bandwidth: ~64 GB/s
- PCIe 4.0 x4 Bandwidth: ~8 GB/s
The ~8x speed difference is significant. How much it affects you depends entirely on how you use the two GPUs.
How to Use Two GPUs: Two Main Strategies
Strategy 1: Model Splitting (One Giant Model)
This is used when a single LLM is too large to fit into the VRAM of one GPU. The model's layers are split across both GPUs.
- How it Works: The software (e.g.,
transformers with device_map="auto", llama.cpp) loads some layers onto GPU 0 (your x16 card) and the rest onto GPU 1 (your x4 card).
- The Performance Impact: This is where the PCIe x4 bottleneck is most severe. For every single token generated, data (activations) must be passed back and forth between the two GPUs. This communication happens over the motherboard's PCIe bus, and the entire process is limited by the slowest link—the 8 GB/s of the x4 slot.
- Result: Inference will be noticeably slower than if the entire model fit on the primary GPU. It works, but it's not fast.
Strategy 2: Parallel Inference (Two Separate Models/Tasks)
This is where you run two completely independent models or tasks, one on each GPU.
- How it Works:
- Task A (e.g., LLaVA vision model) runs exclusively on GPU 0.
- Task B (e.g., Mistral 7B for text generation) runs exclusively on GPU 1.
- The Performance Impact: The PCIe bottleneck is almost irrelevant here. The only slowdown is during the initial model loading from your SSD/RAM to the VRAM of the GPU in the x4 slot. Once the model is loaded, all the computation happens inside that GPU. The slow bus isn't used during inference.
- Result: You get the full inference speed of each individual GPU for its respective task. This is the most efficient use case for your hardware setup.
Step-by-Step Setup Guide
1. Hardware Installation
- Primary GPU: Install your most powerful GPU (e.g., the 4060 Ti 16GB) in the PCIe 5.0 x16 slot. This will be
GPU 0.
- Secondary GPU: Install your second GPU in the PCIe 4.0 x4 slot. This will be
GPU 1.
- Power: Ensure your power supply (PSU) has enough wattage and separate power connectors for both cards.
- Cooling: Make sure your case has adequate airflow. Two GPUs will generate more heat.
2. Software & Driver Installation
-
NVIDIA Drivers: Install the latest NVIDIA drivers. The driver will automatically detect both GPUs.
-
Verify: Open a terminal and run nvidia-smi. You should see both GPUs listed as GPU 0 and GPU 1.
$ nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.60.13 Driver Version: 525.60.13 CUDA Version: 12.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... On | 00000000:01:00.0 Off | N/A |
| 0% 30C P8 15W / 160W | 10MiB / 16384MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 NVIDIA GeForce ... On | 00000000:03:00.0 Off | N/A |
| 0% 32C P8 12W / 115W | 10MiB / 8192MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
3. Running Your Models
Here’s how to implement the two strategies:
For Model Splitting (Example with transformers)
The accelerate library makes this easy. device_map="auto" will automatically split the model, but it's better to create a manual map to control the split.
from transformers import AutoModelForCausalLM
import torch
# Put more layers on the faster GPU (GPU 0)
# Example: A 70B model with 80 layers
# 60 layers on GPU 0, 20 layers on GPU 1
# Adjust the numbers based on your GPUs' VRAM
device_map = {
# First 60 layers on GPU 0
**{f"model.layers.{i}": 0 for i in range(60)},
# Last 20 layers on GPU 1
**{f"model.layers.{i}": 1 for i in range(60, 80)},
# Other components
"model.embed_tokens": 0,
"model.norm": 1,
"lm_head": 1,
}
# Load the model with the custom device map
model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-2-70b-chat-hf",
device_map=device_map,
torch_dtype=torch.float16,
# Add quantization to save more memory if needed
# load_in_4bit=True
)
print("Model loaded across two GPUs. Ready for inference.")
# Now you can run inference as usual, but it will be slow.
For Parallel Inference (Recommended Method)
This is done by setting the CUDA_VISIBLE_DEVICES environment variable before running your Python script. This tells the script which GPU(s) it is allowed to see.
Terminal 1: Run the LLaVA Vision Model on GPU 0
# This script will only see GPU 0
export CUDA_VISIBLE_DEVICES=0
python run_llava.py
On Windows, use set CUDA_VISIBLE_DEVICES=0 and then run the python command in the same terminal.
Terminal 2: Run the Mistral Text Model on GPU 1
# This script will only see GPU 1
export CUDA_VISIBLE_DEVICES=1
python run_mistral.py
Your Python code (run_llava.py, run_mistral.py) doesn't need any special changes. It will automatically use the only GPU it can see.
Summary & Recommendation
| Feature | Model Splitting | Parallel Inference (Recommended) |
|---|
| Use Case | Running a single model >16GB VRAM (e.g., a 34B model). | Running two smaller models simultaneously (e.g., LLaVA + Mistral). |
| Performance | Slow. Limited by the 8 GB/s PCIe 4.0 x4 bus. | Fast. Each GPU runs at its full, independent speed. |
| VRAM Usage | Combines VRAM from both GPUs for one large model. | VRAM is isolated. GPU 0 has its own VRAM, GPU 1 has its own. |
| Setup | Requires careful layer mapping in code. | Simple environment variable setting in the terminal. |
Recommendation for your setup:
Strongly favor the Parallel Inference strategy.
Your 4060 Ti 16GB is powerful enough to run excellent models like Llama-3-8B-Instruct, Mixtral-8x7B (quantized), or LLaVA-13B. Use your second GPU in the x4 slot to offload a secondary task, like running a dedicated RAG model, a coding assistant, or a text-to-speech engine. This gives you multitasking capabilities without a significant performance penalty.