Skip to content

[perf] Avoid dtype promotion sync in mamba_get_block_table_tensor#34870

Merged
vllm-bot merged 3 commits intovllm-project:mainfrom
hl475:linear_attn
Feb 20, 2026
Merged

[perf] Avoid dtype promotion sync in mamba_get_block_table_tensor#34870
vllm-bot merged 3 commits intovllm-project:mainfrom
hl475:linear_attn

Conversation

@hl475
Copy link
Contributor

@hl475 hl475 commented Feb 19, 2026

Purpose

From the perf profiling on a model using linear attention, one thing draws the attention is aten::to from somewhere in vllm gpu_model_runner preprocess

image

For this aten::to,
image

We can tell it is doing to with dtype=3 (int64)

With CC's help, we found it is from mamba_get_block_table_tensor

  • start_indices is int32
  • offsets is int64
  • indices_to_gather = start_indices.unsqueeze(1) + offsets will perform int32+int64 and sync

Now we made offsets as int32 as well, and then no sync.

With the change, new profiling looks much better

image

Test Plan

Test Result


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.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Signed-off-by: Huamin Li <3ericli@gmail.com>
@hl475 hl475 marked this pull request as draft February 19, 2026 04:22
@mergify mergify bot added the v1 label Feb 19, 2026
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 introduces a performance optimization within the mamba_get_block_table_tensor function. The change modifies the creation of the offsets tensor to use torch.int32, which avoids a dtype promotion to int64 during the subsequent addition operation. The final result is then explicitly cast to torch.int64 to meet the requirements of torch.gather. This is a sound optimization that should reduce overhead as intended. The implementation appears correct and I found no issues.

@hl475 hl475 changed the title [WIP] mamba_get_block_table_tensor [perf] Avoid dtype promotion sync in mamba_get_block_table_tensor Feb 19, 2026
@hl475 hl475 marked this pull request as ready for review February 19, 2026 04:36
Copy link
Collaborator

@heheda12345 heheda12345 left a comment

Choose a reason for hiding this comment

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

Nice finding! Thanks for your contribution.

@heheda12345 heheda12345 enabled auto-merge (squash) February 19, 2026 04:44
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Feb 19, 2026
@hl475
Copy link
Contributor Author

hl475 commented Feb 19, 2026

CI failures are probably from #33600

@hl475
Copy link
Contributor Author

hl475 commented Feb 20, 2026

failure from entrypoints/openai/responses/test_harmony.py::test_mcp_code_interpreter_streaming[openai/gpt-oss-20b] should not be relevant - https://buildkite.com/organizations/vllm/analytics/suites/ci-1/tests/e82e9b97-3f4c-89ab-933c-7e077bedf38c?branch=main&query=test_mcp_code_interpreter_streaming is red since yesterday.

@vllm-bot vllm-bot merged commit 1fe4621 into vllm-project:main Feb 20, 2026
52 of 54 checks passed
DarkLight1337 added a commit to DarkLight1337/vllm that referenced this pull request Feb 21, 2026
…lm-project#34870)

Signed-off-by: Huamin Li <3ericli@gmail.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
yugong333 pushed a commit to yugong333/vllm that referenced this pull request Feb 22, 2026
…lm-project#34870)

Signed-off-by: Huamin Li <3ericli@gmail.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
jmamou pushed a commit to jmamou/vllm that referenced this pull request Feb 23, 2026
…lm-project#34870)

Signed-off-by: Huamin Li <3ericli@gmail.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
llsj14 pushed a commit to llsj14/vllm that referenced this pull request Mar 1, 2026
…lm-project#34870)

Signed-off-by: Huamin Li <3ericli@gmail.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
tunglinwood pushed a commit to tunglinwood/vllm that referenced this pull request Mar 4, 2026
…lm-project#34870)

Signed-off-by: Huamin Li <3ericli@gmail.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
askliar pushed a commit to askliar/vllm that referenced this pull request Mar 9, 2026
…lm-project#34870)

Signed-off-by: Huamin Li <3ericli@gmail.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
Signed-off-by: Andrii Skliar <askliar@nvidia.com>
Copilot AI pushed a commit to machov/vllm that referenced this pull request Mar 10, 2026
…lm-project#34870)

Signed-off-by: Huamin Li <3ericli@gmail.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
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.

4 participants