Skip to content

vllm.pooling_params

PoolingTask module-attribute

PoolingTask = Literal[
    "encode", "embed", "classify", "score"
]

PoolingParams

Bases: Struct

API parameters for pooling models.

Attributes:

Name Type Description
dimensions Optional[int]

Reduce the dimensions of embeddings if model support matryoshka representation.

Source code in vllm/pooling_params.py
class PoolingParams(
        msgspec.Struct,
        omit_defaults=True,  # type: ignore[call-arg]
        array_like=True):  # type: ignore[call-arg]
    """API parameters for pooling models.

    Attributes:
        dimensions: Reduce the dimensions of embeddings
                    if model support matryoshka representation.
    """

    dimensions: Optional[int] = None

    output_kind: RequestOutputKind = RequestOutputKind.FINAL_ONLY

    task: Optional[PoolingTask] = None
    """Internal use only."""

    requires_token_ids: bool = False
    """Internal use only."""

    def clone(self) -> "PoolingParams":
        """Returns a deep copy of the PoolingParams instance."""
        return PoolingParams(
            dimensions=self.dimensions,
            task=self.task,
            requires_token_ids=self.requires_token_ids,
        )

    def verify(self, task: PoolingTask, model_config: "ModelConfig") -> None:
        if self.task is None:
            self.task = task
        elif self.task != task:
            msg = f"You cannot overwrite {self.task=!r} with {task=!r}!"
            raise ValueError(msg)

        # NOTE: Task validation needs to done against the model instance,
        # which is not available in model config. So, it's not included
        # in this method

        if self.dimensions is not None:
            if not model_config.is_matryoshka:
                raise ValueError(
                    f'Model "{model_config.served_model_name}" does not '
                    f'support matryoshka representation, '
                    f'changing output dimensions will lead to poor results.')

            mds = model_config.matryoshka_dimensions
            if mds is not None:
                if self.dimensions not in mds:
                    raise ValueError(
                        f'Model "{model_config.served_model_name}" '
                        f'only supports {str(mds)} matryoshka dimensions, '
                        f'use other output dimensions will '
                        f'lead to poor results.')
            elif self.dimensions < 1:
                raise ValueError("Dimensions must be greater than 0")

    def __repr__(self) -> str:
        return (f"PoolingParams("
                f"dimensions={self.dimensions}, "
                f"task={self.task}, "
                f"requires_token_ids={self.requires_token_ids})")

    def __post_init__(self) -> None:
        assert self.output_kind == RequestOutputKind.FINAL_ONLY,\
            "For pooling output_kind has to be FINAL_ONLY"

dimensions class-attribute instance-attribute

dimensions: Optional[int] = None

output_kind class-attribute instance-attribute

requires_token_ids class-attribute instance-attribute

requires_token_ids: bool = False

Internal use only.

task class-attribute instance-attribute

task: Optional[PoolingTask] = None

Internal use only.

__post_init__

__post_init__() -> None
Source code in vllm/pooling_params.py
def __post_init__(self) -> None:
    assert self.output_kind == RequestOutputKind.FINAL_ONLY,\
        "For pooling output_kind has to be FINAL_ONLY"

__repr__

__repr__() -> str
Source code in vllm/pooling_params.py
def __repr__(self) -> str:
    return (f"PoolingParams("
            f"dimensions={self.dimensions}, "
            f"task={self.task}, "
            f"requires_token_ids={self.requires_token_ids})")

clone

clone() -> PoolingParams

Returns a deep copy of the PoolingParams instance.

Source code in vllm/pooling_params.py
def clone(self) -> "PoolingParams":
    """Returns a deep copy of the PoolingParams instance."""
    return PoolingParams(
        dimensions=self.dimensions,
        task=self.task,
        requires_token_ids=self.requires_token_ids,
    )

verify

verify(
    task: PoolingTask, model_config: ModelConfig
) -> None
Source code in vllm/pooling_params.py
def verify(self, task: PoolingTask, model_config: "ModelConfig") -> None:
    if self.task is None:
        self.task = task
    elif self.task != task:
        msg = f"You cannot overwrite {self.task=!r} with {task=!r}!"
        raise ValueError(msg)

    # NOTE: Task validation needs to done against the model instance,
    # which is not available in model config. So, it's not included
    # in this method

    if self.dimensions is not None:
        if not model_config.is_matryoshka:
            raise ValueError(
                f'Model "{model_config.served_model_name}" does not '
                f'support matryoshka representation, '
                f'changing output dimensions will lead to poor results.')

        mds = model_config.matryoshka_dimensions
        if mds is not None:
            if self.dimensions not in mds:
                raise ValueError(
                    f'Model "{model_config.served_model_name}" '
                    f'only supports {str(mds)} matryoshka dimensions, '
                    f'use other output dimensions will '
                    f'lead to poor results.')
        elif self.dimensions < 1:
            raise ValueError("Dimensions must be greater than 0")