? 포옹하는 얼굴 | ? 모델스코프 | ? 종이(미정) | ? 블로그 | 문서
데모 | 위챗(微信) | ? 불화
Hugging Face 또는 ModelScope 조직(위 링크 클릭)을 방문하여 Qwen2.5-
로 시작하는 이름으로 체크포인트를 검색하거나 Qwen2.5 컬렉션을 방문하면 필요한 모든 것을 찾을 수 있습니다! 즐기다!
Qwen2.5에 대해 자세히 알아보려면 문서 [EN|ZH]를 읽어보세요. 우리의 문서는 다음 섹션으로 구성됩니다:
llama.cpp
및 Ollama
와 같은 프레임워크를 사용하여 CPU 및 GPU에서 로컬로 LLM을 실행하기 위한 지침입니다.vLLM
, TGI
등과 같은 프레임워크를 사용하여 대규모 추론을 위해 Qwen을 배포하는 방법 시연Qwen2 출시 이후 지난 3개월 동안 수많은 개발자가 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
명령을 사용하세요. :0.5b
, :1.5b
, :7b
또는 :72b
와 같이 qwen2.5
에 접미사를 추가하여 모델 크기를 지정할 수 있습니다.
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
과 호환되는 체크포인트도 제공됩니다. Qwen2.5-7B-Instruct-MLX와 같이 HuggingFace Hub에서 MLX로 끝나는 모델을 찾으세요.
Qwen2.5는 이미 lmstudio.ai에서 지원되었습니다. GGUF 파일과 함께 LMStudio를 직접 사용할 수 있습니다.
Qwen2.5는 이미 OpenVINO 툴킷에서 지원되었습니다. Intel CPU, 통합 GPU 또는 개별 GPU를 사용하여 이 챗봇 예제를 설치하고 실행할 수 있습니다.
웹 UI 데모를 생성하기 위해 text-generation-webui
직접 사용할 수 있습니다. GGUF를 사용하는 경우 Qwen2.5를 지원하는 최신 휠인 llama.cpp
를 설치해야 합니다.
llamafile
복제하고 소스 설치를 실행한 다음 여기 가이드에 따라 GGUF 파일을 사용하여 자신만의 llamafile을 만듭니다. ./qwen.llamafile
과 같은 한 줄의 명령을 실행하여 데모를 만들 수 있습니다.
Qwen2.5는 여러 추론 프레임워크에서 지원됩니다. 여기서는 vLLM
, SGLang
및 OpenLLM
의 사용법을 보여줍니다.
경고
vllm 0.6.3에서는 작동하지 않습니다.
도구 사용 지원을 포함하여 OpenAI 호환 API 서비스를 구축하려면 최신 버전의 vLLM을 사용하는 것이 좋습니다. 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를 호출할 수 있습니다. 자세한 내용은 설명서를 참조하세요.
도구 사용 기능의 경우 도구 사용 또는 함수 호출을 지원하기 위해 이러한 API에 대한 래퍼를 제공하는 Qwen-Agent를 살펴보는 것이 좋습니다. Qwen2.5의 도구 사용은 Hugging Face transformers
, Ollama 및 vLLM에서도 수행할 수 있습니다. 지원을 활성화하는 방법을 알아보려면 설명서의 지침을 따르세요.
SFT, DPO, PPO 등으로 모델을 미세 조정하려면 Axolotl, Llama-Factory, unsloth, Swift 등을 포함한 교육 프레임워크를 사용하는 것이 좋습니다.
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 또는 WeChat 그룹에 가입하세요!