Repository navigation
[Bugfix][Spec Decode] Size DFlash query buffers for cudagraph-padded batches #50065
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
Merged
MatthewBonanni
merged 9 commits into
vllm-project:main
from
siddhant-bharti:fix-dflash-query-buffer-cudagraph-padding
Jul 28, 2026
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9607f97
[Bugfix][Spec Decode] Size DFlash query buffers for cudagraph-padded …
siddhant-bharti d4a2f4f
Merge branch 'main' into fix-dflash-query-buffer-cudagraph-padding
siddhant-bharti 7199c93
Merge branch 'main' into fix-dflash-query-buffer-cudagraph-padding
siddhant-bharti f62c9d6
[Bugfix][Spec Decode] Add regression test for DFlash query buffer cap…
siddhant-bharti f685837
Merge branch 'main' into fix-dflash-query-buffer-cudagraph-padding
siddhant-bharti 72ecfa8
Merge branch 'main' into fix-dflash-query-buffer-cudagraph-padding
siddhant-bharti cffbd1b
Address review: drop regression test, trim comment
siddhant-bharti ad34b5b
Merge branch 'main' into fix-dflash-query-buffer-cudagraph-padding
siddhant-bharti a2df229
Merge branch 'main' into fix-dflash-query-buffer-cudagraph-padding
siddhant-bharti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from vllm.config import ( | ||
| CacheConfig, | ||
| ModelConfig, | ||
| ParallelConfig, | ||
| SchedulerConfig, | ||
| SpeculativeConfig, | ||
| VllmConfig, | ||
| ) | ||
| from vllm.v1.spec_decode.dflash import DFlashProposer | ||
|
|
||
| DFLASH_TARGET_DIR = "Qwen/Qwen3-8B" | ||
| DFLASH_DRAFT_DIR = "z-lab/Qwen3-8B-DFlash-b16" | ||
|
|
||
| NUM_SPECULATIVE_TOKENS = 3 | ||
|
|
||
|
|
||
| def _dflash_vllm_config(max_num_seqs: int) -> VllmConfig: | ||
| model_config = ModelConfig( | ||
| model=DFLASH_TARGET_DIR, | ||
| runner="generate", | ||
| max_model_len=8192, | ||
| trust_remote_code=True, | ||
| ) | ||
| speculative_config = SpeculativeConfig( | ||
| target_model_config=model_config, | ||
| target_parallel_config=ParallelConfig(), | ||
| model=DFLASH_DRAFT_DIR, | ||
| method="dflash", | ||
| num_speculative_tokens=NUM_SPECULATIVE_TOKENS, | ||
| ) | ||
| return VllmConfig( | ||
| model_config=model_config, | ||
| scheduler_config=SchedulerConfig( | ||
| max_num_seqs=max_num_seqs, | ||
| max_num_batched_tokens=8192, | ||
| max_model_len=model_config.max_model_len, | ||
| is_encoder_decoder=model_config.is_encoder_decoder, | ||
| ), | ||
| cache_config=CacheConfig( | ||
| block_size=16, | ||
| gpu_memory_utilization=0.9, | ||
| cache_dtype="auto", | ||
| ), | ||
| parallel_config=ParallelConfig(), | ||
| speculative_config=speculative_config, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("max_num_seqs", [33, 32]) | ||
| def test_dflash_query_buffers_cover_cudagraph_padding(max_num_seqs: int): | ||
| """The cudagraph dispatcher pads drafter batches up to the next capture | ||
| size, which exceeds max_query_tokens whenever it is not itself a capture | ||
| size (any odd max_num_seqs: e.g. 33 * 4 = 132 pads to 136 with the default | ||
| ladder). The persistent query buffers must cover the padded size, or | ||
| slicing them at that size silently yields short tensors and the drafter | ||
| crashes during cudagraph warmup. | ||
| """ | ||
| vllm_config = _dflash_vllm_config(max_num_seqs) | ||
| proposer = DFlashProposer(vllm_config, torch.device("cuda")) | ||
|
|
||
| max_query_tokens = max_num_seqs * (1 + NUM_SPECULATIVE_TOKENS) | ||
| capture_sizes = vllm_config.compilation_config.cudagraph_capture_sizes or [] | ||
| padded_max_query = min( | ||
| (size for size in capture_sizes if size >= max_query_tokens), | ||
| default=max_query_tokens, | ||
| ) | ||
|
|
||
| assert proposer.positions.shape[0] >= padded_max_query | ||
| assert proposer._slot_mapping_buffer.shape[0] >= padded_max_query | ||
| assert proposer.max_positions >= proposer.max_num_tokens + padded_max_query | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.