VLLM推理流程解析

2023-08-22 09:20:29 浏览数 (2)

0x0. 前言

本文在对VLLM进行解析时只关注单卡情况,忽略基于ray做分布式推理的所有代码。

0x1. 运行流程梳理

先从使用VLLM调用opt-125M模型进行推理的脚本看起:

代码语言:javascript复制
from vllm import LLM, SamplingParams

# Sample prompts.
prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

# Create an LLM.
llm = LLM(model="facebook/opt-125m")
# Generate texts from the prompts. The output is a list of RequestOutput objects
# that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

...

完整文章清移步知乎,这个是最近有空时逐步走读了下vllm的流程,还不包含paged attention的实现具体解析,后续有空会把这paged attention这一节的 kernel 实现细节补一下

地址:https://zhuanlan.zhihu.com/p/649974825 & https://zhuanlan.zhihu.com/p/649977422

参考:https://zhuanlan.zhihu.com/p/641999400

0 人点赞