[Spec][V2] Support MTP speculative decoding under pipeline parallelism (#46994)

Signed-off-by: Chris Eastwood <chris.eastwood@pwn4g3.dev>
Signed-off-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Chris Eastwood
2026-09-11 17:55:21 +00:00
committed by GitHub
co-authored by Nick Hill mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 9a35c081e8
commit 6fe67cbbf3
12 changed files with 167 additions and 49 deletions
@@ -6,6 +6,9 @@ from typing import TYPE_CHECKING, cast
import torch
from vllm.model_executor.layers.attention.sparse_mla_attention import (
SharedTopkIndicesBuffer,
)
from vllm.v1.attention.backend import (
AttentionLayer,
AttentionType,
@@ -29,7 +32,9 @@ def _kv_scale_format_for_model(model_type: str | None) -> str:
return "pow2_fp32"
class FlashInferMLASparseSM120Impl(MLAAttentionImpl[FlashInferMLASparseMetadata]):
class FlashInferMLASparseSM120Impl(
MLAAttentionImpl[FlashInferMLASparseMetadata], SharedTopkIndicesBuffer
):
"""SM120 FlashInfer sparse-MLA implementation."""
is_sparse = True
@@ -86,11 +91,7 @@ class FlashInferMLASparseSM120Impl(MLAAttentionImpl[FlashInferMLASparseMetadata]
# Skip-topk layers are built with indexer=None and get the shared
# buffer via mla_args instead (cf. FLASHMLA_SPARSE).
self.topk_indices_buffer: torch.Tensor | None = (
indexer.topk_indices_buffer
if indexer is not None
else mla_args.get("topk_indices_buffer")
)
self.init_topk_indices_buffer(indexer, mla_args.get("topk_indices_buffer"))
from vllm.utils.flashinfer import has_flashinfer_sparse_mla_sm120
if not has_flashinfer_sparse_mla_sm120():
@@ -15,6 +15,9 @@ from vllm.logger import init_logger
from vllm.model_executor.layers.attention.mla_attention import (
get_mla_dims,
)
from vllm.model_executor.layers.attention.sparse_mla_attention import (
SharedTopkIndicesBuffer,
)
from vllm.platforms import current_platform
from vllm.triton_utils import tl, triton
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
@@ -750,7 +753,9 @@ def reference_mla_sparse_prefill(
return (result, lse)
class ROCMAiterMLASparseImpl(MLAAttentionImpl[ROCMAiterMLASparseMetadata]):
class ROCMAiterMLASparseImpl(
MLAAttentionImpl[ROCMAiterMLASparseMetadata], SharedTopkIndicesBuffer
):
is_sparse = True
supports_dense_mha_prefill = False
supports_dcp = False
@@ -795,12 +800,7 @@ class ROCMAiterMLASparseImpl(MLAAttentionImpl[ROCMAiterMLASparseMetadata]):
self.kv_cache_dtype = kv_cache_dtype
self.kv_lora_rank: int = mla_args["kv_lora_rank"]
self.softmax_scale = scale
# The indexer carries the shared buffer for normal layers and tests;
# the explicitly-passed buffer covers backbone skip layers, whose
# indexer is not constructed (see deepseek_v2.py).
self.topk_indices_buffer: torch.Tensor | None = (
indexer.topk_indices_buffer if indexer is not None else topk_indices_buffer
)
self.init_topk_indices_buffer(indexer, topk_indices_buffer)
vllm_config = get_current_vllm_config()
max_tokens = vllm_config.scheduler_config.max_num_batched_tokens
@@ -13,6 +13,9 @@ from vllm.logger import init_logger
from vllm.model_executor.layers.attention.mla_attention import (
get_mla_dims,
)
from vllm.model_executor.layers.attention.sparse_mla_attention import (
SharedTopkIndicesBuffer,
)
from vllm.utils.torch_utils import is_quantized_kv_cache, np_to_pinned_tensor
from vllm.v1.attention.backend import (
AttentionBackend,
@@ -183,7 +186,7 @@ class XPUMLASparseMetadataBuilder(AttentionMetadataBuilder[XPUMLASparseMetadata]
return metadata
class XPUMLASparseImpl(MLAAttentionImpl[XPUMLASparseMetadata]):
class XPUMLASparseImpl(MLAAttentionImpl[XPUMLASparseMetadata], SharedTopkIndicesBuffer):
is_sparse = True
def __init__(
@@ -210,12 +213,7 @@ class XPUMLASparseImpl(MLAAttentionImpl[XPUMLASparseMetadata]):
self.kv_cache_dtype = kv_cache_dtype
self.kv_lora_rank: int = mla_args["kv_lora_rank"]
self.softmax_scale = scale
# The indexer carries the shared buffer for normal layers and tests;
# the explicitly-passed buffer covers backbone skip layers, whose
# indexer is not constructed (see deepseek_v2.py).
self.topk_indices_buffer: torch.Tensor | None = (
indexer.topk_indices_buffer if indexer is not None else topk_indices_buffer
)
self.init_topk_indices_buffer(indexer, topk_indices_buffer)
def _forward_bf16_kv(
self,
+7 -1
View File
@@ -2030,7 +2030,13 @@ class GPUModelRunner(LoRAModelRunnerMixin):
)
mm_inputs: tuple[list[torch.Tensor], torch.Tensor] | None = None
if self.speculator is not None and self.speculator.supports_mm_inputs:
# The encoder runner exists only on the first PP rank, so later ranks
# have no cached embeddings to gather.
if (
self.speculator is not None
and self.speculator.supports_mm_inputs
and self.model_state.supports_mm_inputs
):
# Get cached multimodal embeddings for draft forward.
# NOTE: This is done here because postprocess updates
# num_computed_prefill_tokens.