-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
[Core] More-efficient cross-attention parallel QKV computation #7448
base: main
Are you sure you want to change the base?
[Core] More-efficient cross-attention parallel QKV computation #7448
Conversation
👋 Hi! Thank you for contributing to the vLLM project. Once the PR is approved and ready to go, please make sure to run full CI as it is required to merge (or just use auto-merge). To run full CI, you can do one of these:
🚀 |
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. Left a couple of small comments. Thanks for the pr.
@@ -303,7 +304,7 @@ def __init__( | |||
f" and `num_heads`: {num_heads}).") | |||
self.scaling = self.head_dim**-0.5 | |||
|
|||
self.qkv_proj = QKVParallelLinear( | |||
self.qkv_proj = QCrossKVParallelLinear( |
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.
Was wondering if in the encoder-decode e2e test (e.g. test_bart.py) did you observe any increase in the input token/s or the output token/s with this change?
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.
Good question. I ran a very informal test to prove to myself that QCrossKVParallelLinear improved the total runtime of the encoder/decoder example script. I should run an actual benchmark in order compare tokens/s
Perf test:Server:Note the use of eager mode & the lack of tensor-/pipeline-parallelism. The key change in
Client:
Testbench:
Baseline perf benchmark result (main, 029c71d)
PR branch result (after merging in 029c71d)
|
Based on the benchmarks it is not clear this change improves performance. |
I'm trying And I have a question: as you compute q_output_parallel = self._apply_w_conditional_bias(
self._cached_q_weights_wrapper, decoder_input_,
self._cached_q_bias)
kv_output_parallel = None if is_decode_phase else (
self._apply_w_conditional_bias(self._cached_kv_weights_wrapper,
encoder_input_,
self._cached_kv_bias)) |
This pull request has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this pull request should remain open. Thank you! |
This PR makes QKV computation more efficient in the case of cross-attention layers.
QKVParallelLinear
only performs self-attention QKV computation against a single hidden-state input from the previous decoder layer.Cross-attention requires Q to be computed from the previous decoder layer output hidden state, and KV to be computed from the encoder output hidden state. Additionally,
The current, inefficient workaround is to construct a
QKVParallelLinear
layer & apply it up to twice, once todecoder_hidden_states
to obtain Q, and (only during prefill) a second time toencoder_hidden_states
to obtain KV:This PR introduces a cross-attention QKV parallel linear layer with the following characteristics
QKVParallelLinear
forward()
takes a decoder hidden states argument, and an optional encoder hidden states argumentforward()
always computesforward()
computesNone
The forward method of this new QKV parallel linear layer will return:
The cross-attention layer will construct this new QKV parallel linear layer in
__init__()
as followsand then compute Q,K,V in
forward()
as followsNote:
tests/models/test_bart
serves as an end-to-end encoder/decoder model test, implicitly testingQCrossKVParallelLinear
FIX #7397 (link existing issues this PR will resolve)
BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
PR Checklist (Click to Expand)
Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]
for bug fixes.[CI/Build]
for build or continuous integration improvements.[Doc]
for documentation fixes and improvements.[Model]
for adding a new model or improving an existing model. Model name should appear in the title.[Frontend]
For changes on the vLLM frontend (e.g., OpenAI API server,LLM
class, etc.)[Kernel]
for changes affecting CUDA kernels or other compute kernels.[Core]
for changes in the core vLLM logic (e.g.,LLMEngine
,AsyncLLMEngine
,Scheduler
, etc.)[Hardware][Vendor]
for hardware-specific changes. Vendor name should appear in the prefix (e.g.,[Hardware][AMD]
).[Misc]
for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
format.sh
to format your code.docs/source/
if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.Notes for Large Changes
Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with
rfc-required
and might not go through the PR.What to Expect for the Reviews
The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:
action-required
label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.Thank You
Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!