-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] InternVL2-2B的推理速度慢,发现是视觉特征提取的耗时很长 #2604
Comments
哈喽 下午好!
非常感谢你的解答,我这边把x.cpu()注释掉以后 vit的处理时间还是很慢呢,还是要300ms左右。不知道你那边注释了以后推理速度怎么样呢
丰
***@***.***
…------------------ 原始邮件 ------------------
发件人: "InternLM/lmdeploy" ***@***.***>;
发送时间: 2024年10月23日(星期三) 下午2:48
***@***.***>;
***@***.******@***.***>;
主题: Re: [InternLM/lmdeploy] [Bug] InternVL2-2B的推理速度慢,发现是视觉特征提取的耗时很长 (Issue #2604)
嗨,我也发现了类似的问题,我这边简单分析了下,lmdeploy比vllm在vit部分平均增加的耗时是由于lmdeploy需要将vit的feature遍历从gpu到cpu,也就是下面图中的x.cpu()引起的
image.png (view on web)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
但是这里虽然是去掉了to cpu时间,后面还是会进行gpu到cpu同步的,lmdeploy逻辑是这样实现的 |
所以是lmdeploy这里即便注释掉tocpu()了,后面还是会进行GPU到CPU的同步是吗,就是整体的时间哈还是不会减少吗 |
@irexyc 我测了vision model的单纯GPU计算feature的时间和vllm是差不多的,但是在VLAsyncEngine类的_get_prompt_input中统计features = await self.vl_encoder.async_infer(images)的时间会比vllm慢很多,导致实际测下来的推理速度比vllm慢 |
@fong-git 我这边实测在tp均为4的情况下,lmdeploy比vllm慢500ms左右,feature推理时间基本一致,问题就在于to cpu这部分,vllm是直接把GPU 的torch tensor传入后续流程的:
|
@irexyc @fong-git 是的,lmdeploy的to cpu 是不能缺少的,就像 @Dimensionzw 说的那样,lmdeploy和vllm的架构设计有区别的,lmdeploy更多的是在上层进行模版拼接、特征提取等工作,最后把这些inputs信息传递到turomind backend端进行处理。而且像 @irexyc 说的,后面的prefix caching等,也可能会使用内存、甚至硬盘来存储特征信息,进而优化显存的占用,这些都是需要to cpu操作的 |
Checklist
Describe the bug
使用Transformer、vllm、LMdeploy对InternVL2-2B进行推理,max_num_patch都设置为12,推理结果发现:
Transformer平均691ms/条
VLLM平均308ms/条
LMdeploy平均523ms/条
对VLLM和LMdeploy耗时进行分析发现,vllm的vit部分平均耗时9ms,LMdeploy的vit部分平均耗时323ms。
LMdeploy的vit统计时间在VLAsyncEngine类的_get_prompt_input中统计``
Reproduction
from lmdeploy import pipeline, TurbomindEngineConfig, PytorchEngineConfig
from lmdeploy.vl import load_image
import os
import time
PROMPT_SYSTEM = """
根据图片,判断该文档所属的文档类别。 请严格按照如下的格式进行回复,不要输出多余的解释(注意不要强行给文档分一个不正确的类别:对于不属于特定类别的文档,判别为‘其他文档’):
文档类别:该文档所属的文档类别
"""
model = 'model/OpenGVLab/InternVL2-1B'
model = 'model/OpenGVLab/InternVL2-2B'
pipe = pipeline(model, backend_config=TurbomindEngineConfig(session_len=8192,model_format='hf'))
img_path = './cs_function_recommendation_bak/test_data/image'
imgs = os.listdir(img_path)
totle_time = 0
vit_time_total =0
for img in imgs[:100]:
image = load_image(os.path.join(img_path,img))
print(vit_time_total)
print(totle_time)
Environment
Error traceback
No response
The text was updated successfully, but these errors were encountered: