[Spec Decode] Enable adaptive DSpark on SM100 sparse MLA (#52783)
Signed-off-by: mgoin <mgoin64@gmail.com>
This commit is contained in:
@@ -130,8 +130,6 @@ def init_attn_backend(
|
||||
|
||||
# Phase 3: create metadata builders and determine cudagraph support.
|
||||
attn_backend_workspace: torch.Tensor | None = None
|
||||
min_cg_support = AttentionCGSupport.ALWAYS
|
||||
min_cg_attn_backend = None
|
||||
for kv_cache_group_id, groups in enumerate(attn_groups):
|
||||
kernel_block_size = None
|
||||
if kv_cache_group_id < len(kernel_block_sizes):
|
||||
@@ -150,7 +148,25 @@ def init_attn_backend(
|
||||
else:
|
||||
if hasattr(builder, "set_workspace_buffer"):
|
||||
builder.set_workspace_buffer(attn_backend_workspace)
|
||||
# Check cudagraph support for the attention backend
|
||||
attn_cg_support_info = get_attn_cg_support(attn_groups, vllm_config)
|
||||
return attn_groups, attn_cg_support_info, kernel_block_sizes
|
||||
|
||||
|
||||
def get_attn_cg_support(
|
||||
attn_groups: list[list[AttentionGroup]],
|
||||
vllm_config: VllmConfig,
|
||||
checked_layer_names: set[str] | None = None,
|
||||
) -> AttentionCGSupportInfo:
|
||||
"""Return the weakest CUDA graph support among the checked layers."""
|
||||
min_cg_support = AttentionCGSupport.ALWAYS
|
||||
min_cg_attn_backend = None
|
||||
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)
|
||||
cg_support = builder.get_cudagraph_support(
|
||||
vllm_config,
|
||||
group.kv_cache_spec,
|
||||
@@ -158,15 +174,15 @@ def init_attn_backend(
|
||||
if cg_support.value < min_cg_support.value:
|
||||
min_cg_support = cg_support
|
||||
min_cg_attn_backend = group.backend.__name__
|
||||
|
||||
attn_cg_support_info = AttentionCGSupportInfo(
|
||||
min_cg_support=min_cg_support, min_cg_attn_backend=min_cg_attn_backend
|
||||
return AttentionCGSupportInfo(
|
||||
min_cg_support=min_cg_support,
|
||||
min_cg_attn_backend=min_cg_attn_backend,
|
||||
)
|
||||
return attn_groups, attn_cg_support_info, kernel_block_sizes
|
||||
|
||||
|
||||
def get_query_lens_mismatch_unsupported_backend(
|
||||
attn_groups: list[list[AttentionGroup]],
|
||||
checked_layer_names: set[str] | None = None,
|
||||
) -> str | None:
|
||||
"""Name the first backend needing the CPU query lengths to be exact, if any.
|
||||
|
||||
@@ -176,6 +192,10 @@ def get_query_lens_mismatch_unsupported_backend(
|
||||
"""
|
||||
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
|
||||
if not group.backend.supports_device_cpu_query_lens_mismatch():
|
||||
return group.backend.__name__
|
||||
return None
|
||||
|
||||
@@ -559,12 +559,21 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
max_num_blocks = get_block_table_width(max_num_blocks, spec.block_size)
|
||||
max_num_blocks_per_group.append(max_num_blocks)
|
||||
|
||||
target_attn_layer_names = None
|
||||
if isinstance(self.speculator, DraftModelSpeculator):
|
||||
# Adaptive verification validates target attention separately.
|
||||
target_attn_layer_names = {
|
||||
layer_name
|
||||
for group in self.kv_cache_config.kv_cache_groups
|
||||
for layer_name in group.layer_names
|
||||
} - self.speculator.draft_attn_layer_names
|
||||
self.attn_groups, attn_cg_support, self.kernel_block_sizes = init_attn_backend(
|
||||
self.kv_cache_config, self.vllm_config, self.device
|
||||
)
|
||||
attn_cg_support = attn_cg_support.narrow(
|
||||
*self.model_state.get_additional_cg_support()
|
||||
self.kv_cache_config,
|
||||
self.vllm_config,
|
||||
self.device,
|
||||
)
|
||||
additional_attn_cg_support = self.model_state.get_additional_cg_support()
|
||||
attn_cg_support = attn_cg_support.narrow(*additional_attn_cg_support)
|
||||
# The speculator clears the flag at load time when the checkpoint has
|
||||
# no confidence head, so it holds the effective value.
|
||||
self.adaptive_verification = maybe_create_adaptive_verification_manager(
|
||||
@@ -577,6 +586,9 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
query_start_loc=self.input_buffers.query_start_loc,
|
||||
num_bonus_tokens=self.model_state.num_new_sampled_tokens_per_step,
|
||||
max_total_logits=get_max_chunk_logits(self.vocab_size),
|
||||
vllm_config=self.vllm_config,
|
||||
target_layer_names=target_attn_layer_names,
|
||||
additional_attn_cg_support=additional_attn_cg_support,
|
||||
)
|
||||
|
||||
self.block_tables = BlockTables(
|
||||
|
||||
@@ -17,6 +17,7 @@ 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,
|
||||
)
|
||||
from vllm.v1.worker.gpu.buffer_utils import async_copy_to_gpu
|
||||
@@ -25,6 +26,7 @@ logger = init_logger(__name__)
|
||||
_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
|
||||
@@ -444,13 +446,19 @@ def maybe_create_adaptive_verification_manager(
|
||||
query_start_loc: torch.Tensor,
|
||||
num_bonus_tokens: int,
|
||||
max_total_logits: int,
|
||||
vllm_config: "VllmConfig",
|
||||
target_layer_names: set[str] | None = None,
|
||||
additional_attn_cg_support: tuple[AttentionCGSupport, str | None] | None = None,
|
||||
) -> AdaptiveVerificationManager | None:
|
||||
if not enable_adaptive_verification:
|
||||
return None
|
||||
|
||||
# The selector rejects unsupported backends, but models that
|
||||
# hard-wire theirs (e.g. DeepSeek-V4) never go through it.
|
||||
backend = get_query_lens_mismatch_unsupported_backend(attn_groups)
|
||||
backend = get_query_lens_mismatch_unsupported_backend(
|
||||
attn_groups,
|
||||
checked_layer_names=target_layer_names,
|
||||
)
|
||||
if backend is not None:
|
||||
raise ValueError(
|
||||
"Adaptive verification trims verification requests on device, which"
|
||||
@@ -459,12 +467,23 @@ def maybe_create_adaptive_verification_manager(
|
||||
"use a backend that does."
|
||||
)
|
||||
|
||||
if attn_cg_support.min_cg_support != AttentionCGSupport.ALWAYS:
|
||||
target_attn_cg_support = attn_cg_support
|
||||
if target_layer_names is not None:
|
||||
target_attn_cg_support = get_attn_cg_support(
|
||||
attn_groups,
|
||||
vllm_config,
|
||||
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:
|
||||
raise ValueError(
|
||||
"Adaptive verification captures varlen decode cudagraphs, so every"
|
||||
" attention builder must report AttentionCGSupport.ALWAYS, but "
|
||||
f"{attn_cg_support.min_cg_attn_backend} reports "
|
||||
f"{attn_cg_support.min_cg_support}. Pass "
|
||||
" 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."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user