-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Use w8a8 quantized matmul Pallas kernel #19170
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
Use w8a8 quantized matmul Pallas kernel #19170
Conversation
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
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.
Hello @vanbasten23, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello team, gemini-code-assist here to provide a summary of this pull request. This PR, titled "Use w8a8 quantized matmul Pallas kernel", focuses on integrating a specific optimized kernel for 8-bit weight and 8-bit activation (w8a8) quantization on XLA/TPU platforms. The primary change involves switching the underlying matrix multiplication operation used for scaled quantization from a generic quantized_matmul to a more specific quantized_matmul_int8 kernel, likely a Pallas kernel as indicated by the title, which is intended for w8a8 operations. Additionally, a new test case is added to specifically verify the functionality of running a w8a8 quantized model on TPU, ensuring the new kernel is correctly utilized and produces expected results. A minor adjustment is also made to the XLA runtime initialization arguments.
Highlights
- TPU W8A8 Quantization Kernel: The core change is the adoption of
torch.ops.xla.quantized_matmul_int8for w8a8 scaled matrix multiplication within the XLA quantization kernel implementation. This replaces a previous, more generalquantized_matmulcall. - W8A8 Test Case: A new test function,
test_w8a8_quantization, is added totests/v1/tpu/test_basic.py. This test loads a specific w8a8 quantized Llama model and performs a basic generation to validate the integration of the new kernel and overall w8a8 support on TPU. - XLA Runtime Configuration: A previously included XLA compiler flag,
--xla_jf_conv_input_fusion=False, is commented out from theLIBTPU_INIT_ARGSenvironment variable setting in the TPU worker initialization.
Changelog
- tests/v1/tpu/test_basic.py
- Added a new test
test_w8a8_quantizationto verify running w8a8 quantized models on TPU. - The new test loads a specific w8a8 quantized Llama model and performs a basic generation check.
- Added a new test
- vllm/model_executor/layers/quantization/kernels/scaled_mm/xla.py
- Added import
torch_xla.experimental.custom_kernelrequired for registering custom XLA ops. - Replaced the call to
torch.ops.xla.quantized_matmulwithtorch.ops.xla.quantized_matmul_int8for w8a8 scaled matrix multiplication. - Commented out the old
quantized_matmulimplementation.
- Added import
- vllm/v1/worker/tpu_worker.py
- Commented out the XLA compiler flag
--xla_jf_conv_input_fusion=FalsefromLIBTPU_INIT_ARGS.
- Commented out the XLA compiler flag
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Weights shrink down to eight,
Activations match their state,
TPU runs fast,
Quantization lasts,
Inference sealed by fate.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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 the use of a w8a8 quantized matmul Pallas kernel for XLA, which is a good step towards optimizing performance on TPUs. A new test case for w8a8 quantization has also been added.
However, the pull request description is currently a template and needs to be filled out with the purpose, test plan, and test results. This information is crucial for understanding the changes and their impact.
There are a couple of areas in the code that would benefit from clarification or minor improvements, detailed in the comments below.
Summary of Findings
- Missing Pull Request Description: The pull request description is currently a template and lacks essential information such as the purpose of the PR, test plan, and test results. This information is vital for reviewers and future maintainers.
- Output Dtype of New XLA Matmul Op: In
vllm/model_executor/layers/quantization/kernels/scaled_mm/xla.py, the explicit cast of the output tensor tox.dtypewas removed. It's important to confirm the output dtype of the newtorch.ops.xla.quantized_matmul_int8op and ensure that this removal doesn't negatively impact performance or type consistency downstream. - Test Assertion Specificity: The assertion in the new test
test_w8a8_quantizationintests/v1/tpu/test_basic.pyis identical to a more generic test. It could be strengthened to be more specific tow8a8quantization. - Commented-out Code: In
vllm/v1/worker/tpu_worker.py, there's a commented-out line forLIBTPU_INIT_ARGS(lines 102-104). This seems like leftover experimental code and should ideally be removed for clarity. (Severity: low, not commented due to review settings)
Merge Readiness
This pull request makes a targeted change to use a new Pallas kernel for w8a8 quantization on TPUs and adds a corresponding test. However, before merging, it's important to address the following:
- Fill out the Pull Request Description: Provide details on the purpose, testing, and results.
- Clarify Output Dtype: Confirm the behavior of
torch.ops.xla.quantized_matmul_int8regarding its output data type and the necessity (or lack thereof) of casting it, as this could impact correctness or performance. - Improve Test Assertion: Consider making the assertion in
test_w8a8_quantizationmore specific to the quantization being tested.
Due to the potential impact of the dtype question (high severity) and the missing PR description, I recommend addressing these points before merging. I am unable to approve pull requests, so please ensure other reviewers take a look and approve once these concerns are addressed.
| out = torch.ops.xla.quantized_matmul_int8( | ||
| x, | ||
| w_q, | ||
| w_s, | ||
| quantize_activation=True, | ||
| ) |
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.
The previous implementation using torch.ops.xla.quantized_matmul included a cast out = out.to(x.dtype) with the comment "quantized_matmul output is fp32, cast it down to bf16 for perf".
What is the output data type of the new torch.ops.xla.quantized_matmul_int8? If it also outputs in a higher precision (e.g., fp32) and x.dtype is a lower precision format like bfloat16, is a similar cast to x.dtype still necessary for performance or type consistency with subsequent layers? If the new op already handles this or outputs directly in x.dtype, then this change is fine.
tests/v1/tpu/test_basic.py
Outdated
| max_tokens) | ||
| output = vllm_outputs[0][1] | ||
|
|
||
| assert "1024" in output or "0, 1" in output |
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.
The assertion assert "1024" in output or "0, 1" in output is the same as in the test_basic function. For a test specifically targeting w8a8 quantization, could this assertion be made more specific to validate the correctness of the quantization itself? For example, comparing against known good outputs for this quantized model or checking for specific numerical properties might provide stronger validation.
cab307d to
c6d0225
Compare
vllm/model_executor/layers/quantization/kernels/scaled_mm/xla.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
e4f6dcf to
e1be425
Compare
|
The failing CI is test_sampler.py and the failure is |
yaochengji
left a comment
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!
Head branch was pushed to by a user without write access
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com> Signed-off-by: x22x22 <wadeking@qq.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com> Signed-off-by: Jinzhen Lin <linjinzhen@hotmail.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com> Signed-off-by: Paul Pak <paulpak58@gmail.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com> Signed-off-by: Diego-Castan <diego.castan@ibm.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
Essential Elements of an Effective PR Description Checklist
Purpose
This PR uses a custom Pallas kernel to do w8a8 quantized matmul in lieu of XLA's matmul. This results in much better performance for w8a8 models:
by using neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w8a8 with TP=1 and RedHatAI/Meta-Llama-3.1-70B-Instruct-quantized.w8a8 with TP=8, I got the following e2e benchmark:
Test Plan
Test Result
Note, need to install
lm-eval==0.4.8. Without specifying the version, lm-eval=0.4.9 will be installed and runningtest_quantization_accuracy.pyfails with an error