2
2
3
3
import importlib
4
4
from abc import ABC , abstractmethod
5
- from typing import TYPE_CHECKING , Any , Dict , List , Optional , Tuple , Union
5
+ from typing import TYPE_CHECKING , Any , Optional , Union
6
6
7
7
if TYPE_CHECKING :
8
8
from vllm .entrypoints .chat_utils import ChatCompletionMessageParam
@@ -12,17 +12,17 @@ class TokenizerBase(ABC):
12
12
13
13
@property
14
14
@abstractmethod
15
- def all_special_tokens_extended (self ) -> List [str ]:
15
+ def all_special_tokens_extended (self ) -> list [str ]:
16
16
raise NotImplementedError ()
17
17
18
18
@property
19
19
@abstractmethod
20
- def all_special_tokens (self ) -> List [str ]:
20
+ def all_special_tokens (self ) -> list [str ]:
21
21
raise NotImplementedError ()
22
22
23
23
@property
24
24
@abstractmethod
25
- def all_special_ids (self ) -> List [int ]:
25
+ def all_special_ids (self ) -> list [int ]:
26
26
raise NotImplementedError ()
27
27
28
28
@property
@@ -66,7 +66,7 @@ def __len__(self) -> int:
66
66
@abstractmethod
67
67
def __call__ (
68
68
self ,
69
- text : Union [str , List [str ], List [int ]],
69
+ text : Union [str , list [str ], list [int ]],
70
70
text_pair : Optional [str ] = None ,
71
71
add_special_tokens : bool = False ,
72
72
truncation : bool = False ,
@@ -75,11 +75,11 @@ def __call__(
75
75
raise NotImplementedError ()
76
76
77
77
@abstractmethod
78
- def get_vocab (self ) -> Dict [str , int ]:
78
+ def get_vocab (self ) -> dict [str , int ]:
79
79
raise NotImplementedError ()
80
80
81
81
@abstractmethod
82
- def get_added_vocab (self ) -> Dict [str , int ]:
82
+ def get_added_vocab (self ) -> dict [str , int ]:
83
83
raise NotImplementedError ()
84
84
85
85
@abstractmethod
@@ -88,44 +88,44 @@ def encode_one(
88
88
text : str ,
89
89
truncation : bool = False ,
90
90
max_length : Optional [int ] = None ,
91
- ) -> List [int ]:
91
+ ) -> list [int ]:
92
92
raise NotImplementedError ()
93
93
94
94
@abstractmethod
95
95
def encode (self ,
96
96
text : str ,
97
- add_special_tokens : Optional [bool ] = None ) -> List [int ]:
97
+ add_special_tokens : Optional [bool ] = None ) -> list [int ]:
98
98
raise NotImplementedError ()
99
99
100
100
@abstractmethod
101
101
def apply_chat_template (self ,
102
- messages : List ["ChatCompletionMessageParam" ],
103
- tools : Optional [List [ Dict [str , Any ]]] = None ,
104
- ** kwargs ) -> List [int ]:
102
+ messages : list ["ChatCompletionMessageParam" ],
103
+ tools : Optional [list [ dict [str , Any ]]] = None ,
104
+ ** kwargs ) -> list [int ]:
105
105
raise NotImplementedError ()
106
106
107
107
@abstractmethod
108
- def convert_tokens_to_string (self , tokens : List [str ]) -> str :
108
+ def convert_tokens_to_string (self , tokens : list [str ]) -> str :
109
109
raise NotImplementedError ()
110
110
111
111
@abstractmethod
112
112
def decode (self ,
113
- ids : Union [List [int ], int ],
113
+ ids : Union [list [int ], int ],
114
114
skip_special_tokens : bool = True ) -> str :
115
115
raise NotImplementedError ()
116
116
117
117
@abstractmethod
118
118
def convert_ids_to_tokens (
119
119
self ,
120
- ids : List [int ],
120
+ ids : list [int ],
121
121
skip_special_tokens : bool = True ,
122
- ) -> List [str ]:
122
+ ) -> list [str ]:
123
123
raise NotImplementedError ()
124
124
125
125
126
126
class TokenizerRegistry :
127
127
# Tokenizer name -> (tokenizer module, tokenizer class)
128
- REGISTRY : Dict [str , Tuple [str , str ]] = {}
128
+ REGISTRY : dict [str , tuple [str , str ]] = {}
129
129
130
130
@staticmethod
131
131
def register (name : str , module : str , class_name : str ) -> None :
0 commit comments