vLLM环境安装与运行实例【v0.5.4】

vLLM环境安装与运行实例【v0.5.4】

vLLM

vLLM is a fast and easy-to-use library for LLM inference and serving.
vLLM是一个快速易用的LLM推理和服务库。
(注意:vllm使用v0.5.4版本,否则使用PyTorch报错

vLLM环境安装

  1. 基础环境安装
环境版本备注
CUDA12.1PyTorch==2.4.0需要对应cuda==12.1
Python3.10.4可以通过Annaconda或者源码安装
vllm0.5.4使用v0.5.4版本,否则使用PyTorch报错
torch2.4.0PyTorch==2.4.0需要对应cuda==12.1

具体安装可参考我的另一篇文章fairseq-0.12.2多机训练环境搭建

  1. Python安装(可选,通过Annaconda)
conda create -n vllm python=3.10 -y
conda activate vllm

vllm为conda创建的环境名称

  1. 安装vllm
#使用v0.5.4版本,否则使用PyTorch报错
pip3 install vllm==0.5.4 -i https://pypi.tuna.tsinghua.edu.cn/simple
#如果PyTorch版本不正确,可按以下安装
pip3 install torch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 --index-url https://download.pytorch.org/whl/cu121 -i https://pypi.tuna.tsinghua.edu.cn/simple

vLLM运行示例

  1. 测试代码
from vllm import LLM, SamplingParams

prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

llm = LLM(model="./opt-125m")

outputs = llm.generate(prompts, sampling_params)

for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
  1. 测试结果
CUDA_VISIBLE_DEVICES=0 python3 test.py

说明:

  • CUDA_VISIBLE_DEVICES为指定运行显卡号

运行结果:
vllm测试结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

莽夫搞战术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值