环境配置
Reference : https://pytorch.org/get-started/previous-versions/
conda create -n vllm python=3.10
conda activate vllm
pip install torch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 --index-url https://download.pytorch.org/whl/cu121
# Install vLLM with CUDA 12.1.
pip install vllm
# 建议环境python 3.9 torch 2.1.2
vllm使用指南
https://zhuanlan.zhihu.com/p/685621164
VLLM挂起LLM环境
## 创建一个新会话:
tmux new -s ttt
## tmux 到一个新的控制窗口(附加到会话)
tmux a -t <正确的会话名>
tmux a -t ttt
# 切换到适合的环境
conda activate ttt
# 使用 vllm 在线运行 Orca2-13b,orca2-13B挂起时间双卡推算(20:39->20:52挂起成功,会有提示,且双GPU基本占满)
python -m vllm.entrypoints.openai.api_server --model /home/data/xxx/codespace/hgpractice/orca-2-13b --tensor-parallel-size 2
# 替换 model 位置相关参数 --model /你的服务器上Orca-2-13b的位置/Orca-2-13b
# 离开会话并保持其运行
tmux detach
启动成功后显示如图
#检查现有会话
tmux ls
#完全退出并关闭会话
exit
#强制关闭会话:
tmux kill-session -t <会话名>
调用方式的代码:
# import openai
from openai import OpenAI
openai_api_key = "EMPTY" # 填 EMPTY
openai_api_base = "http://localhost:8000/v1" # 这里在本地 mac 上远
#程请求部署的推理服务,所以端口是 8989
# openai.api_key=openai_api_key
# openai.base_url=openai_api_base
client = OpenAI(api_key=openai_api_key, base_url=openai_api_base)
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Give me a short introduction to large language model."}
]
llm_response = client.completions.create(
prompt="Who is the President of the United States?",
model="/home/data/xxx/codespace/hgpractice/orca-2-13b", # 这里填的就是vLLM 启动的时候的服务名,即orca2-13的位置
max_tokens=2048,
temperature=0,
stream=False,
logprobs=True,
echo=True,
n=1 #请求返回一个候选完成项
)
print(llm_response)