当前位置:   article > 正文

在Win11上部署大模型推理加速工具vLLM_vllm windows

vllm windows

vLLM是伯克利大学LMSYS组织开源的大语言模型高速推理框架,旨在极大地提升实时场景下的语言模型服务的吞吐与内存使用效率。vLLM是一个快速且易于使用的库,用于 LLM 推理和服务,可以和HuggingFace 无缝集成。vLLM利用了全新的注意力算法PagedAttention,有效地管理注意力键和值。

在吞吐量方面,vLLM的性能比HuggingFace Transformers(HF)高出 24 倍,文本生成推理(TGI)高出3.5倍。

使用docker方式安装

拉取cuda镜像

docker pull nvcr.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04

创建容器

docker run --gpus=all -it --name vllm -p 8010:8000 -v D:\llm-model:/llm-model  nvcr.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04

安装依赖环境

  1. apt-get update -yq --fix-missing
  2. DEBIAN_FRONTEND=noninteractive
  3. apt-get install -yq --no-install-recommends pkg-config wget cmake curl git vim

安装Miniconda3

  1. wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
  2. sh Miniconda3-latest-Linux-x86_64.sh -b -u -p ~/miniconda3
  3. ~/miniconda3/bin/conda init
  4. source ~/.bashrc

创建环境

  1. conda create -n vllm python=3.10
  2. conda activate vllm

安装依赖库

  1. pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
  2. pip install torch==2.1.2+cu118 torchvision==0.16.2+cu118 torchaudio==2.1.2 xformers==0.0.23.post1+cu118 --extra-index-url https://download.pytorch.org/whl/cu118
  3. pip install transformers
  4. pip install requests
  5. pip install gradio==4.14.0
  6. export VLLM_VERSION=0.4.0
  7. export PYTHON_VERSION=39
  8. pip install https://github.com/vllm-project/vllm/releases/download/v${VLLM_VERSION}/vllm-${VLLM_VERSION}+cu118-cp${PYTHON_VERSION}-cp${PYTHON_VERSION}-manylinux1_x86_64.whl --extra-index-url https://download.pytorch.org/whl/cu118

在线调用

vLLM可以部署为API服务,web框架使用FastAPI。API服务使用AsyncLLMEngine类来支持异步调用。

启动服务

  1. python -m vllm.entrypoints.openai.api_server --model /llm-model/Baichuan2-7B-Chat --served-model-name Baichuan2-7B-Chat --trust-remote-code
  2. #查看GPU
  3. nvidia-smi
  4. #指定GPU和端口号
  5. CUDA_VISIBLE_DEVICES=7 python -m vllm.entrypoints.openai.api_server --host 0.0.0.0 --port 10086 --model /llm-model/Baichuan2-7B-Chat --served-model-name Baichuan2-7B-Chat --trust-remote-code

调用方式

  1. curl http://localhost:8000/v1/completions \
  2. -H "Content-Type: application/json" \
  3. -d '{
  4. "model": "Baichuan2-7B-Chat",
  5. "prompt": "San Francisco is a",
  6. "max_tokens": 7,
  7. "temperature": 0
  8. }'
  1. curl http://localhost:8000/v1/chat/completions \
  2. -H "Content-Type: application/json" \
  3. -d '{
  4. "model": "Baichuan2-7B-Chat",
  5. "messages": [
  6. {"role": "system", "content": "You are a helpful assistant."},
  7. {"role": "user", "content": "Who won the world series in 2020?"}
  8. ]
  9. }'

离线调用

  1. import torch
  2. from vllm import LLM, SamplingParams
  3. MODEL_PATH = "/llm-model/Baichuan2-7B-Chat"
  4. prompts = ["San Francisco is a"]
  5. sampling_params = SamplingParams(temperature=0, max_tokens=100)
  6. llm = LLM(model=MODEL_PATH,
  7. tokenizer_mode='auto',
  8. trust_remote_code=True,
  9. enforce_eager=True,
  10. enable_prefix_caching=True)
  11. outputs = llm.generate(prompts, sampling_params=sampling_params)
  12. for output in outputs:
  13. generated_text = output.outputs[0].text
  14. print(generated_text)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/887207
推荐阅读
相关标签
  

闽ICP备14008679号