Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yyihuang
Copy link

@yyihuang yyihuang commented Aug 10, 2025

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Purpose

flashinfer 0.2.11 updates: flashinfer-ai/flashinfer#1444

cc @elvischenv

Test Plan

Test Result

(Optional) Documentation Update

Copy link

👋 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 fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

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 ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added the v1 label Aug 10, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]>
@yyihuang yyihuang force-pushed the init_zero_workspace branch from fc85b03 to 2f56b6a Compare August 10, 2025 21:08
@@ -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(
Copy link
Contributor

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

Copy link
Author

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!

Copy link
Author

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.

@yyihuang yyihuang marked this pull request as ready for review August 11, 2025 22:09
@IwakuraRein
Copy link
Contributor

I have tested this pr on b200 and benchmarks/benchmark_serving.py passed with flashinfer-ai/flashinfer#1463. Arguments:

python3 ./benchmarks/benchmark_serving.py --model gpt-oss-120b --dataset-name random --ignore-eos --num-prompts 12288 --random-input-len 1024 --random-output-len 1024 --max-concurrency 4096

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants