🤗 Hugging Face | 🤖 ModelScope | 📑 Paper | 📑 Blog | 📖 Documentation
🖥️ Demo | 💬 WeChat (微信) | 🫨 Discord
Visit our Hugging Face or ModelScope organization (click links above), search checkpoints with names starting with Qwen2.5-
or visit the Qwen2.5 collection, and you will find all you need! Enjoy!
To learn more about Qwen2.5, feel free to read our documentation [EN|ZH]. Our documentation consists of the following sections:
- Quickstart: the basic usages and demonstrations;
- Inference: the guidance for the inference with transformers, including batch inference, streaming, etc.;
- Run Locally: the instructions for running LLM locally on CPU and GPU, with frameworks like
llama.cpp
andOllama
; - Deployment: the demonstration of how to deploy Qwen for large-scale inference with frameworks like
vLLM
,TGI
, etc.; - Quantization: the practice of quantizing LLMs with GPTQ, AWQ, as well as the guidance for how to make high-quality quantized GGUF files;
- Training: the instructions for post-training, including SFT and RLHF (TODO) with frameworks like Axolotl, LLaMA-Factory, etc.
- Framework: the usage of Qwen with frameworks for application, e.g., RAG, Agent, etc.
- Benchmark: the statistics about inference speed and memory footprint (to be updated for Qwen2.5).
In the past three months since Qwen2's release, numerous developers have built new models on the Qwen2 language models, providing us with valuable feedback. During this period, we have focused on creating smarter and more knowledgeable language models. Today, we are excited to introduce the latest addition to the Qwen family: Qwen2.5.
- Dense, easy-to-use, decoder-only language models, available in 0.5B, 1.5B, 3B, 7B, 14B, 32B, and 72B sizes, and base and instruct variants.
- Pretrained on our latest large-scale dataset, encompassing up to 18T tokens.
- Significant improvements in instruction following, generating long texts (over 8K tokens), understanding structured data (e.g, tables), and generating structured outputs especially JSON.
- More resilient to the diversity of system prompts, enhancing role-play implementation and condition-setting for chatbots.
- Context length support up to 128K tokens and can generate up to 8K tokens.
- Multilingual support for over 29 languages, including Chinese, English, French, Spanish, Portuguese, German, Italian, Russian, Japanese, Korean, Vietnamese, Thai, Arabic, and more.
- 2024.09.19: We released the Qwen2.5 series. This time there are 3 extra model sizes: 3B, 14B, and 32B for more possibilities. Check our blog for more!
- 2024.06.06: We released the Qwen2 series. Check our blog!
- 2024.03.28: We released the first MoE model of Qwen: Qwen1.5-MoE-A2.7B! Temporarily, only HF transformers and vLLM support the model. We will soon add the support of llama.cpp, mlx-lm, etc. Check our blog for more information!
- 2024.02.05: We released the Qwen1.5 series.
Detailed evaluation results are reported in this 📑 blog.
For requirements on GPU memory and the respective throughput, see results here (to be updated for Qwen2.5).
The latest version of transformers
is recommended (at least 4.37.0).
Here we show a code snippet to show you how to use the chat model with transformers
:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Qwen/Qwen2.5-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = "Give me a short introduction to large language model."
messages = [
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
For quantized models, we advise you to use the GPTQ and AWQ correspondents, namely Qwen2.5-7B-Instruct-GPTQ-Int8
and Qwen2.5-7B-Instruct-AWQ
.
We strongly advise users especially those in mainland China to use ModelScope. snapshot_download
can help you solve issues concerning downloading checkpoints.
After installing ollama, you can initiate the ollama service with the following command:
ollama serve
# You need to keep this service running whenever you are using ollama
To pull a model checkpoint and run the model, use the ollama run
command. You can specify a model size by adding a suffix to qwen2.5
, such as :0.5b
, :1.5b
, :7b
, or :72b
:
ollama run qwen2.5:7b
# To exit, type "/bye" and press ENTER
You can also access the ollama service via its OpenAI-compatible API. Please note that you need to (1) keep ollama serve
running while using the API, and (2) execute ollama run qwen2.5:7b
before utilizing this API to ensure that the model checkpoint is prepared.
from openai import OpenAI
client = OpenAI(
base_url='http://localhost:11434/v1/',
api_key='ollama', # required but ignored
)
chat_completion = client.chat.completions.create(
messages=[
{
'role': 'user',
'content': 'Say this is a test',
}
],
model='qwen2.5:7b',
)
For additional details, please visit ollama.ai.
Download our provided GGUF files or create them by yourself, and you can directly use them with the latest llama.cpp
with a one-line command:
./llama-cli -m <path-to-file> -n 512 -co -sp -cnv -f "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."
For additional guides, please refer to our documentation.
If you are running on Apple Silicon, we have also provided checkpoints compatible with mlx-lm
. Look for models ending with MLX on HuggingFace Hub, like Qwen2.5-7B-Instruct-MLX.
Qwen2.5 has already been supported by lmstudio.ai. You can directly use LMStudio with our GGUF files.
Qwen2.5 has already been supported by OpenVINO toolkit. You can install and run this chatbot example with Intel CPU, integrated GPU or discrete GPU.
You can directly use text-generation-webui
for creating a web UI demo. If you use GGUF, remember to install the latest wheel of llama.cpp
with the support of Qwen2.5.
Clone llamafile
, run source install, and then create your own llamafile with the GGUF file following the guide here. You are able to run one line of command, say ./qwen.llamafile
, to create a demo.
Qwen2.5 is supported by multiple inference frameworks. Here we demonstrate the usage of vLLM
and SGLang
.
We advise you to use the latest version of vLLM to build OpenAI-compatible API service, including tool use support. Start the server with a chat model, e.g. Qwen2.5-7B-Instruct
:
vllm serve Qwen/Qwen2.5-7B-Instruct
Then use the chat API as demonstrated below:
curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "Qwen/Qwen2.5-7B-Instruct",
"messages": [
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
{"role": "user", "content": "Tell me something about large language models."}
],
"temperature": 0.7,
"top_p": 0.8,
"repetition_penalty": 1.05,
"max_tokens": 512
}'
from openai import OpenAI
# Set OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
chat_response = client.chat.completions.create(
model="Qwen2.5-7B-Instruct",
messages=[
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
{"role": "user", "content": "Tell me something about large language models."},
],
temperature=0.7,
top_p=0.8,
max_tokens=512,
extra_body={
"repetition_penalty": 1.05,
},
)
print("Chat response:", chat_response)
Warning
The OpenAI-compatible APIs provided by SGLang currently do NOT support tool use or function calling.
Please install SGLang
from source. Similar to vLLM
, you need to launch a server and use OpenAI-compatible API service. Start the server first:
python -m sglang.launch_server --model-path Qwen/Qwen2.5-7B-Instruct --port 30000
You can use it in Python as shown below:
from sglang import function, system, user, assistant, gen, set_default_backend, RuntimeEndpoint
@function
def multi_turn_question(s, question_1, question_2):
s += system("You are Qwen, created by Alibaba Cloud. You are a helpful assistant.")
s += user(question_1)
s += assistant(gen("answer_1", max_tokens=256))
s += user(question_2)
s += assistant(gen("answer_2", max_tokens=256))
set_default_backend(RuntimeEndpoint("http://localhost:30000"))
state = multi_turn_question.run(
question_1="What is the capital of China?",
question_2="List two local attractions.",
)
for m in state.messages():
print(m["role"], ":", m["content"])
print(state["answer_1"])
For tool use capabilities, we recommend taking a look at Qwen-Agent, which provides a wrapper around these APIs to support tool use or function calling.
Tool use with Qwen2.5 can also be conducted with Hugging Face transformers
, Ollama, and vLLM.
Follow guides in our documentation to see how to enable the support.
We advise you to use training frameworks, including Axolotl, Llama-Factory, unsloth, Swift, etc., to finetune your models with SFT, DPO, PPO, etc.
All our open-source models, except for the 3B and 72B variants, are licensed under Apache 2.0. You can find the license files in the respective Hugging Face repositories. It is NOT necessary for you to submit a request for commercial usage.
If you find our work helpful, feel free to give us a cite.
@misc{qwen2.5,
title = {Qwen2.5: A Party of Foundation Models},
url = {https://qwenlm.github.io/blog/qwen2.5/},
author = {Qwen Team},
month = {September},
year = {2024}
}
@article{qwen2,
title={Qwen2 Technical Report},
author={An Yang and Baosong Yang and Binyuan Hui and Bo Zheng and Bowen Yu and Chang Zhou and Chengpeng Li and Chengyuan Li and Dayiheng Liu and Fei Huang and Guanting Dong and Haoran Wei and Huan Lin and Jialong Tang and Jialin Wang and Jian Yang and Jianhong Tu and Jianwei Zhang and Jianxin Ma and Jin Xu and Jingren Zhou and Jinze Bai and Jinzheng He and Junyang Lin and Kai Dang and Keming Lu and Keqin Chen and Kexin Yang and Mei Li and Mingfeng Xue and Na Ni and Pei Zhang and Peng Wang and Ru Peng and Rui Men and Ruize Gao and Runji Lin and Shijie Wang and Shuai Bai and Sinan Tan and Tianhang Zhu and Tianhao Li and Tianyu Liu and Wenbin Ge and Xiaodong Deng and Xiaohuan Zhou and Xingzhang Ren and Xinyu Zhang and Xipin Wei and Xuancheng Ren and Yang Fan and Yang Yao and Yichang Zhang and Yu Wan and Yunfei Chu and Yuqiong Liu and Zeyu Cui and Zhenru Zhang and Zhihao Fan},
journal={arXiv preprint arXiv:2407.10671},
year={2024}
}
If you are interested to leave a message to either our research team or product team, join our Discord or WeChat groups!