Merge branch 'main' into patches
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
@@ -142,6 +142,13 @@ _language_model_by_module: "weakref.WeakKeyDictionary[nn.Module, VllmModel]" = (
|
||||
)
|
||||
|
||||
|
||||
def _is_language_model(model: object) -> TypeIs[VllmModel]:
|
||||
# Text towers can use config/position_ids signatures and omit loader hooks.
|
||||
return callable(getattr(model, "embed_input_ids", None)) and callable(
|
||||
getattr(model, "forward", None)
|
||||
)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class SupportsMultiModalEmbeddings(Protocol):
|
||||
"""The interface for models that can merge external multimodal embeddings."""
|
||||
@@ -285,14 +292,14 @@ class SupportsMultiModal(SupportsMultiModalEmbeddings, Protocol):
|
||||
mod = getattr(mod, attr)
|
||||
|
||||
candidate: object = mod
|
||||
if candidate is not self_module and isinstance(candidate, VllmModel):
|
||||
if candidate is not self_module and _is_language_model(candidate):
|
||||
_language_model_by_module[self_module] = candidate
|
||||
return candidate
|
||||
|
||||
# Fallback
|
||||
for mod in self_module.children():
|
||||
candidate = mod
|
||||
if isinstance(candidate, VllmModel):
|
||||
if _is_language_model(candidate):
|
||||
_language_model_by_module[self_module] = candidate
|
||||
return candidate
|
||||
|
||||
@@ -859,6 +866,27 @@ def _supports_pp_inspect(model: type[object] | object) -> bool:
|
||||
return supports_kw(model_forward, "intermediate_tensors")
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class SupportsHCSP(Protocol):
|
||||
"""Support sequence-parallel HC without changing MoE parallelism."""
|
||||
|
||||
supports_hc_sp: ClassVar[Literal[True]] = True
|
||||
|
||||
|
||||
@overload
|
||||
def supports_hc_sp(model: type[object]) -> TypeIs[type[SupportsHCSP]]: ...
|
||||
|
||||
|
||||
@overload
|
||||
def supports_hc_sp(model: object) -> TypeIs[SupportsHCSP]: ...
|
||||
|
||||
|
||||
def supports_hc_sp(
|
||||
model: type[object] | object,
|
||||
) -> TypeIs[type[SupportsHCSP]] | TypeIs[SupportsHCSP]:
|
||||
return getattr(model, "supports_hc_sp", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class HasInnerState(Protocol):
|
||||
"""The interface required for all models that has inner state."""
|
||||
@@ -1114,13 +1142,10 @@ def has_noops(
|
||||
|
||||
@runtime_checkable
|
||||
class SupportsMambaPrefixCaching(Protocol):
|
||||
"""The interface for models whose mamba layers support prefix caching.
|
||||
|
||||
This is currently experimental.
|
||||
"""The interface for attention-free Mamba models that support prefix
|
||||
caching. Hybrid models get the same methods from `IsHybrid`.
|
||||
"""
|
||||
|
||||
supports_mamba_prefix_caching: ClassVar[Literal[True]] = True
|
||||
|
||||
@classmethod
|
||||
def get_mamba_state_copy_func(cls) -> tuple["MambaStateCopyFunc", ...]:
|
||||
"""Return copy functions for the model's Mamba states."""
|
||||
@@ -1136,24 +1161,6 @@ class SupportsMambaPrefixCaching(Protocol):
|
||||
return {mamba_type: copy_funcs for mamba_type in mamba_types}
|
||||
|
||||
|
||||
@overload
|
||||
def supports_mamba_prefix_caching(
|
||||
model: type[object],
|
||||
) -> TypeIs[type[SupportsMambaPrefixCaching]]: ...
|
||||
|
||||
|
||||
@overload
|
||||
def supports_mamba_prefix_caching(
|
||||
model: object,
|
||||
) -> TypeIs[SupportsMambaPrefixCaching]: ...
|
||||
|
||||
|
||||
def supports_mamba_prefix_caching(
|
||||
model: type[object] | object,
|
||||
) -> TypeIs[type[SupportsMambaPrefixCaching]] | TypeIs[SupportsMambaPrefixCaching]:
|
||||
return getattr(model, "supports_mamba_prefix_caching", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class SupportsReplaySSM(Protocol):
|
||||
"""The interface for models whose recurrent layers support ReplaySSM
|
||||
|
||||
Reference in New Issue
Block a user