main
py 44 lines 1.38 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 from typing import Literal, get_args
4
5 from vllm.exceptions import VLLMValidationError
6
7 GenerationTask = Literal["generate", "transcription", "realtime"]
8 GENERATION_TASKS: tuple[GenerationTask, ...] = get_args(GenerationTask)
9
10 PoolingTask = Literal[
11 "embed",
12 "classify",
13 "token_embed",
14 "token_classify",
15 "plugin",
16 "embed&token_classify",
17 ]
18 POOLING_TASKS: tuple[PoolingTask, ...] = get_args(PoolingTask)
19
20 _REMOVED_POOLING_TASK_MESSAGES = {
21 "score": "`score` task was removed; use `classify` instead.",
22 "encode": (
23 "`encode` task was removed; use `token_embed` or `token_classify` instead."
24 ),
25 }
26
27
28 def check_removed_pooling_task(task: object) -> None:
29 if isinstance(task, str) and (message := _REMOVED_POOLING_TASK_MESSAGES.get(task)):
30 raise VLLMValidationError(message, parameter="task")
31
32
33 ScoreType = Literal["bi-encoder", "cross-encoder", "late-interaction"]
34 SCORE_TYPE_MAP: dict[PoolingTask, ScoreType] = {
35 "embed": "bi-encoder",
36 "classify": "cross-encoder",
37 "token_embed": "late-interaction",
38 }
39
40 FrontendTask = Literal["render"]
41 FRONTEND_TASKS: tuple[FrontendTask, ...] = get_args(FrontendTask)
42
43 SupportedTask = Literal[GenerationTask, PoolingTask, FrontendTask]
44 FALLBACK_SUPPORTED_TASKS: tuple[SupportedTask, ...] = ("generate",)