vllm.model_executor.layers.pooler
PoolingFn
module-attribute
¶
PoolingFn = Callable[
[Union[Tensor, list[Tensor]], PoolingMetadata],
Union[Tensor, list[Tensor]],
]
AllPool
¶
Bases: PoolingMethod
Source code in vllm/model_executor/layers/pooler.py
forward_all
¶
forward_one
¶
Source code in vllm/model_executor/layers/pooler.py
get_supported_tasks
¶
get_supported_tasks() -> Set[PoolingTask]
BasePoolerActivation
¶
Source code in vllm/model_executor/layers/pooler.py
forward
abstractmethod
¶
Source code in vllm/model_executor/layers/pooler.py
CLSPool
¶
Bases: PoolingMethod
Source code in vllm/model_executor/layers/pooler.py
forward_all
¶
Source code in vllm/model_executor/layers/pooler.py
forward_one
¶
Source code in vllm/model_executor/layers/pooler.py
get_supported_tasks
¶
get_supported_tasks() -> Set[PoolingTask]
ClassifierPooler
¶
Bases: Pooler
A pooling layer for classification tasks.
This layer does the following: 1. Applies a classification layer to the hidden states. 2. Optionally applies a pooler layer. 3. Applies an activation function to the output.
Source code in vllm/model_executor/layers/pooler.py
__init__
¶
__init__(
pooling: PoolingFn,
classifier: ClassifierFn,
act_fn: PoolerActivation,
) -> None
act_fn_for_cross_encoder
staticmethod
¶
act_fn_for_cross_encoder(config: ModelConfig)
act_fn_for_seq_cls
staticmethod
¶
act_fn_for_seq_cls(config: ModelConfig)
forward
¶
forward(
hidden_states: Union[Tensor, list[Tensor]],
pooling_metadata: PoolingMetadata,
) -> PoolerOutput
Source code in vllm/model_executor/layers/pooler.py
get_supported_tasks
¶
get_supported_tasks() -> Set[PoolingTask]
DispatchPooler
¶
Bases: Pooler
Dispatches calls to a sub-pooler based on the pooling task.
Source code in vllm/model_executor/layers/pooler.py
__init__
¶
__init__(
poolers_by_task: Mapping[PoolingTask, Pooler],
) -> None
Source code in vllm/model_executor/layers/pooler.py
forward
¶
forward(
hidden_states: Union[Tensor, list[Tensor]],
pooling_metadata: PoolingMetadata,
) -> PoolerOutput
Source code in vllm/model_executor/layers/pooler.py
get_pooling_updates
¶
get_pooling_updates(
task: PoolingTask,
) -> PoolingParamsUpdate
get_supported_tasks
¶
get_supported_tasks() -> Set[PoolingTask]
LambdaPoolerActivation
¶
LastPool
¶
Bases: PoolingMethod
Source code in vllm/model_executor/layers/pooler.py
forward_all
¶
Source code in vllm/model_executor/layers/pooler.py
forward_one
¶
get_supported_tasks
¶
get_supported_tasks() -> Set[PoolingTask]
MeanPool
¶
Bases: PoolingMethod
Source code in vllm/model_executor/layers/pooler.py
forward_all
¶
Source code in vllm/model_executor/layers/pooler.py
forward_one
¶
Source code in vllm/model_executor/layers/pooler.py
get_supported_tasks
¶
get_supported_tasks() -> Set[PoolingTask]
Pooler
¶
The interface required for all poolers used in pooling models in vLLM.
Source code in vllm/model_executor/layers/pooler.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
for_classify
staticmethod
¶
for_classify(
pooler_config: PoolerConfig,
classifier: Optional[ClassifierFn],
*,
default_pooling_type: PoolingType = LAST,
default_normalize: bool = False,
default_softmax: bool = True,
)
Source code in vllm/model_executor/layers/pooler.py
for_embed
staticmethod
¶
for_embed(
pooler_config: PoolerConfig,
*,
default_pooling_type: PoolingType = LAST,
default_normalize: bool = True,
default_softmax: bool = False,
)
Source code in vllm/model_executor/layers/pooler.py
for_encode
staticmethod
¶
for_encode(
pooler_config: PoolerConfig,
*,
default_pooling_type: PoolingType = ALL,
default_normalize: bool = False,
default_softmax: bool = False,
default_step_tag_id: Optional[int] = None,
default_returned_token_ids: Optional[list[int]] = None,
)
Source code in vllm/model_executor/layers/pooler.py
forward
abstractmethod
¶
forward(
hidden_states: Union[list[Tensor], Tensor],
pooling_metadata: PoolingMetadata,
) -> PoolerOutput
get_pooling_updates
¶
get_pooling_updates(
task: PoolingTask,
) -> PoolingParamsUpdate
Construct the updated pooling parameters to use for a supported task.
get_supported_tasks
abstractmethod
¶
get_supported_tasks() -> Set[PoolingTask]
PoolerActivation
¶
Bases: BasePoolerActivation
Source code in vllm/model_executor/layers/pooler.py
PoolerClassify
¶
Bases: PoolerActivation
Source code in vllm/model_executor/layers/pooler.py
forward_chunk
¶
Source code in vllm/model_executor/layers/pooler.py
PoolerHead
¶
Bases: Module
Source code in vllm/model_executor/layers/pooler.py
__init__
¶
__init__(activation: PoolerActivation) -> None
forward
¶
forward(
pooled_data: Union[list[Tensor], Tensor],
pooling_metadata: PoolingMetadata,
)
Source code in vllm/model_executor/layers/pooler.py
from_config
classmethod
¶
from_config(
pooler_config: ResolvedPoolingConfig,
) -> PoolerHead
Source code in vllm/model_executor/layers/pooler.py
PoolerIdentity
¶
Bases: PoolerActivation
Source code in vllm/model_executor/layers/pooler.py
PoolerNormalize
¶
Bases: PoolerActivation
Source code in vllm/model_executor/layers/pooler.py
PoolerScore
¶
PoolingMethod
¶
Source code in vllm/model_executor/layers/pooler.py
forward
¶
forward(
hidden_states: Union[Tensor, list[Tensor]],
pooling_metadata: PoolingMetadata,
) -> Union[list[Tensor], Tensor]
Source code in vllm/model_executor/layers/pooler.py
forward_all
abstractmethod
¶
forward_one
abstractmethod
¶
Note
prompt_len=None means prompt_len=len(hidden_states).
Source code in vllm/model_executor/layers/pooler.py
from_pooling_type
staticmethod
¶
from_pooling_type(
pooling_type: PoolingType,
) -> PoolingMethod
Source code in vllm/model_executor/layers/pooler.py
get_pooling_updates
¶
get_pooling_updates(
task: PoolingTask,
) -> PoolingParamsUpdate
PoolingParamsUpdate
dataclass
¶
Source code in vllm/model_executor/layers/pooler.py
requires_token_ids
class-attribute
instance-attribute
¶
requires_token_ids: bool = False
Set this flag to enable get_prompt_token_ids for your pooler.
apply
¶
apply(params: PoolingParams) -> None
PoolingType
¶
Bases: IntEnum
Enumeration for different types of pooling methods.
Source code in vllm/model_executor/layers/pooler.py
ResolvedPoolingConfig
dataclass
¶
Source code in vllm/model_executor/layers/pooler.py
__init__
¶
__init__(
pooling_type: PoolingType,
normalize: bool,
softmax: bool,
step_tag_id: Optional[int],
returned_token_ids: Optional[list[int]],
) -> None
from_config_with_defaults
classmethod
¶
from_config_with_defaults(
pooler_config: PoolerConfig,
pooling_type: PoolingType,
normalize: bool,
softmax: bool,
step_tag_id: Optional[int] = None,
returned_token_ids: Optional[list[int]] = None,
) -> ResolvedPoolingConfig
Source code in vllm/model_executor/layers/pooler.py
SimplePooler
¶
Bases: Pooler
A layer that pools specific information from hidden states.
This layer does the following:
1. Extracts specific tokens or aggregates data based on pooling method.
2. Normalizes output if specified.
3. Returns structured results as PoolerOutput.
Source code in vllm/model_executor/layers/pooler.py
__init__
¶
__init__(pooling: PoolingMethod, head: PoolerHead) -> None
forward
¶
forward(
hidden_states: Union[Tensor, list[Tensor]],
pooling_metadata: PoolingMetadata,
) -> PoolerOutput
Source code in vllm/model_executor/layers/pooler.py
from_config
classmethod
¶
from_config(
pooler_config: ResolvedPoolingConfig,
) -> SimplePooler
Source code in vllm/model_executor/layers/pooler.py
get_pooling_updates
¶
get_pooling_updates(
task: PoolingTask,
) -> PoolingParamsUpdate
get_supported_tasks
¶
get_supported_tasks() -> Set[PoolingTask]
StepPooler
¶
Bases: Pooler
Source code in vllm/model_executor/layers/pooler.py
__init__
¶
__init__(
head: PoolerHead,
*,
step_tag_id: Optional[int] = None,
returned_token_ids: Optional[list[int]] = None,
) -> None
Source code in vllm/model_executor/layers/pooler.py
extract_states
¶
extract_states(
hidden_states: Union[Tensor, list[Tensor]],
pooling_metadata: PoolingMetadata,
) -> Union[list[Tensor], Tensor]
Source code in vllm/model_executor/layers/pooler.py
forward
¶
forward(
hidden_states: Union[Tensor, list[Tensor]],
pooling_metadata: PoolingMetadata,
) -> PoolerOutput
Source code in vllm/model_executor/layers/pooler.py
from_config
classmethod
¶
from_config(
pooler_config: ResolvedPoolingConfig,
) -> StepPooler
Source code in vllm/model_executor/layers/pooler.py
get_pooling_updates
¶
get_pooling_updates(
task: PoolingTask,
) -> PoolingParamsUpdate
get_supported_tasks
¶
get_supported_tasks() -> Set[PoolingTask]
get_classification_activation_function
¶
get_cross_encoder_activation_function
¶
Source code in vllm/model_executor/layers/pooler.py
get_prompt_lens
¶
get_prompt_lens(
hidden_states: Union[Tensor, list[Tensor]],
pooling_metadata: PoolingMetadata,
) -> Tensor
Source code in vllm/model_executor/layers/pooler.py
get_prompt_token_ids
¶
get_prompt_token_ids(
pooling_metadata: PoolingMetadata,
) -> list[Tensor]
Source code in vllm/model_executor/layers/pooler.py
get_tasks
¶
get_tasks(
pooling_metadata: PoolingMetadata,
) -> list[PoolingTask]