Skip to content

[Perf]:Optimize qwen2-vl to reduce cudaMemcpyAsync #14377

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

Merged
merged 5 commits into from
Mar 11, 2025

Conversation

cynthieye
Copy link
Contributor

@cynthieye cynthieye commented Mar 6, 2025

qwen2-vl logic optimization: During each forward propagation, the xformer branch of Qwen2VisionTransformer will execute multiple tensor tolist methods (flash attn branch will execute multiple tensor items) to force the GPU tensor to be copied to the CPU, triggering CUDAMemcpyAsync to increase time consumption. Since the input and output are the same multiple times, it will be executed once, and the remaining will reuse the first result. After optimization, the online environment xformer branch QPS can be improved by 15%, and the flash attn branch QPS can be improved by 7%

Copy link
Collaborator

@Isotr0py Isotr0py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this optimization! Can you please also update qwen2.5-vl as well?

@cynthieye cynthieye changed the title feat:Optimize qwen2-vl to reduce cudaMemcpyAsync [Perf]:Optimize qwen2-vl to reduce cudaMemcpyAsync Mar 10, 2025
@cynthieye cynthieye force-pushed the main branch 3 times, most recently from ae09649 to 1fbb69c Compare March 10, 2025 06:53
@Isotr0py Isotr0py enabled auto-merge (squash) March 10, 2025 09:50
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Mar 10, 2025
auto-merge was automatically disabled March 10, 2025 13:26

Head branch was pushed to by a user without write access

Signed-off-by: cynthieye <987073381@qq.com>
Signed-off-by: cynthieye <987073381@qq.com>
@ywang96
Copy link
Member

ywang96 commented Mar 11, 2025

@cynthieye Thank you for making this PR! Can you update this branch with our main branch? I think thr CI error should be fixed on main a while ago.

Copy link
Member

@ywang96 ywang96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments - Otherwise LGTM!

@@ -259,6 +259,8 @@ def forward(
x: torch.Tensor,
cu_seqlens: torch.Tensor,
rotary_pos_emb: torch.Tensor,
max_seqlen: int = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't max_seqlen be also Optional[int]?

Comment on lines 372 to 373
max_seqlen: int,
seqlens: list[int],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify the typing accordingly

Comment on lines 310 to 311
max_seqlen: int = None,
seqlens: Optional[list[int]] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines 417 to 418
max_seqlen: int,
seqlens: list[int],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines 372 to 373
max_seqlen: int,
seqlens: list[int],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably a good idea to add a small documentation here to indicate that max_seqlen is only used for FA and seqlens is only used to xformers.

Signed-off-by: cynthieye <987073381@qq.com>
Signed-off-by: cynthieye <987073381@qq.com>
@ywang96 ywang96 enabled auto-merge (squash) March 11, 2025 06:25
@ywang96 ywang96 merged commit 70b808f into vllm-project:main Mar 11, 2025
33 checks passed
lulmer pushed a commit to lulmer/vllm that referenced this pull request Apr 7, 2025
Signed-off-by: cynthieye <987073381@qq.com>
Signed-off-by: Louis Ulmer <ulmerlouis@gmail.com>
shreyankg pushed a commit to shreyankg/vllm that referenced this pull request May 3, 2025
RichardoMrMu pushed a commit to RichardoMrMu/vllm that referenced this pull request May 12, 2025
Signed-off-by: cynthieye <987073381@qq.com>
Signed-off-by: Mu Huai <tianbowen.tbw@antgroup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants