System Requirements
Minimum Requirements
Python
Python 3.8 or higher
PyTorch
PyTorch 1.12+ (2.0+ recommended)
CUDA
CUDA 11.4+ (for GPU users)
GPU Memory
Varies by model size (see table below)
GPU Memory Requirements
Minimum GPU memory needed for inference (generating 2048 tokens):For fine-tuning, memory requirements are higher. Q-LoRA requires minimum:
- Qwen-1.8B: 5.8GB
- Qwen-7B: 11.5GB
- Qwen-14B: 18.7GB
- Qwen-72B: 61.4GB
Basic Installation
Step 1: Install Core Dependencies
Install the required Python packages from the requirements file:Understanding the Dependencies
Understanding the Dependencies
- transformers: Hugging Face library for loading and running models
- accelerate: Efficient model loading and distributed inference
- tiktoken: Fast tokenization library
- einops: Tensor operations for attention mechanisms
- transformers_stream_generator: Streaming text generation support
- scipy: Scientific computing utilities
Step 2: Verify Installation
Test your installation with this simple script:Flash Attention (Recommended)
Flash Attention significantly improves inference speed and reduces memory usage. Installation is optional but highly recommended.1
Check Compatibility
Flash Attention requires:
- GPU with FP16 or BF16 support
- CUDA 11.4 or higher
- PyTorch 1.12 or higher
2
Install Flash Attention
Qwen supports Flash Attention 2 for optimal performance:
3
Install Optional Components (Flash Attention v2.1.1 and below)
For older versions of Flash Attention, you may optionally install additional components:
These are optional and may slow down the installation. Skip if flash-attention version is higher than 2.1.1.
4
Verify Flash Attention
Test that Flash Attention is working:
Performance Impact
With Flash Attention enabled, you can expect:- 40% faster batch inference
- 20-30% lower memory usage
- Support for longer sequences without OOM errors
Docker Installation
Using Docker is the fastest way to get started with Qwen, as it includes all dependencies pre-configured.Pre-built Docker Images
Qwen provides official Docker images that skip most environment setup steps:Make sure you have NVIDIA Container Toolkit installed to use GPUs with Docker.
Custom Dockerfile
If you need a custom setup, create your own Dockerfile:Quantization Dependencies
To use quantized models (Int4/Int8), install additional libraries:AutoGPTQ Installation
Verify Quantization Support
Fine-tuning Dependencies
For training and fine-tuning, install additional packages:LoRA and Q-LoRA
peft>=0.8.0 has a known issue with loading Qwen tokenizers. Use peft<0.8.0 until the issue is resolved.DeepSpeed (for distributed training)
Full Fine-tuning Requirements
Platform-Specific Installation
x86 Platforms (Intel CPUs/GPUs)
For Intel Core/Xeon processors or Arc GPUs, use OpenVINO for optimized inference:Ascend NPU
For Huawei Ascend 910 NPU:ascend-support directory in the Qwen repository for detailed instructions.
Hygon DCU
For Hygon DCU acceleration:Installing from Source
To get the latest development version or contribute to Qwen:1
Clone the Repository
2
Install Dependencies
3
Run from Source
Downloading Models
From Hugging Face
Models are automatically downloaded when you first load them:From ModelScope
For users with better access to ModelScope:Manual Download
You can also manually download model files:- Using Git LFS
- Using Hugging Face CLI
Environment Variables
Configure these environment variables for optimal performance:Verification
Run this complete verification script to ensure everything is working:verify_installation.py and run:
Troubleshooting
Installation fails with CUDA errors
Installation fails with CUDA errors
Ensure your CUDA version matches PyTorch requirements:
Flash Attention compilation fails
Flash Attention compilation fails
Common solutions:
- Ensure you have CUDA development tools:
sudo apt-get install cuda-toolkit-11-8 - Update your GCC compiler:
sudo apt-get install build-essential - Set environment variables:
- Try installing from PyPI:
pip install flash-attn --no-build-isolation
AutoGPTQ version conflicts
AutoGPTQ version conflicts
If you see errors about incompatible versions:
ImportError: trust_remote_code
ImportError: trust_remote_code
Update transformers to a compatible version:
Out of disk space during installation
Out of disk space during installation
Flash Attention compilation requires ~5GB temporary space:
Model download is slow or fails
Model download is slow or fails
Try these solutions:
- Use ModelScope instead of Hugging Face (see above)
- Set a mirror:
- Download manually with git-lfs or huggingface-cli
- Resume interrupted downloads by re-running the same command
Next Steps
Quickstart
Get started with Qwen in under 5 minutes
Model Selection
Choose the right model for your use case
Inference
Learn about inference options and optimizations
Docker Setup
Deploy Qwen with Docker in production