[Spec Decode] Enable Gemma4 DSpark adaptive verification with FlashInfer (#57263)

Signed-off-by: zixi-qi <zixi@inferact.ai>
Co-authored-by: OpenAI Codex <noreply@openai.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
qizixi
2026-09-26 17:01:17 +08:00
committed by GitHub
co-authored by OpenAI Codex Claude Opus 5.5 Nick Hill
parent 3b4566c5cf
commit a4eb3f25d6
24 changed files with 894 additions and 135 deletions
+34
View File
@@ -328,6 +328,40 @@ def get_query_lens_mismatch_unsupported_backend(
return None
def get_varlen_cudagraph_unsupported_backend(
attn_groups: list[list[AttentionGroup]],
vllm_config: VllmConfig,
max_query_len: int,
checked_layer_names: set[str] | None = None,
) -> tuple[str, int | None] | None:
"""Name the first backend whose FULL cudagraphs cannot replay decode batches
of 1 to max_query_len tokens per request, with its bound, if any.
ALWAYS builders replay any batch; the others need a bound of at least
max_query_len. See AttentionMetadataBuilder.get_varlen_cudagraph_max_query_len().
"""
for groups in attn_groups:
for group in groups:
if checked_layer_names is not None and checked_layer_names.isdisjoint(
group.layer_names
):
continue
builder = group.get_metadata_builder(0)
spec = group.kv_cache_spec
support = builder.get_cudagraph_support(vllm_config, spec)
if support == AttentionCGSupport.ALWAYS:
continue
bound = (
# NEVER means never, whatever an inherited override says.
None
if support == AttentionCGSupport.NEVER
else builder.get_varlen_cudagraph_max_query_len(vllm_config, spec)
)
if bound is None or bound < max_query_len:
return group.backend.__name__, bound
return None
def init_kv_cache(
forward_context: dict[str, Any],
kv_cache_config: KVCacheConfig,
+2 -1
View File
@@ -69,7 +69,8 @@ class BatchExecutionDescriptor:
num_reqs: int | None # None means no request padding is needed (PIECEWISE graphs)
uniform_token_count: int | None = None
# Upper bound on per-request query length. Varlen decode graphs leave
# uniform_token_count unset, so this is what keeps a prefill batch out of one.
# uniform_token_count unset, so this is what keeps a prefill batch out of one:
# the runner passes None for any batch with a prefill.
max_query_len: int | None = None
num_active_loras: int = 0
# Number of microbatches the batch is split into (DBO). 1 means no splitting.
+2 -1
View File
@@ -243,7 +243,8 @@ def dispatch_cg_and_sync_dp(
dp_size: Data-parallel world size. 1 skips all cross-rank work.
dp_rank: This rank's index in the DP group.
max_query_len: Upper bound on per-request query length, for selecting
varlen decode graphs. None means the graph must not constrain it.
varlen decode graphs. None, as for a batch with a prefill, keeps
the batch out of graphs that constrain it.
need_eager: Force `CUDAGraphMode.NONE` instead of dispatching.
num_active_loras: Active LoRA count for this rank. Does not need
cross-rank agreement; it never changes a bucket's token count.
+5 -2
View File
@@ -640,7 +640,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
self.speculator, "enable_adaptive_verification", False
),
attn_groups=self.attn_groups,
attn_cg_support=attn_cg_support,
req_states=self.req_states,
query_start_loc=self.input_buffers.query_start_loc,
num_bonus_tokens=self.model_state.num_new_sampled_tokens_per_step,
@@ -1646,12 +1645,16 @@ class GPUModelRunner(LoRAModelRunnerMixin):
# Get batch descriptor and sync across DP ranks.
num_reqs = len(scheduler_output.num_scheduled_tokens)
num_toks = scheduler_output.total_num_scheduled_tokens
max_query_len = max(scheduler_output.num_scheduled_tokens.values())
max_query_len: int | None = max(scheduler_output.num_scheduled_tokens.values())
batch_req_state, uniform_tok_count = self.gather_batch_req_state(
scheduler_output, dummy_run
)
if batch_req_state is not None:
num_toks = batch_req_state.num_tokens
if batch_req_state.has_prefill:
# Varlen decode graphs replay decodes only, and their bound
# alone would admit a short prefill.
max_query_len = None
if self.pcp_manager is not None:
num_toks = self.pcp_manager.get_num_tokens_for_dispatch(
batch_req_state.num_scheduled_tokens,
@@ -19,8 +19,8 @@ from vllm.v1.attention.backend import AttentionCGSupport
from vllm.v1.utils import CpuGpuBuffer
from vllm.v1.worker.gpu.async_utils import StepTimingSample, stream
from vllm.v1.worker.gpu.attn_utils import (
get_attn_cg_support,
get_query_lens_mismatch_unsupported_backend,
get_varlen_cudagraph_unsupported_backend,
)
logger = init_logger(__name__)
@@ -28,7 +28,6 @@ _PROFILE_REPLAYS = 5
if TYPE_CHECKING:
from vllm.config import VllmConfig
from vllm.v1.worker.gpu.attn_utils import AttentionCGSupportInfo
from vllm.v1.worker.gpu.input_batch import InputBatch
from vllm.v1.worker.gpu.states import RequestState
from vllm.v1.worker.utils import AttentionGroup
@@ -452,7 +451,6 @@ def maybe_create_adaptive_verification_manager(
*,
enable_adaptive_verification: bool,
attn_groups: list[list["AttentionGroup"]],
attn_cg_support: "AttentionCGSupportInfo",
req_states: "RequestState",
query_start_loc: torch.Tensor,
num_bonus_tokens: int,
@@ -477,25 +475,30 @@ def maybe_create_adaptive_verification_manager(
"use a backend that does."
)
target_attn_cg_support = attn_cg_support
if target_layer_names is not None:
target_attn_cg_support = get_attn_cg_support(
# The runner's decode_query_len, the width varlen decode graphs capture.
max_query_len = req_states.num_speculative_steps + num_bonus_tokens
unsupported: tuple[str | None, int | None] | None = (
get_varlen_cudagraph_unsupported_backend(
attn_groups,
vllm_config,
max_query_len,
checked_layer_names=target_layer_names,
)
if additional_attn_cg_support is not None:
target_attn_cg_support = target_attn_cg_support.narrow(
*additional_attn_cg_support
)
if target_attn_cg_support.min_cg_support != AttentionCGSupport.ALWAYS:
)
if unsupported is None and additional_attn_cg_support is not None:
# Groups built outside init_attn_backend report only their support
# level, and without a bound only ALWAYS replays varlen batches.
additional_support, additional_backend = additional_attn_cg_support
if additional_support != AttentionCGSupport.ALWAYS:
unsupported = additional_backend, None
if unsupported is not None:
backend, bound = unsupported
allowed = "none" if bound is None else f"at most {bound}"
raise ValueError(
"Adaptive verification captures varlen decode cudagraphs, so every"
" target attention builder must report AttentionCGSupport.ALWAYS, but "
f"{target_attn_cg_support.min_cg_attn_backend} reports "
f"{target_attn_cg_support.min_cg_support}. Pass "
"enable_adaptive_verification=false in the speculative config, or "
"use a backend that does."
"Adaptive verification replays decode cudagraphs whose per-request "
f"query lengths vary up to {max_query_len}, but {backend} allows "
f"{allowed}. Pass enable_adaptive_verification=false in the "
"speculative config, or use a backend that does."
)
return AdaptiveVerificationManager(