[Bugfix] Fix batch-invariant fp32 matmul OOR on SM89 for N=1 - #52960
Merged
DarkLight1337 merged 3 commits intoAug 21, 2026
Merged
Conversation
Signed-off-by: Juqi Li <2223621784@qq.com>
yewentao256
reviewed
Aug 20, 2026
| @@ -174,10 +174,10 @@ def grid(META): | |||
| }, | |||
| torch.float32: { | |||
| "BLOCK_SIZE_M": 128, | |||
| "BLOCK_SIZE_N": 128, | |||
| "BLOCK_SIZE_N": _fp32_block_size_n if N == 1 else 128, | |||
Member
There was a problem hiding this comment.
What is the case that N will equal to 1, in production setting?
Contributor
Author
There was a problem hiding this comment.
Pooling mode + classify head (num_labels=1)
yewentao256
approved these changes
Aug 20, 2026
yewentao256
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks for the work!
Comment on lines
+14
to
+21
| from vllm.model_executor.layers import batch_invariant as batch_invariant_mod | ||
| from vllm.model_executor.layers.batch_invariant import ( | ||
| bmm_batch_invariant, | ||
| matmul_batch_invariant, | ||
| matmul_persistent, | ||
| ) | ||
| from vllm.platforms import current_platform | ||
| from vllm.utils.mem_utils import get_max_shared_memory_bytes |
|
✅ @vhagor, CI is now available for this PR.
|
Contributor
|
Hi @vhagor, the pre-commit checks have failed. Please run: uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-filesThen, commit the changes and push to your branch. For future commits, |
Signed-off-by: Juqi Li <2223621784@qq.com>
vhagor
force-pushed
the
fix/batch-invariant-fp32-smem-sm89
branch
from
August 21, 2026 00:35
93a8766 to
e1c9785
Compare
Contributor
Author
|
/ci run |
|
✅ Triggered Buildkite CI #84914 for commit |
tzielinski-habana
added a commit
to tzielinski-habana/vllm-fork
that referenced
this pull request
Aug 21, 2026
Resolve conflict in batch_invariant.py: keep upstream's fp32 N=1 shared-memory workaround (vllm-project#52960) alongside the XPU _NUM_SMS global. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
wyettzeng
pushed a commit
to wyettzeng/vllm
that referenced
this pull request
Aug 21, 2026
…oject#52960) Signed-off-by: Juqi Li <2223621784@qq.com> Signed-off-by: Wyett <wyettzeng@gmail.com>
zufangzhu
pushed a commit
to zufangzhu/vllm
that referenced
this pull request
Aug 24, 2026
…oject#52960) Signed-off-by: Juqi Li <2223621784@qq.com> Signed-off-by: Zhu, Zufang <zufang.zhu@intel.com>
khushali9
pushed a commit
to khushali9/vllm
that referenced
this pull request
Aug 29, 2026
…oject#52960) Signed-off-by: Juqi Li <2223621784@qq.com> Signed-off-by: khushali9 <khushali.desai9@gmail.com>
am-cohere
pushed a commit
to am-cohere/vllm
that referenced
this pull request
Sep 1, 2026
…oject#52960) Signed-off-by: Juqi Li <2223621784@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Bugfix] Fix batch-invariant fp32 matmul OOR on SM89 for N=1
Purpose
On SM86/SM89 GPUs with a ~100 KB shared-memory budget (NVIDIA L20 / L4: 101376 B/block),
VLLM_BATCH_INVARIANT=1can fail during engine warmup:SM8x installs Triton
matmul_persistentforaten::mm/addmm/matmul/linear. Float32 used a single hardcoded tile (128×128×32,num_stages=3). fp16 already capsBLOCK_SIZE_Nfrom shared memory (#38670); fp32 did not.Triton still compiles a 128-wide N-tile and masks leftover columns. On L20 + Triton 3.6.0 it then specializes on the runtime
N. ForN=1that specialization adds ~32 KB of staging and the kernel needs 131072 B. SweepN ∈ {1,2,…,4096}×K ∈ {768,2048}(plus odd K, unaligned M, bmm): onlyN=1OORs.Observed call chain on L20 warmup:
Fix: on CUDA devices with
get_max_shared_memory_bytes() <= 106496, useBLOCK_SIZE_N=32,num_stages=2only whenN == 1. Every other fp32 shape keeps128 / stages=3.BLOCK_SIZE_Kstays 32. Tile choice depends on output widthN(a layer property), not batch sizeM, so batch invariance is unchanged.Not a duplicate of #38670 (fp16 N-tile cap). Not a duplicate of open #49131 (SM80 decode perf via M-dependent tiles;
M>64keeps the original fp32 tile, which is exactly the warmup path that OORs).Change
In
enable_batch_invariant_mode():BLOCK_SIZE_NN=1tile> 106496(e.g. A100)128 / stages=3(unchanged)≤ 106496(L20/L4)32 / stages=2Launch (
matmul_persistentandbmm): fp32 uses that N=1 override only whenN == 1;N > 1stays128 / stages=3.Test Plan
New tests:
test_fp32_n_equals_1: fp32N=1matchestorch.mm/torch.bmmand stays batch-invarianttest_fp32_n_gt_1_keeps_wide_tile:N>1still matchestorch.mmwhen the N=1 override is armedL20 (SM 8.9, smem 101376), Triton 3.6.0:
M∈{4,128}, K=2048, N=1VLLM_BATCH_INVARIANT=1serveBAAI/bge-reranker-base; hit/v1/modelsand/v1/rerankTest Result
Kernel compile (L20, Triton 3.6.0, old
128/stages=3):New N=1 tile (
32 / stages=2): 36864 B, launch ok (M=4andM=128).AI assistance
Drafting and code edits used Cursor. The submitting author reviewed every changed line and ran the L20 kernel / serve checks above.