-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
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) |
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
|
@yyihuang Please fix the DCO issue (i.e. run git commit with |
Signed-off-by: Avery Yingyi Huang <[email protected]>
Signed-off-by: Avery Yingyi Huang <[email protected]>
Signed-off-by: Avery Yingyi Huang <[email protected]>
963518a
to
1a3a34e
Compare
@nvpohanh I re-committed and DCO should pass now. Thank you! |
<!-- .github/pull_request_template.md --> ## 📌 Description The duplicate zero_init should be fixed. But we got some crash reported from DLFW. So we revert it in #1459 and make 0.2.11.post1. After this fix, **workspace buffer passed into any trtllm-gen attn interface must be zero-initialized**. This PR is to enable this optimization. It should be merged and released only after these two are tested. - sgl-project/sglang#9065 - vllm-project/vllm#22603 ## 🔍 Related Issues <!-- Link any related issues here --> ## 🚀 Pull Request Checklist Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete. ### ✅ Pre-commit Checks - [ ] I have installed `pre-commit` by running `pip install pre-commit` (or used your preferred method). - [ ] I have installed the hooks with `pre-commit install`. - [ ] I have run the hooks manually with `pre-commit run --all-files` and fixed any reported issues. > If you are unsure about how to set up `pre-commit`, see [the pre-commit documentation](https://pre-commit.com/). ## 🧪 Tests - [ ] Tests have been added or updated as needed. - [ ] All tests are passing (`unittest`, etc.). ## Reviewer Notes <!-- Optional: anything you'd like reviewers to focus on, concerns, etc. -->
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
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.
Looks good to me, thanks for the work!
CI error doesn't seem to be caused by this change |
…m-project#22603) Signed-off-by: Yiwen Chen <[email protected]>
…m-project#22603) Signed-off-by: Duncan Moss <[email protected]>
…m-project#22603) Signed-off-by: Boyuan Feng <[email protected]>
…m-project#22603) Signed-off-by: Xiao Yu <[email protected]>
…m-project#22603) Signed-off-by: Xiao Yu <[email protected]>
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.Purpose
flashinfer v0.2.11.post3 updates: flashinfer-ai/flashinfer#1463
cc @elvischenv
Test Plan
Test Result
(Optional) Documentation Update