VLLM安裝
參考:http://www.lxweimin.com/p/fd0297790806
模型地址
https://www.modelscope.cn/models/Qwen/QwQ-32B-AWQ/files
下載命令:
modelscope download --model Qwen/QwQ-32B-AWQ --local_dir /data/vllm/data/models/QwQ-32B-AWQ
最后要把此模型copy到vllm集群中的所有機(jī)器上
自定義chat_template.jinja
模型自帶的chat_template(https://www.modelscope.cn/models/Qwen/QwQ-32B-AWQ/file/view/master?fileName=tokenizer_config.json&status=1),在最后拼接上了
<think>
,導(dǎo)致最終輸出的內(nèi)容只有</think>
而沒有<think>
。如果使輸出的內(nèi)容以<think>
開始,需要把chat_template中最后的<think>
去掉
自定義chat_template.jinja如下:
cat > /data/vllm/data/models/QwQ-32B-AWQ/chat_template.jinja <<"EOF"
{%- if tools %}
<|im_start|>system
{%- if messages[0]['role'] == 'system' %}
{{- messages[0]['content'] }}
{%- else %}
{{- '' }}
{%- endif %}
# Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
{%- for tool in tools %}
{{- tool | tojson }}
{%- endfor %}
</tools>
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call><|im_end|>
{%- else %}
{%- if messages[0]['role'] == 'system' %}
<|im_start|>system
{{ messages[0]['content'] }}
<|im_end|>
{%- endif %}
{%- endif %}
{%- for message in messages %}
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
<|im_start|>{{ message.role }}
{{ message.content }}
<|im_end|>
{%- elif message.role == "assistant" and not message.tool_calls %}
{%- set content = message.content.split('</think>')[-1].lstrip('\n') %}
<|im_start|>{{ message.role }}
{{ content }}
<|im_end|>
{%- elif message.role == "assistant" %}
<|im_start|>{{ message.role }}
{%- if message.content %}
{{ message.content }}
{%- endif %}
{%- for tool_call in message.tool_calls %}
{%- if tool_call.function is defined %}
{%- set tool_call = tool_call.function %}
{%- endif %}
<tool_call>
{"name": "{{ tool_call.name }}", "arguments": {{ tool_call.arguments | tojson }}}
</tool_call>
{%- endfor %}
<|im_end|>
{%- elif message.role == "tool" %}
{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
<|im_start|>user
{%- endif %}
<tool_response>
{{ message.content }}
</tool_response>
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
<|im_end|>
{%- endif %}
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
<|im_start|>assistant
{%- endif %}
EOF
啟動(dòng)
進(jìn)入vllm容器內(nèi)部:
docker exec -it ray_vllm bash
# 啟動(dòng)
nohup vllm serve /models/QwQ-32B-AWQ \
--served-model-name QwQ-32B-AWQ \
--gpu-memory-utilization 0.90 \
--max-num-seqs 1024 \
--max_model_len 30000 \
--pipeline_parallel_size 4 \
--tensor-parallel-size 2 \
--chat_template /models/QwQ-32B-AWQ/chat_template.jinja \
--enable-reasoning \
--reasoning-parser deepseek_r1 \
--port 8001 \
> logs/QwQ-32B-AWQ.log 2>&1 &
測試
[root@bogon ~]# curl http://10.3.6.41:8001/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer " \
-d '{
"model": "QwQ-32B-AWQ",
"messages": [
{
"role": "system",
"content": "你是一位富有詩意的助手,擅長以富有創(chuàng)意的方式闡釋復(fù)雜的概念"
},
{
"role": "user",
"content": "創(chuàng)作一首七言絕句,來描述煙花的壯麗與悲壯"
}
],
"stream": false
}'
# ------------------------------------ 輸出 ------------------------------------
{
"id": "chatcmpl-425afa4970b24d5a8f7589d98439d33f",
"object": "chat.completion",
"created": 1741336750,
"model": "QwQ-32B-AWQ",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"reasoning_content": "\n嗯,用戶讓我創(chuàng)作一首七言絕句,主題是煙花的壯麗與悲壯。首先得理解要求,七言絕句是四句,每句七個(gè)字,押平聲韻。得注意平仄和對仗這些基本要求。不過用戶又提到他擅長用詩意的方式闡釋復(fù)雜概念,所以可能需要更創(chuàng)新一些,不完全拘泥于傳統(tǒng)格式,但得保持古詩的韻味。\n\n先想煙花的特點(diǎn),既有絢爛奪目的美麗,又有瞬間消逝的悲壯。得把這兩種對立的情感結(jié)合起來。壯麗方面,可以用金色、烈火、銀河等意象,表現(xiàn)出煙花升空時(shí)的輝煌。悲壯的話,可以用隕落、短暫、塵埃等詞匯,強(qiáng)調(diào)其轉(zhuǎn)瞬即逝的遺憾。\n\n第一句要起興,描繪煙花升空的景象。比如“十萬金珠出燧臺”中,“十萬金珠”形容大量煙花如同金珠般燦爛,“燧臺”是指發(fā)射煙花的高臺,有古意。第二句進(jìn)一步渲染其燦爛,如“九霄烈火割云開”,用“九霄”描繪高空,烈火沖破云層,突出壯麗。\n\n第三句轉(zhuǎn)寫悲壯,可能提到隕落后的結(jié)局,比如“紛紜盡落珠沉海”,煙花散落如珠子沉入大海,帶點(diǎn)哀傷。最后一句點(diǎn)明主題,悲壯與壯麗并存,“頃刻榮枯入夢來”說明盛衰在剎那間,留在夢里,突出瞬間的輝煌與消逝的惆悵。\n\n接下來檢查押韻,第二句和第四句的末尾字“開”、“來”是否在同一個(gè)韻部。平水韻中,“開”屬于上平十灰,“來”也在同一韻部,所以押韻正確。平仄方面,七言絕句通常有四種格式,這里可能用的是平起式。需要逐字檢查是否符合平仄規(guī)則,可能需要調(diào)整,比如“十萬金珠出燧臺”平仄是否合適,但用戶可能更在意意境,所以如果平仄稍有出入,只要不影響朗讀效果也可以接受。\n\n還要考慮對仗,前兩句和后兩句是否有對仗關(guān)系。比如“十萬”對“九霄”,“金珠”對“烈火”,“出燧臺”對“割云開”,有一定的對仗感。后兩句的“紛紜盡落”對“頃刻榮枯”,“珠沉海”對“入夢來”,稍顯寬松,但絕句不要求必須對仗,所以可能沒問題。\n\n最后賞析部分需要點(diǎn)明意象的選擇和主題的融合,比如用金珠、烈火、銀河、隕星來表現(xiàn)壯麗,珠沉海、剎那榮枯來表現(xiàn)悲壯。同時(shí),結(jié)尾用夢境連接生死,深化了主題。這樣用戶不僅能得到詩,還能理解創(chuàng)作思路,符合他要求的解釋和創(chuàng)意闡釋。\n\n可能還需要考慮用詞是否準(zhǔn)確,比如“燧臺”是否合適,是否指煙花發(fā)射的地方,應(yīng)該沒問題。而“隕星”是否恰當(dāng),可能有些夸張,但增加詩意的大氣感。總之,這首詩要在有限的字?jǐn)?shù)內(nèi)兼顧壯麗與悲壯,通過意象和對比來表達(dá),應(yīng)該能滿足用戶的需求。\n",
"content": "\n\n\n《天火》\n十萬金珠出燧臺,九霄烈火割云開。\n紛紜盡落珠沉海,頃刻榮枯入夢來。\n\n賞析:這首作品以\"十萬金珠\"開篇,喻指煙花綻放時(shí)的璀璨奪目。后用\"割云開\"展現(xiàn)其刺破蒼穹的壯烈氣勢。第三句\"珠沉海\"筆鋒一轉(zhuǎn),喻指煙花隕落之悲,末句\"頃刻榮枯\"以時(shí)空交錯(cuò)的筆法,將剎那煙火與永恒夢境交融,既寫盡天火之壯美,亦道出生命無常的哲思。",
"tool_calls": [
]
},
"logprobs": null,
"finish_reason": "stop",
"stop_reason": null
}
],
"usage": {
"prompt_tokens": 43,
"total_tokens": 888,
"completion_tokens": 845,
"prompt_tokens_details": null
},
"prompt_logprobs": null
}