VLLM加速LLM推理

环境配置

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)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值