Skip to content

Conversation

yyihuang
Copy link
Contributor

@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 v0.2.11.post3 updates: flashinfer-ai/flashinfer#1463

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)

@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
Contributor 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
Contributor 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 draft August 11, 2025 08:36
@yyihuang yyihuang force-pushed the init_zero_workspace branch from 3d73616 to 2f56b6a Compare August 11, 2025 21:16
@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

@nvpohanh
Copy link
Contributor

@yyihuang Please fix the DCO issue (i.e. run git commit with -s flag)

Signed-off-by: Avery Yingyi Huang <[email protected]>
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 963518a to 1a3a34e Compare August 13, 2025 06:39
@yyihuang yyihuang requested a review from yewentao256 as a code owner August 13, 2025 06:39
@yyihuang
Copy link
Contributor Author

@nvpohanh I re-committed and DCO should pass now. Thank you!

yzh119 pushed a commit to flashinfer-ai/flashinfer that referenced this pull request Aug 13, 2025
<!-- .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.
-->
Copy link
Member

@mgoin mgoin left a comment

Choose a reason for hiding this comment

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

LGTM

@mgoin mgoin enabled auto-merge (squash) August 13, 2025 12:45
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 13, 2025
Copy link
Collaborator

@yewentao256 yewentao256 left a 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!

@nvpohanh
Copy link
Contributor

CI error doesn't seem to be caused by this change

@mgoin mgoin merged commit 1723ef1 into vllm-project:main Aug 15, 2025
40 of 41 checks passed
666even666 pushed a commit to 666even666/vllm that referenced this pull request Aug 18, 2025
juuice-lee pushed a commit to juuice-lee/vllm-moe.code that referenced this pull request Aug 18, 2025
divakar-amd pushed a commit to divakar-amd/vllm_upstream that referenced this pull request Aug 20, 2025
djmmoss pushed a commit to djmmoss/vllm that referenced this pull request Aug 21, 2025
BoyuanFeng pushed a commit to BoyuanFeng/vllm that referenced this pull request Aug 21, 2025
xiao-llm pushed a commit to xiao-llm/vllm that referenced this pull request Aug 28, 2025
xiao-llm pushed a commit to xiao-llm/vllm that referenced this pull request Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed v1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants