Yes, you can use 2 RTX 3080s for LLaVA and Mistral multimodal workloads. Let's break down the capabilities and optimal setup, considering the RTX 3080's 10GB VRAM per card.
Hardware Configuration
RTX 3080 Specs (Per Card):
- VRAM: 10GB GDDR6X
- Memory Bandwidth: 760 GB/s
- FP16 Performance: ~70 TFLOPS
- Power Draw: ~320W per card
- Total System VRAM: 20GB (2 × 10GB)
Model Size Constraints
What Fits on Each 10GB Card:
-
LLaVA Models:
- ✅ LLaVA-7B (4-bit quantized): ~4-5GB VRAM
- ✅ LLaVA-13B (4-bit quantized): ~7-8GB VRAM
- ❌ LLaVA-34B: Too large even quantized
-
Mistral Models:
- ✅ Mistral-7B (4-bit): ~4GB VRAM
- ✅ Mixtral-8x7B (4-bit): ~8GB VRAM
- ✅ Idefics-9B (multimodal, 4-bit): ~6GB VRAM
Optimal Setup Strategy
Here's the best configuration for two RTX 3080s:
# config.py
DEVICE_CONFIG = {
"GPU_0": {
"model": "LLaVA-13B",
"quantization": "4-bit",
"tasks": ["vision", "image_understanding"],
"vram_usage": "~7.5GB"
},
"GPU_1": {
"model": "Mixtral-8x7B",
"quantization": "4-bit",
"tasks": ["text", "reasoning"],
"vram_usage": "~8GB"
}
}
Implementation Code
import os
import torch
from transformers import AutoProcessor, AutoModelForCausalLM
from auto_gptq import AutoGPTQForCausalLM
import numpy as np
from PIL import Image
class DualGPUProcessor:
def __init__(self):
# GPU 0: LLaVA for vision
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
self.llava_processor = AutoProcessor.from_pretrained(
"liuhaotian/LLaVA-13B-v1.5-GPTQ",
trust_remote_code=True
)
self.llava_model = AutoModelForCausalLM.from_pretrained(
"liuhaotian/LLaVA-13B-v1.5-GPTQ",
device_map="auto",
trust_remote_code=True,
revision="gptq-4bit-32g-actorder_True"
)
# GPU 1: Mixtral for text
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
self.mixtral_model = AutoGPTQForCausalLM.from_quantized(
"TheBloke/Mixtral-8x7B-Instruct-v0.1-GPTQ",
device_map="auto",
trust_remote_code=True,
revision="gptq-4bit-32g-actorder_True"
)
# Reset device visibility
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"
def process_image(self, image_path, prompt):
"""Process image using LLaVA on GPU 0"""
with torch.cuda.device(0):
image = Image.open(image_path)
inputs = self.llava_processor(
images=image,
text=prompt,
return_tensors="pt"
).to("cuda:0")
outputs = self.llava_model.generate(
**inputs,
max_new_tokens=200,
temperature=0.7
)
return self.llava_processor.decode(
outputs[0],
skip_special_tokens=True
)
def process_text(self, prompt):
"""Process text using Mixtral on GPU 1"""
with torch.cuda.device(1):
inputs = self.mixtral_model.tokenizer(
prompt,
return_tensors="pt"
).to("cuda:1")
outputs = self.mixtral_model.generate(
**inputs,
max_new_tokens=200,
temperature=0.7
)
return self.mixtral_model.tokenizer.decode(
outputs[0],
skip_special_tokens=True
)
def process_multimodal_task(self, image_path, text_prompt):
"""Combined vision and text processing"""
# Get image understanding from LLaVA
vision_output = self.process_image(
image_path,
"Describe this image in detail."
)
# Feed vision output to Mixtral for reasoning
combined_prompt = f"""
Image Description: {vision_output}
User Query: {text_prompt}
Please provide a detailed response considering both the image content and the query.
"""
final_response = self.process_text(combined_prompt)
return final_response
Usage Example
# main.py
from dual_gpu_processor import DualGPUProcessor
def main():
# Initialize the processor
processor = DualGPUProcessor()
# Example multimodal task
image_path = "example.jpg"
text_prompt = "What are the key elements in this image and how do they relate to our business goals?"
# Process the task
result = processor.process_multimodal_task(image_path, text_prompt)
print(result)
if __name__ == "__main__":
main()
Memory Management Tips
- Dynamic VRAM Clearing:
def clear_gpu_memory(gpu_id):
with torch.cuda.device(gpu_id):
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
- Batch Processing for Efficiency:
def batch_process_images(image_paths, batch_size=4):
results = []
for i in range(0, len(image_paths), batch_size):
batch = image_paths[i:i+batch_size]
# Process batch
clear_gpu_memory(0) # Clear LLaVA GPU
# Continue processing
Performance Monitoring
import pynvml
class GPUMonitor:
def __init__(self):
pynvml.nvmlInit()
def get_gpu_usage(self, gpu_id):
handle = pynvml.nvmlDeviceGetHandleByIndex(gpu_id)
info = pynvml.nvmlDeviceGetMemoryInfo(handle)
return {
"total": info.total / 1024**2, # MB
"used": info.used / 1024**2,
"free": info.free / 1024**2
}
def monitor(self):
while True:
print("GPU 0 (LLaVA):", self.get_gpu_usage(0))
print("GPU 1 (Mixtral):", self.get_gpu_usage(1))
time.sleep(1)
Optimization Tips
-
Load Balancing:
- Keep LLaVA on GPU 0 for vision tasks
- Use Mixtral on GPU 1 for text/reasoning
- Avoid cross-GPU communication when possible
-
Memory Efficiency:
- Use 4-bit quantization for both models
- Clear VRAM between batches
- Monitor memory usage with
GPUMonitor
-
Performance Tweaks:
# Add to model loading
torch.backends.cudnn.benchmark = True
torch.backends.cuda.matmul.allow_tf32 = True
-
Error Handling:
class GPUOutOfMemoryHandler:
@staticmethod
def handle_oom(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except torch.cuda.OutOfMemoryError:
clear_gpu_memory(0)
clear_gpu_memory(1)
return func(*args, **kwargs)
return wrapper
System Requirements
- Power Supply: Minimum 850W (preferably 1000W+)
- Cooling: Excellent airflow required
- PCIe Slots: Two x16 slots recommended
- Software:
- CUDA 11.8+
- PyTorch 2.0+
- transformers 4.30+
- auto-gptq latest version
This setup provides a powerful multimodal AI system capable of handling both vision and text tasks efficiently across two RTX 3080s. The key is maintaining proper load balancing and memory management between the GPUs.