vllm.model_executor.layers.pooler
AllPool
¶
Bases: SimplePooler
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
CLSPool
¶
Bases: SimplePooler
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
ClassifierPooler
¶
Bases: Module
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. In the case of classification models it is either sigmoid or softmax. In the case of scoring models, the same behavior is configuration dependent, as in the sentence-transformers library.
Source code in vllm/model_executor/layers/pooler.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
|
default_activation_function
instance-attribute
¶
default_activation_function = (
get_cross_encoder_activation_function(hf_config)
)
__init__
¶
__init__(
config: ModelConfig,
classifier: Module,
pooler: Optional[Module] = None,
)
Source code in vllm/model_executor/layers/pooler.py
forward
¶
forward(
hidden_states: Union[Tensor, list[Tensor]],
pooling_metadata: PoolingMetadata,
) -> PoolerOutput
Pools sentence pair scores from the hidden_states.
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
LastPool
¶
Bases: SimplePooler
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
MeanPool
¶
Bases: SimplePooler
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
Pooler
¶
Bases: Module
Source code in vllm/model_executor/layers/pooler.py
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,
) -> SimplePooler
Source code in vllm/model_executor/layers/pooler.py
PoolerHead
¶
Bases: Module
Source code in vllm/model_executor/layers/pooler.py
__init__
¶
forward
¶
forward(
pooled_data: Union[list[Tensor], Tensor],
pooling_metadata: PoolingMetadata,
)
Source code in vllm/model_executor/layers/pooler.py
PoolingType
¶
Bases: IntEnum
Enumeration for different types of pooling methods.
Source code in vllm/model_executor/layers/pooler.py
SimplePooler
¶
Bases: Module
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
.
Attributes:
Name | Type | Description |
---|---|---|
pooling_type |
The type of pooling to use. |
|
normalize |
Whether to normalize the pooled data. |
Source code in vllm/model_executor/layers/pooler.py
__init__
¶
build_output
¶
build_output(data: Tensor) -> PoolingSequenceGroupOutput
extract_states
¶
forward
¶
forward(
hidden_states: Union[Tensor, list[Tensor]],
pooling_metadata: PoolingMetadata,
) -> PoolerOutput
Source code in vllm/model_executor/layers/pooler.py
from_pooling_type
staticmethod
¶
from_pooling_type(
pooling_type: PoolingType,
*,
normalize: bool,
softmax: bool,
step_tag_id: Optional[int] = None,
returned_token_ids: Optional[list[int]] = None,
) -> SimplePooler
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
StepPool
¶
Bases: SimplePooler
Source code in vllm/model_executor/layers/pooler.py
__init__
¶
__init__(
*,
normalize: bool,
softmax: bool,
step_tag_id: Optional[int] = None,
returned_token_ids: Optional[list[int]] = 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
get_prompt_token_ids
¶
get_prompt_token_ids(
pooling_metadata: PoolingMetadata,
) -> list[Tensor]