main
py 130 lines 3.27 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 from collections.abc import Sequence
4 from pathlib import Path
5 from typing import TYPE_CHECKING, Any, Protocol, overload
6
7 if TYPE_CHECKING:
8 from transformers import BatchEncoding
9
10 from vllm.entrypoints.chat_utils import ChatCompletionMessageParam
11
12
13 class TokenizerLike(Protocol):
14 @classmethod
15 def from_pretrained(
16 cls,
17 path_or_repo_id: str | Path,
18 *args,
19 trust_remote_code: bool = False,
20 revision: str | None = None,
21 download_dir: str | None = None,
22 **kwargs,
23 ) -> "TokenizerLike":
24 raise NotImplementedError
25
26 def num_special_tokens_to_add(self) -> int:
27 raise NotImplementedError
28
29 @property
30 def all_special_tokens(self) -> list[str]:
31 raise NotImplementedError
32
33 @property
34 def all_special_ids(self) -> list[int]:
35 raise NotImplementedError
36
37 @property
38 def bos_token_id(self) -> int:
39 raise NotImplementedError
40
41 @property
42 def eos_token_id(self) -> int:
43 raise NotImplementedError
44
45 @property
46 def pad_token_id(self) -> int:
47 raise NotImplementedError
48
49 @property
50 def is_fast(self) -> bool:
51 raise NotImplementedError
52
53 @property
54 def vocab_size(self) -> int:
55 raise NotImplementedError
56
57 @property
58 def max_token_id(self) -> int:
59 raise NotImplementedError
60
61 @property
62 def max_chars_per_token(self) -> int:
63 raise NotImplementedError
64
65 @property
66 def truncation_side(self) -> str:
67 raise NotImplementedError
68
69 def __hash__(self) -> int:
70 return hash(id(self))
71
72 def __len__(self) -> int:
73 return self.vocab_size
74
75 def __call__(
76 self,
77 text: str | list[str],
78 text_pair: str | None = None,
79 add_special_tokens: bool = True,
80 truncation: bool = False,
81 max_length: int | None = None,
82 ) -> "BatchEncoding":
83 raise NotImplementedError
84
85 def get_vocab(self) -> dict[str, int]:
86 raise NotImplementedError
87
88 def get_added_vocab(self) -> dict[str, int]:
89 raise NotImplementedError
90
91 def encode(
92 self,
93 text: str,
94 truncation: bool | None = None,
95 max_length: int | None = None,
96 add_special_tokens: bool = True,
97 ) -> list[int]:
98 raise NotImplementedError
99
100 def apply_chat_template(
101 self,
102 messages: list["ChatCompletionMessageParam"],
103 tools: list[dict[str, Any]] | None = None,
104 **kwargs,
105 ) -> str | list[int]:
106 raise NotImplementedError
107
108 @overload
109 def convert_tokens_to_ids(self, tokens: str) -> int: ...
110
111 @overload
112 def convert_tokens_to_ids(self, tokens: list[str]) -> list[int]: ...
113
114 def convert_tokens_to_ids(self, tokens: str | list[str]) -> int | list[int]:
115 raise NotImplementedError
116
117 def convert_tokens_to_string(self, tokens: list[str]) -> str:
118 raise NotImplementedError
119
120 def decode(
121 self, ids: Sequence[int] | int, skip_special_tokens: bool = False
122 ) -> str:
123 raise NotImplementedError
124
125 def convert_ids_to_tokens(
126 self,
127 ids: Sequence[int],
128 skip_special_tokens: bool = False,
129 ) -> list[str]:
130 raise NotImplementedError