[Model] Update pooling model interface (#21058)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -119,13 +119,6 @@ class SupportsMultiModal(Protocol):
|
||||
...
|
||||
|
||||
|
||||
# We can't use runtime_checkable with ClassVar for issubclass checks
|
||||
# so we need to treat the class as an instance and use isinstance instead
|
||||
@runtime_checkable
|
||||
class _SupportsMultiModalType(Protocol):
|
||||
supports_multimodal: Literal[True]
|
||||
|
||||
|
||||
@overload
|
||||
def supports_multimodal(
|
||||
model: type[object]) -> TypeIs[type[SupportsMultiModal]]:
|
||||
@@ -140,10 +133,7 @@ def supports_multimodal(model: object) -> TypeIs[SupportsMultiModal]:
|
||||
def supports_multimodal(
|
||||
model: Union[type[object], object],
|
||||
) -> Union[TypeIs[type[SupportsMultiModal]], TypeIs[SupportsMultiModal]]:
|
||||
if isinstance(model, type):
|
||||
return isinstance(model, _SupportsMultiModalType)
|
||||
|
||||
return isinstance(model, SupportsMultiModal)
|
||||
return getattr(model, "supports_multimodal", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
@@ -174,13 +164,6 @@ class SupportsScoreTemplate(Protocol):
|
||||
...
|
||||
|
||||
|
||||
# We can't use runtime_checkable with ClassVar for issubclass checks
|
||||
# so we need to treat the class as an instance and use isinstance instead
|
||||
@runtime_checkable
|
||||
class _SupportsScoreTemplateType(Protocol):
|
||||
supports_score_template: Literal[True]
|
||||
|
||||
|
||||
@overload
|
||||
def supports_score_template(
|
||||
model: type[object]) -> TypeIs[type[SupportsScoreTemplate]]:
|
||||
@@ -195,11 +178,7 @@ def supports_score_template(model: object) -> TypeIs[SupportsScoreTemplate]:
|
||||
def supports_score_template(
|
||||
model: Union[type[object], object],
|
||||
) -> Union[TypeIs[type[SupportsScoreTemplate]], TypeIs[SupportsScoreTemplate]]:
|
||||
|
||||
if isinstance(model, type):
|
||||
return isinstance(model, _SupportsScoreTemplateType)
|
||||
|
||||
return isinstance(model, SupportsScoreTemplate)
|
||||
return getattr(model, "supports_score_template", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
@@ -409,11 +388,6 @@ class HasInnerState(Protocol):
|
||||
"""
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class _HasInnerStateType(Protocol):
|
||||
has_inner_state: ClassVar[Literal[True]]
|
||||
|
||||
|
||||
@overload
|
||||
def has_inner_state(model: object) -> TypeIs[HasInnerState]:
|
||||
...
|
||||
@@ -427,10 +401,7 @@ def has_inner_state(model: type[object]) -> TypeIs[type[HasInnerState]]:
|
||||
def has_inner_state(
|
||||
model: Union[type[object], object]
|
||||
) -> Union[TypeIs[type[HasInnerState]], TypeIs[HasInnerState]]:
|
||||
if isinstance(model, type):
|
||||
return isinstance(model, _HasInnerStateType)
|
||||
|
||||
return isinstance(model, HasInnerState)
|
||||
return getattr(model, "has_inner_state", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
@@ -446,11 +417,6 @@ class IsAttentionFree(Protocol):
|
||||
"""
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class _IsAttentionFreeType(Protocol):
|
||||
is_attention_free: ClassVar[Literal[True]]
|
||||
|
||||
|
||||
@overload
|
||||
def is_attention_free(model: object) -> TypeIs[IsAttentionFree]:
|
||||
...
|
||||
@@ -464,10 +430,7 @@ def is_attention_free(model: type[object]) -> TypeIs[type[IsAttentionFree]]:
|
||||
def is_attention_free(
|
||||
model: Union[type[object], object]
|
||||
) -> Union[TypeIs[type[IsAttentionFree]], TypeIs[IsAttentionFree]]:
|
||||
if isinstance(model, type):
|
||||
return isinstance(model, _IsAttentionFreeType)
|
||||
|
||||
return isinstance(model, IsAttentionFree)
|
||||
return getattr(model, "is_attention_free", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
@@ -502,11 +465,6 @@ class IsHybrid(Protocol):
|
||||
...
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class _IsHybridType(Protocol):
|
||||
is_hybrid: ClassVar[Literal[True]]
|
||||
|
||||
|
||||
@overload
|
||||
def is_hybrid(model: object) -> TypeIs[IsHybrid]:
|
||||
...
|
||||
@@ -520,10 +478,7 @@ def is_hybrid(model: type[object]) -> TypeIs[type[IsHybrid]]:
|
||||
def is_hybrid(
|
||||
model: Union[type[object], object]
|
||||
) -> Union[TypeIs[type[IsHybrid]], TypeIs[IsHybrid]]:
|
||||
if isinstance(model, type):
|
||||
return isinstance(model, _IsHybridType)
|
||||
|
||||
return isinstance(model, IsHybrid)
|
||||
return getattr(model, "is_hybrid", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
@@ -598,11 +553,6 @@ class HasNoOps(Protocol):
|
||||
has_noops: ClassVar[Literal[True]] = True
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class _HasNoOpsType(Protocol):
|
||||
has_noops: ClassVar[Literal[True]]
|
||||
|
||||
|
||||
@overload
|
||||
def has_noops(model: object) -> TypeIs[HasNoOps]:
|
||||
...
|
||||
@@ -616,10 +566,7 @@ def has_noops(model: type[object]) -> TypeIs[type[HasNoOps]]:
|
||||
def has_noops(
|
||||
model: Union[type[object], object]
|
||||
) -> Union[TypeIs[type[HasNoOps]], TypeIs[HasNoOps]]:
|
||||
if isinstance(model, type):
|
||||
return isinstance(model, _HasNoOpsType)
|
||||
|
||||
return isinstance(model, HasNoOps)
|
||||
return getattr(model, "has_noops", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
@@ -643,11 +590,7 @@ def supports_cross_encoding(model: object) -> TypeIs[SupportsCrossEncoding]:
|
||||
def _supports_cross_encoding(
|
||||
model: Union[type[object], object],
|
||||
) -> Union[TypeIs[type[SupportsCrossEncoding]], TypeIs[SupportsCrossEncoding]]:
|
||||
|
||||
if isinstance(model, type):
|
||||
return isinstance(model, SupportsCrossEncoding)
|
||||
|
||||
return isinstance(model, SupportsCrossEncoding)
|
||||
return getattr(model, "supports_cross_encoding", False)
|
||||
|
||||
|
||||
def supports_cross_encoding(
|
||||
@@ -658,8 +601,9 @@ def supports_cross_encoding(
|
||||
|
||||
def has_step_pooler(model: Union[type[object], object]) -> bool:
|
||||
"""Check if the model uses step pooler."""
|
||||
return is_pooling_model(model) and any(
|
||||
type(module).__name__ == "StepPooler" for module in model.modules())
|
||||
from vllm.model_executor.layers.pooler import StepPooler
|
||||
|
||||
return is_pooling_model(model) and isinstance(model.pooler, StepPooler)
|
||||
|
||||
|
||||
class SupportsQuant:
|
||||
@@ -770,10 +714,7 @@ def supports_transcription(model: object) -> TypeIs[SupportsTranscription]:
|
||||
def supports_transcription(
|
||||
model: Union[type[object], object],
|
||||
) -> Union[TypeIs[type[SupportsTranscription]], TypeIs[SupportsTranscription]]:
|
||||
if isinstance(model, type):
|
||||
return isinstance(model, SupportsTranscription)
|
||||
|
||||
return isinstance(model, SupportsTranscription)
|
||||
return getattr(model, "supports_transcription", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
@@ -796,7 +737,4 @@ def supports_v0_only(model: object) -> TypeIs[SupportsV0Only]:
|
||||
def supports_v0_only(
|
||||
model: Union[type[object], object],
|
||||
) -> Union[TypeIs[type[SupportsV0Only]], TypeIs[SupportsV0Only]]:
|
||||
if isinstance(model, type):
|
||||
return isinstance(model, SupportsV0Only)
|
||||
|
||||
return isinstance(model, SupportsV0Only)
|
||||
return getattr(model, "supports_v0_only", False)
|
||||
|
||||
Reference in New Issue
Block a user