-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
base: main
Are you sure you want to change the base?
Use w8a8 quantized matmul Pallas kernel #19170
Conversation
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
Signed-off-by: Xiongfei Wei <isaacwxf23@gmail.com>
👋 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_int8
for w8a8 scaled matrix multiplication within the XLA quantization kernel implementation. This replaces a previous, more generalquantized_matmul
call. - 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_ARGS
environment variable setting in the TPU worker initialization.
Changelog
- tests/v1/tpu/test_basic.py
- Added a new test
test_w8a8_quantization
to 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_kernel
required for registering custom XLA ops. - Replaced the call to
torch.ops.xla.quantized_matmul
withtorch.ops.xla.quantized_matmul_int8
for w8a8 scaled matrix multiplication. - Commented out the old
quantized_matmul
implementation.
- Added import
- vllm/v1/worker/tpu_worker.py
- Commented out the XLA compiler flag
--xla_jf_conv_input_fusion=False
fromLIBTPU_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.dtype
was removed. It's important to confirm the output dtype of the newtorch.ops.xla.quantized_matmul_int8
op 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_quantization
intests/v1/tpu/test_basic.py
is identical to a more generic test. It could be strengthened to be more specific tow8a8
quantization. - 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_int8
regarding 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_quantization
more 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.
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.
Essential Elements of an Effective PR Description Checklist
Purpose
Test Plan
Test Result