[Bugfix] Make Attention Backend Auto-Selection Batch-Invariance-Aware (#40193)
Signed-off-by: Srreyansh Sethi <srreyansh.sethi@gmail.com> Signed-off-by: Matthew Bonanni <mbonanni@redhat.com> Co-authored-by: Matthew Bonanni <mbonanni@redhat.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Matthew Bonanni
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
d0009ddb0b
commit
b7a2605020
@@ -6,6 +6,7 @@ from typing import NamedTuple, cast, get_args
|
||||
|
||||
import torch
|
||||
|
||||
import vllm.envs as envs
|
||||
from vllm.config.cache import CacheDType
|
||||
from vllm.logger import init_logger
|
||||
from vllm.utils.import_utils import resolve_obj_by_qualname
|
||||
@@ -30,6 +31,7 @@ class AttentionSelectorConfig(NamedTuple):
|
||||
use_per_head_quant_scales: bool = False
|
||||
attn_type: str = AttentionType.DECODER
|
||||
use_non_causal: bool = False
|
||||
use_batch_invariant: bool = False
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
@@ -43,7 +45,8 @@ class AttentionSelectorConfig(NamedTuple):
|
||||
f"use_mm_prefix={self.use_mm_prefix}, "
|
||||
f"use_per_head_quant_scales={self.use_per_head_quant_scales}, "
|
||||
f"attn_type={self.attn_type}, "
|
||||
f"use_non_causal={self.use_non_causal})"
|
||||
f"use_non_causal={self.use_non_causal}, "
|
||||
f"use_batch_invariant={self.use_batch_invariant})"
|
||||
)
|
||||
|
||||
|
||||
@@ -95,6 +98,7 @@ def get_attn_backend(
|
||||
use_per_head_quant_scales=use_per_head_quant_scales,
|
||||
attn_type=attn_type or AttentionType.DECODER,
|
||||
use_non_causal=use_non_causal,
|
||||
use_batch_invariant=envs.VLLM_BATCH_INVARIANT,
|
||||
)
|
||||
|
||||
return _cached_get_attn_backend(
|
||||
@@ -162,4 +166,9 @@ def _cached_get_mamba_attn_backend(
|
||||
) from e
|
||||
|
||||
mamba_attn_backend = selected_backend.get_class()
|
||||
if envs.VLLM_BATCH_INVARIANT and not mamba_attn_backend.supports_batch_invariance():
|
||||
raise RuntimeError(
|
||||
"VLLM batch_invariant mode is not supported for "
|
||||
f"{mamba_attn_backend.get_name()}."
|
||||
)
|
||||
return mamba_attn_backend
|
||||
|
||||
Reference in New Issue
Block a user