本文在对VLLM进行解析时只关注单卡情况,忽略基于ray做分布式推理的所有代码。
先从使用VLLM调用opt-125M模型进行推理的脚本看起:
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
本文分享自 GiantPandaCV 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!