-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[perf] Use CPU tensor to reduce GPU->CPU sync #25884
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
Conversation
Signed-off-by: Lehua Ding <lehuading@tencent.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a performance optimization to reduce GPU-to-CPU synchronization during speculative decoding. The change replaces a call to .max()
on a GPU tensor (seq_lens
) with its CPU counterpart (seq_lens_cpu
) within a conditional check. This avoids a blocking operation, which is particularly beneficial for asynchronous scheduling. The change is correct and aligns with the stated goal of improving performance. I have no further comments.
Which introduce by this pr(#24662), @AlonKejzman can you help review this too? thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
vllm/v1/worker/gpu_model_runner.py
Outdated
self.speculative_config.draft_model_config.max_model_len) | ||
input_fits_in_drafter = spec_decode_common_attn_metadata and ( | ||
spec_decode_common_attn_metadata.seq_lens.max() + | ||
spec_decode_common_attn_metadata.seq_lens_cpu.max() + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use .max_seq_len
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, and it is simpler! spec_decode_common_attn_metadata.max_seq_len
is cmoputed from self.seq_lens.np[:num_reqs].max().item()
, they are equivalent.
Signed-off-by: Lehua Ding <lehuading@tencent.com>
Signed-off-by: Lehua Ding <lehuading@tencent.com>
Signed-off-by: Lehua Ding <lehuading@tencent.com> Signed-off-by: yewentao256 <zhyanwentao@126.com>
Use
seq_lens_cpu
instead ofseq_lens
to reduce GPU->CPU sync.Purpose
Reduce unnecessary GPU->CPU sync, since it will affect the perf of Async Scheduling+MTP.

Test Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.