-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
minor: zero workspace buffer init for flashinfer trtllm-gen attn #22603
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?
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.
Code Review
This pull request addresses a critical correctness issue by initializing the FlashInfer workspace buffer with zeros using torch.zeros
instead of torch.empty
. This is necessary for the proper functioning of the TensorRT-LLM attention kernels in FlashInfer. The change is applied correctly in both the core library code and the test suite. My review includes suggestions to align the data type of the workspace buffer in the tests with the main implementation (torch.uint8
) to ensure consistency and prevent potential data interpretation bugs.
@@ -113,7 +113,7 @@ def test_flashinfer_trtllm_decode_with_baseline( | |||
kv_indices = torch.tensor(kv_indices, dtype=torch.int32) | |||
kv_last_page_lens = torch.tensor(kv_last_page_lens, dtype=torch.int32) | |||
|
|||
workspace_buffer = torch.empty(128 * 1024 * 1024, dtype=torch.int8) | |||
workspace_buffer = torch.zeros(128 * 1024 * 1024, dtype=torch.int8) |
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 workspace buffer is created with torch.int8
dtype, while the main implementation in vllm/v1/attention/backends/flashinfer.py
uses torch.uint8
. While this might not cause issues with a zero-initialized buffer, using an inconsistent data type can lead to subtle bugs if the underlying kernel has specific expectations about the data being signed or unsigned. For consistency and to prevent potential correctness issues, it's recommended to use torch.uint8
here.
workspace_buffer = torch.zeros(128 * 1024 * 1024, dtype=torch.int8) | |
workspace_buffer = torch.zeros(128 * 1024 * 1024, dtype=torch.uint8) |
@@ -247,7 +247,7 @@ def test_flashinfer_trtllm_prefill_with_baseline( | |||
kv_indices = torch.tensor(kv_indices, dtype=torch.int32) | |||
kv_last_page_lens = torch.tensor(kv_last_page_lens, dtype=torch.int32) | |||
|
|||
workspace_buffer = torch.empty(128 * 1024 * 1024, dtype=torch.int8) | |||
workspace_buffer = torch.zeros(128 * 1024 * 1024, dtype=torch.int8) |
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 workspace buffer here is created with torch.int8
, which is inconsistent with the torch.uint8
used in the main implementation. To ensure consistency across the codebase and avoid potential issues related to signed versus unsigned byte interpretation by the FlashInfer kernel, it is advisable to use torch.uint8
for this buffer as well.
workspace_buffer = torch.zeros(128 * 1024 * 1024, dtype=torch.int8) | |
workspace_buffer = torch.zeros(128 * 1024 * 1024, dtype=torch.uint8) |
Signed-off-by: Avery Yingyi Huang <[email protected]>
Signed-off-by: Avery Yingyi Huang <[email protected]>
fc85b03
to
2f56b6a
Compare
@@ -251,7 +251,7 @@ def __init__(self, kv_cache_spec: AttentionSpec, layer_names: list[str], | |||
|
|||
def _get_workspace_buffer(self): | |||
if self._workspace_buffer is None: | |||
self._workspace_buffer = torch.empty( | |||
self._workspace_buffer = torch.zeros( |
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.
Also need to update in vllm/attention/backends/flashinfer.py
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.
Updated. Thanks for your review!
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.
Sorry for accidentally pushing to another PR. It's added now.
3d73616
to
2f56b6a
Compare
I have tested this pr on b200 and
|
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.Purpose
flashinfer 0.2.11 updates: flashinfer-ai/flashinfer#1444
cc @elvischenv
Test Plan
Test Result
(Optional) Documentation Update