-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Kernel] Replaced blockReduce[...]
functions with cub::BlockReduce
#7233
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:
🚀 |
/ready |
cc @WoosukKwon |
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.
Nice cleanup, thanks!
@ProExpertProg could you check if the kernels-test-3 failure is related to your changes? |
Would appreciate a link to this suggestion/discussion if it's public! Is there a reason why this is done? The runtime dispatch for block sizes was done for performance reasons: smaller block sizes allow better block occupancy on CUs for memory latency hiding during the prefill phase (or from a more agnostic view: when
Out of curiosity, what bugs have you seen? |
@mawong-amd there were a few bugs:
We still use a smaller block size, we just have a single block reduction size as opposed to 2 separate ones which will still take up the same amount of shared memory space (because we pick between them at kernel runtime). See If we care about the size of shared memory in the kernel, I can add a template parameter so we can avoid the branch and specialize. |
The kernels are still being launched based on this but @ProExpertProg just removed templating 2 separate block reduce implementations and runtime dispatching between those here, with cub both those cases can be handle but just correctly setting
in this case x could non-deterministically contain incorrect an result since the
but its hard to for a user to know that Also just from software engineering perspective I think it makes sense for use to leverage hardened Nvidia implementations of common routines when possible. (as a bonus we benefit from their docs, which in this case would explain the need for sync threads: https://nvidia.github.io/cccl/cub/developer_overview.html#id5) |
Great catch!
Coincidentally I thought about this a few weeks ago while reviewing code, but I eventually reasoned that Edit: Ahhh you mean clashes between different calls in the same kernel. Apologies! Yes, that's a bit unexpected and it makes sense to be more explicit about its shared memory use. |
I see! I'm not too familiar with CUB, but in that case, this removal makes sense.
I agree completely. I believe there are still a few places in vLLM where people implement their own unoptimized |
@mawong-amd if you point me to those places I'd be happy to consolidate and try to replace them in this PR (or another) if we want to do that. |
blockReduce[...]
functions with cub::BlockReduce
blockReduce[...]
functions with cub::BlockReduce
@tlrmchlsmth I checked and |
3c7aa91
to
b094d97
Compare
@ProExpertProg could you share some performance numbers with the benchmark you wrote? |
Yep, sorry, took a little longer than expected. Here are the results of the layernorm and quant microbenchmarks. The summary is that the cub version is (geomean) 0.2% faster for layernorm and 1.3% slower for quant, but that's most likely just noise. That's because different shapes & dtypes produce vastly different ratios of the |
acd0e8a
to
633f626
Compare
633f626
to
5aa2869
Compare
vllm-project#7233) Co-authored-by: Michael Goin <[email protected]>
vllm-project#7233) Co-authored-by: Michael Goin <[email protected]> Signed-off-by: Alvant <[email protected]>
vllm-project#7233) Co-authored-by: Michael Goin <[email protected]>
Replace all uses of the custom (and buggy) blockReduce function with the idiomatic cub::BlockReduce.
I also removed the runtime dispatching for block sizes per @LucasWilkinson's suggestion.
Here are the results of the layernorm and quant microbenchmarks.
The summary is that the cub version is (geomean) 0.2% faster for layernorm and 1.3% slower for quant, but that's most likely just noise. That's because different shapes & dtypes produce vastly different ratios of the
cub
andmain
runtimes. And there don't seem to be any patterns.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!