Minimum Requirements
Software Prerequisites
- Python: 3.8 and above
- PyTorch: 1.12 and above (2.0+ recommended)
- Transformers: 4.32.0 and above
- CUDA: 11.4 and above (for GPU users)
Optional Dependencies
Flash Attention (recommended for fp16/bf16):Flash Attention 2 is now supported and provides significant speed improvements. It requires NVIDIA GPUs with Turing, Ampere, Ada, or Hopper architecture (e.g., H100, A100, RTX 3090, T4, RTX 2080).
GPU Requirements by Model Size
Qwen-1.8B
Recommended GPU: RTX 3060 12GB or better
Qwen-7B
Recommended GPU: RTX 3090 24GB, RTX 4090 24GB, or A100 40GB
Qwen-14B
Recommended GPU: A100 40GB or A100 80GB
Qwen-72B
Recommended GPU: 2× A100 80GB or 4× A100 40GB
Inference Performance
Benchmarked on A100-SXM4-80G GPU with PyTorch 2.0.1, CUDA 11.8, Flash Attention 2:Inference speed is averaged over encoded and generated tokens.
Finetuning Memory Requirements
Profiling on single A100-SXM4-80G with CUDA 11.8, PyTorch 2.0, Flash Attention 2: Batch size: 1, Gradient accumulation: 8Qwen-1.8B
Qwen-7B
Qwen-14B
Qwen-72B
“LoRA (emb)” refers to training with embedding and output layers as trainable parameters.
KV Cache Quantization Impact
With KV cache quantization enabled, memory usage for different configurations:Batch Size Scaling (Qwen-7B BF16, 1024 tokens)
Sequence Length Scaling (Qwen-7B BF16, batch size=1)
Multi-GPU Configurations
Pipeline Parallelism
For models that don’t fit on a single GPU, use automatic device mapping:Native pipeline parallelism has lower efficiency. For production, consider using vLLM with FastChat.
Recommended Multi-GPU Setups
CPU-Only Deployment
Qwen can run on CPU, but with significantly lower performance.Using qwen.cpp (Recommended)
For efficient CPU deployment, use qwen.cpp:- Pure C++ implementation
- Optimized for CPU inference
- Supports quantization
Direct CPU Inference
Cloud and API Deployment
DashScope API
The simplest deployment option through Alibaba Cloud:- qwen-turbo: Faster responses
- qwen-plus: Better performance
- No hardware management required
- Scalable inference
Specialized Hardware
Ascend 910: Supported for inference Hygon DCU: Supported for inferencex86 with OpenVINO: Supported on Core™/Xeon® Scalable Processors and Arc™ GPU
Docker Deployments
Pre-built Docker images are available to simplify environment setup. See the main documentation for Docker usage.Optimization Recommendations
Choose the right quantization
Choose the right quantization
Int4 Quantization when:
- Memory is the primary constraint
- Inference speed is important
- Slight quality degradation is acceptable
- Balance between memory and quality needed
- Memory is moderately constrained
- Maximum quality is required
- Sufficient GPU memory available
- Training or fine-tuning
Enable Flash Attention
Enable Flash Attention
Flash Attention 2 provides:
- 40% speedup for batch inference
- Lower memory consumption
- Better scaling with sequence length
Use KV Cache Quantization
Use KV Cache Quantization
Enable for:
- Longer sequences (4096+ tokens)
- Larger batch sizes
- Memory-constrained scenarios
Multinode training considerations
Multinode training considerations
- DeepSpeed ZeRO 3 requires high inter-node communication bandwidth
- ZeRO 2 recommended for multinode LoRA fine-tuning
- Test network throughput before scaling to multiple nodes