Skip to main content

Overview

Multi-GPU inference allows you to run larger Qwen models (like Qwen-72B) or handle higher throughput by distributing computation across multiple GPUs. This guide covers different approaches for multi-GPU deployment.

Why Multi-GPU?

Large Models

Run 72B parameter models that don’t fit on a single GPU

Higher Throughput

Process more requests simultaneously

Faster Inference

Parallel processing reduces latency

Better Utilization

Use available GPU resources efficiently

Automatic Multi-GPU (Transformers)

The simplest approach uses Transformers’ automatic device mapping:
With device_map="auto", Transformers automatically distributes model layers across available GPUs to maximize memory efficiency.

How It Works

Manual Device Mapping

For fine-grained control, specify device placement manually:
Manual device mapping requires careful balancing to avoid memory issues on any single GPU. Use automatic mapping unless you have specific requirements.

vLLM for Production

For production deployments, vLLM provides optimized multi-GPU inference with tensor parallelism:

Installation

Basic Usage

vLLM Wrapper

Qwen provides a vLLM wrapper for chat-style inference:
vllm_wrapper.py
See examples/vllm_wrapper.py:224-239 for the complete implementation.

GPU Memory Requirements

Estimated memory requirements for different configurations:

Qwen-7B

Qwen-14B

Qwen-72B

Performance Comparison

Benchmark results for Qwen-72B (generating 2048 tokens):
vLLM provides ~2x speedup compared to native Transformers for multi-GPU inference.

Pipeline Parallelism

For very large models, combine with pipeline parallelism:

Monitoring GPU Usage

Monitor GPU utilization during inference:

Best Practices

  • Small models (1.8B-7B): Single GPU is usually sufficient
  • Medium models (14B): Single GPU or 2 GPUs with quantization
  • Large models (72B): Multi-GPU required, consider vLLM
For production:
  • Use vLLM with tensor parallelism
  • Enable continuous batching
  • Consider quantization (Int8/Int4)
  • Use BF16 precision when possible
Ensure even distribution:

Troubleshooting

Redistribute layers more evenly:
Use NVLink if available, or reduce communication:
Profile and rebalance:

Next Steps

vLLM Deployment

Production-grade multi-GPU serving

Quantization

Reduce memory requirements

Batch Inference

Increase throughput with batching

API Server

Deploy as an API service