| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | from collections.abc import Callable |
| 4 | from dataclasses import dataclass |
| 5 | from typing import TypeVar |
| 6 | |
| 7 | import torch |
| 8 | |
| 9 | from vllm.pooling_params import PoolingParams |
| 10 | |
| 11 | _T = TypeVar("_T", bound=torch.Tensor | list[torch.Tensor]) |
| 12 | |
| 13 | ProjectorFn = Callable[[torch.Tensor], torch.Tensor] |
| 14 | ClassifierFn = Callable[[torch.Tensor], torch.Tensor] |
| 15 | ActivationFn = Callable[[_T], _T] |
| 16 | |
| 17 | |
| 18 | @dataclass(frozen=True) |
| 19 | class PoolingParamsUpdate: |
| 20 | requires_token_ids: bool = False |
| 21 | """Set this flag to enable CPU prompt token IDs for your pooler.""" |
| 22 | |
| 23 | def __or__(self, other: "PoolingParamsUpdate") -> "PoolingParamsUpdate": |
| 24 | return PoolingParamsUpdate( |
| 25 | requires_token_ids=self.requires_token_ids or other.requires_token_ids, |
| 26 | ) |
| 27 | |
| 28 | def apply(self, params: PoolingParams) -> None: |
| 29 | params.requires_token_ids = self.requires_token_ids |
| 30 | |
| 31 | |
| 32 | __all__ = ["ActivationFn", "ClassifierFn", "ProjectorFn", "PoolingParamsUpdate"] |