Skip to main content
This guide covers everything you need to install and configure Qwen models, from basic dependencies to advanced optimizations.

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:
  • 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 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
Verify your setup:
2

Install Flash Attention

Qwen supports Flash Attention 2 for optimal performance:
This installation may take 10-30 minutes as it compiles CUDA kernels. Ensure you have sufficient disk space (~5GB for build files).
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:
Build and run:

Quantization Dependencies

To use quantized models (Int4/Int8), install additional libraries:

AutoGPTQ Installation

Version Compatibility: AutoGPTQ packages are highly dependent on your PyTorch and CUDA versions. If you encounter installation issues:
  • For PyTorch 2.1: auto-gptq>=0.5.1 transformers>=4.35.0 optimum>=1.14.0 peft>=0.6.1
  • For PyTorch 2.0: auto-gptq<0.5.0 transformers<4.35.0 optimum<1.14.0 peft>=0.5.0,<0.6.0
If pre-compiled wheels don’t work, build from source:

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)

Pydantic Compatibility: DeepSpeed may conflict with pydantic>=2.0. If you encounter errors, ensure pydantic<2.0:

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:
See the OpenVINO notebooks for Qwen-specific examples.

Ascend NPU

For Huawei Ascend 910 NPU:
Refer to the 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:

Environment Variables

Configure these environment variables for optimal performance:

Verification

Run this complete verification script to ensure everything is working:
Save this as verify_installation.py and run:

Troubleshooting

Ensure your CUDA version matches PyTorch requirements:
Common solutions:
  1. Ensure you have CUDA development tools: sudo apt-get install cuda-toolkit-11-8
  2. Update your GCC compiler: sudo apt-get install build-essential
  3. Set environment variables:
  4. Try installing from PyPI: pip install flash-attn --no-build-isolation
If you see errors about incompatible versions:
Update transformers to a compatible version:
Flash Attention compilation requires ~5GB temporary space:
Try these solutions:
  1. Use ModelScope instead of Hugging Face (see above)
  2. Set a mirror:
  3. Download manually with git-lfs or huggingface-cli
  4. 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