?擁抱臉| ?模型範圍 | ?紙本(待定)| ?部落格|文檔
演示 | 微信 (微信) | ?不和諧
請造訪我們的 Hugging Face 或 ModelScope 組織(點擊上面的連結),搜尋名稱以Qwen2.5-
開頭的檢查點,或造訪 Qwen2.5 系列,您將找到您需要的一切!享受!
要了解有關 Qwen2.5 的更多信息,請隨時閱讀我們的文件 [EN|ZH]。我們的文件由以下部分組成:
llama.cpp
和Ollama
等框架;vLLM
、 TGI
等框架部署 Qwen 進行大規模推理;自 Qwen2 發布以來的過去三個月裡,眾多開發者在 Qwen2 語言模型上建立了新模型,為我們提供了寶貴的回饋。在此期間,我們專注於創建更聰明、更有知識的語言模型。今天,我們很高興向大家介紹 Qwen 家族的最新成員: Qwen2.5 。
詳細的評估結果在此報告?部落格.
有關 GPU 記憶體和相應吞吐量的要求,請參閱此處的結果。
建議使用最新版本的transformers
(至少 4.37.0)。這裡我們展示了一個程式碼片段,向您展示如何將聊天模型與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 ]
對於量化模型,我們建議您使用 GPTQ 和 AWQ 對應項,即Qwen2.5-7B-Instruct-GPTQ-Int8
和Qwen2.5-7B-Instruct-AWQ
。
我們強烈建議用戶尤其是中國大陸的用戶使用ModelScope。 snapshot_download
可以幫助您解決有關下載檢查點的問題。
安裝ollama後,您可以使用以下指令啟動ollama服務:
ollama serve
# You need to keep this service running whenever you are using ollama
若要拉取模型檢查點並執行模型,請使用ollama run
指令。您可以透過在qwen2.5
加入後綴來指定模型大小,例如:0.5b
、 :1.5b
、 :7b
或:72b
:
ollama run qwen2.5:7b
# To exit, type "/bye" and press ENTER
您也可以透過 OpenAI 相容的 API 存取 ollama 服務。請注意,您需要 (1) 在使用 API 時保持ollama serve
運行,並且 (2) 在使用此 API 之前執行ollama run qwen2.5:7b
以確保模型檢查點已準備就緒。
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' ,
)
如需了解更多詳情,請造訪 ollama.ai。
下載我們提供的 GGUF 檔案或自行建立它們,您可以透過一行命令直接將它們與最新的llama.cpp
一起使用:
./llama-cli -m < path-to-file > -n 512 -co -sp -cnv -p " You are Qwen, created by Alibaba Cloud. You are a helpful assistant. "
如需其他指南,請參閱我們的文件。
如果您在 Apple Silicon 上運行,我們還提供了與mlx-lm
相容的檢查點。在 HuggingFace Hub 上尋找以 MLX 結尾的型號,例如 Qwen2.5-7B-Instruct-MLX。
Qwen2.5已經得到lmstudio.ai的支持。您可以直接將 LMStudio 與我們的 GGUF 檔案一起使用。
Qwen2.5已經得到OpenVINO工具包的支援。您可以使用 Intel CPU、整合 GPU 或獨立 GPU 安裝並執行此聊天機器人範例。
您可以直接使用text-generation-webui
建立 Web UI 演示。如果你使用GGUF,記得安裝最新的llama.cpp
輪子,並支援Qwen2.5。
克隆llamafile
,運行來源安裝,然後按照此處的指南使用 GGUF 檔案建立您自己的 llamafile 。您可以執行一行命令(例如./qwen.llamafile
)來建立演示。
Qwen2.5支持多種推理架構。這裡我們示範了vLLM
、 SGLang
和OpenLLM
的用法。
警告
不適用於 vllm 0.6.3。
我們建議您使用最新版本的vLLM來建立相容OpenAI的API服務,包括工具使用支援。使用聊天模型啟動伺服器,例如Qwen2.5-7B-Instruct
:
vllm serve Qwen/Qwen2.5-7B-Instruct
然後使用聊天 API,如下所示:
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 )
警告
SGLang 提供的相容 OpenAI 的 API 目前不支援工具使用或函數呼叫。
請從原始碼安裝SGLang
。與vLLM
類似,您需要啟動伺服器並使用 OpenAI 相容的 API 服務。首先啟動伺服器:
python -m sglang.launch_server --model-path Qwen/Qwen2.5-7B-Instruct --port 30000
您可以在 Python 中使用它,如下所示:
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" ])
OpenLLM 可讓您輕鬆地將 Qwen2.5 作為 OpenAI 相容的 API 運行。您可以使用openllm serve
啟動模型伺服器。例如:
openllm serve qwen2.5:7b
伺服器在http://localhost:3000/
處於活動狀態,提供與 OpenAI 相容的 API。您可以建立一個 OpenAI 用戶端來呼叫其聊天 API。有關更多信息,請參閱我們的文件。
對於工具使用功能,我們建議查看 Qwen-Agent,它提供了這些 API 的包裝器以支援工具使用或函數呼叫。 Qwen2.5 的工具使用也可以透過 Hugging Face transformers
、Ollama 和 vLLM 進行。請按照我們文件中的指南了解如何啟用支援。
我們建議您使用訓練框架,包括Axolotl、Llama-Factory、unsloth、Swift等,透過SFT、DPO、PPO等對您的模型進行微調。
我們所有的開源模型(3B 和 72B 變體除外)均在 Apache 2.0 下獲得授權。您可以在對應的 Hugging Face 儲存庫中找到許可證文件。您無需提交商業用途請求。
如果您發現我們的工作有幫助,請隨時給我們一個引用。
@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}
}
如果您有興趣給我們的研究團隊或產品團隊留言,請加入我們的Discord或微信群組!