-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[Kernel] Add Fused Layernorm + Dynamic-Per-Token Quant Kernels #6763
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] Add Fused Layernorm + Dynamic-Per-Token Quant Kernels #6763
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 |
3642313 to
c505155
Compare
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.
Left some in-line comments. I see some potential issues with using int for large activations that will need to be resolved. Along those lines, I thing being explicit about using int32_t instead of int will improve things.
csrc/quantization/fused_kernels/fused_layernorm_dynamic_per_token_quant.cu
Outdated
Show resolved
Hide resolved
| __device__ void compute_rms(float* rms, scalar_t const* __restrict__ input, | ||
| int const hidden_size, float const epsilon, | ||
| scalar_t const* __restrict__ residual = nullptr) { | ||
| int const token_offset = blockIdx.x * hidden_size; |
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.
this should be an int64_t
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.
Thanks for catching this. Updated the ints to int32_t / int64_t 👍
| template <typename scalar_t, typename quant_type_t, bool is_scale_inverted> | ||
| __device__ void scaled_quant_conversion(quant_type_t* __restrict__ output, | ||
| scalar_t const* __restrict__ input, | ||
| float const scale, int const tid, | ||
| int const num_elements, | ||
| int const step) { | ||
| for (int i = tid; i < num_elements; i += step) { | ||
| output[i] = ScaledQuant<quant_type_t, is_scale_inverted>(input[i], scale); | ||
| } | ||
| } | ||
|
|
||
| namespace vectorized { | ||
|
|
||
| // Vectorized version of scaled_quant_conversion | ||
| template <typename scalar_t, typename quant_type_t, bool is_scale_inverted> | ||
| __device__ void scaled_quant_conversion(quant_type_t* __restrict__ out, | ||
| scalar_t const* __restrict__ input, | ||
| float const scale, int const tid, | ||
| int const num_elems, int const step) { |
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.
Are these functions used anywhere?
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.
No. it isn't yet. I plan to use them in the static-per-tensor case. On second thought, let me remove it from here and introduce it in static-per-tensor PR.
|
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 pull request has merge conflicts that must be resolved before it can be |
|
@varun-sundar-rabindranath close in favor of #10906 ? |
|
close in favor of #10906 . Thanks @ProExpertProg |
Add Fused Layernorm + Dynamic-Per-Token Quant kernels.
Numbers:
Take away: The fused kernels out perform the unfused counterparts. It is important to note that we don't yet know how much performance gain is actually coming from the fusion (the fused kernels have vectorization optimizations that are not necessarily in their unfused counterparts).
GPU : A6000 x 1
Command:
python3 benchmarks/fused_kernels/layernorm_rms_benchmarks.py<style type="text/css"></style>
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,LLMclass, 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.shto 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-requiredand 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-requiredlabel 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!