[Mamba] Add FlashInfer ReplaySSM support for MTP (#52928)
Signed-off-by: Andrii Skliar <askliar@nvidia.com> Co-authored-by: Andrii Skliar <askliar@nvidia.com>
This commit is contained in:
co-authored by
Andrii Skliar
parent
7e583e615c
commit
deb148e730
@@ -204,15 +204,16 @@ class CacheConfig:
|
||||
Mamba block size."""
|
||||
replayssm_buffer_len: int = Field(default=16, gt=0)
|
||||
"""ReplaySSM logical history length B for Mamba2. Triton uses B physical
|
||||
rows and FlashInfer uses B+1. Kimi-K3 speculative decode does not use B.
|
||||
Default 16."""
|
||||
rows and FlashInfer uses B+T, where T is the target verification length.
|
||||
Kimi-K3 speculative decode does not use B. Default 16."""
|
||||
use_replayssm: bool = False
|
||||
"""Use the ReplaySSM Mamba2 decode kernel: cache recent SSM inputs and skip
|
||||
the per-step full-state store, writing the checkpoint back only on flush.
|
||||
Requires mamba_cache_mode 'none' or 'align' (prefix caching) and the Triton
|
||||
or FlashInfer mamba backend; standard (non-speculative) decode only. In align
|
||||
mode flushes are most efficient when mamba_block_size is a multiple of
|
||||
replayssm_buffer_len, but this is not required."""
|
||||
or FlashInfer mamba backend. Mamba2 speculative decode requires FlashInfer
|
||||
and mamba_cache_mode 'none'. In align mode flushes are most efficient when
|
||||
mamba_block_size is a multiple of replayssm_buffer_len, but this is not
|
||||
required."""
|
||||
use_kda_recoverssm: bool = field(default=False, init=False)
|
||||
"""Whether Kimi-K3 KDA uses RecoverSSM speculative decode."""
|
||||
|
||||
|
||||
+41
-6
@@ -3458,19 +3458,35 @@ class VllmConfig:
|
||||
if not self.cache_config.use_replayssm:
|
||||
self.cache_config.use_kda_recoverssm = False
|
||||
return self
|
||||
self.cache_config.use_kda_recoverssm = self.num_speculative_tokens > 0
|
||||
|
||||
kda_architectures = (
|
||||
"KimiLinearForCausalLM",
|
||||
"KimiK3ForConditionalGeneration",
|
||||
)
|
||||
is_kda_model = (
|
||||
self.model_config is not None
|
||||
and self.model_config.architecture in kda_architectures
|
||||
)
|
||||
self.cache_config.use_kda_recoverssm = (
|
||||
self.num_speculative_tokens > 0 and is_kda_model
|
||||
)
|
||||
use_mamba_replayssm_spec = (
|
||||
self.num_speculative_tokens > 0 and not self.cache_config.use_kda_recoverssm
|
||||
)
|
||||
|
||||
if self.model_config is not None and not self.model_config.supports_replayssm:
|
||||
raise ValueError(
|
||||
"--use-replayssm is not supported for architecture "
|
||||
f"{self.model_config.architecture!r}"
|
||||
)
|
||||
if (
|
||||
self.mamba_config.backend == MambaBackendEnum.FLASHINFER
|
||||
and self.cache_config.replayssm_buffer_len > 16
|
||||
):
|
||||
raise ValueError(
|
||||
"FlashInfer ReplaySSM requires --replayssm-buffer-len <= 16"
|
||||
)
|
||||
if self.cache_config.use_kda_recoverssm:
|
||||
if self.model_config is not None and self.model_config.architecture not in (
|
||||
"KimiLinearForCausalLM",
|
||||
"KimiK3ForConditionalGeneration",
|
||||
):
|
||||
raise ValueError("RecoverSSM is only supported for Kimi-K3 KDA")
|
||||
if self.mamba_config.enable_stochastic_rounding:
|
||||
raise ValueError(
|
||||
"RecoverSSM supports bfloat16/float32 "
|
||||
@@ -3494,6 +3510,25 @@ class VllmConfig:
|
||||
)
|
||||
if self.mamba_config.backend != MambaBackendEnum.TRITON:
|
||||
raise ValueError("RecoverSSM requires --mamba-backend triton")
|
||||
elif use_mamba_replayssm_spec:
|
||||
if self.cache_config.mamba_cache_mode != "none":
|
||||
raise ValueError(
|
||||
"FlashInfer ReplaySSM speculative decoding requires "
|
||||
"--mamba-cache-mode none"
|
||||
)
|
||||
query_len = 1 + self.num_speculative_tokens
|
||||
if self.cache_config.replayssm_buffer_len < query_len:
|
||||
raise ValueError(
|
||||
"FlashInfer ReplaySSM speculative decoding requires "
|
||||
"--replayssm-buffer-len >= 1 + num_speculative_tokens "
|
||||
f"({query_len}); got "
|
||||
f"{self.cache_config.replayssm_buffer_len}"
|
||||
)
|
||||
if self.mamba_config.backend != MambaBackendEnum.FLASHINFER:
|
||||
raise ValueError(
|
||||
"Mamba2 ReplaySSM speculative decoding requires "
|
||||
"--mamba-backend flashinfer"
|
||||
)
|
||||
elif self.cache_config.mamba_cache_mode == "all":
|
||||
raise ValueError(
|
||||
"--use-replayssm supports prefix caching only in align mode; "
|
||||
|
||||
Reference in New Issue
Block a user