vllm.tokenizers.hf ¶
Classes:
-
ThreadSafeHFTokenizerMixin–Mixin class for thread-safe HF fast tokenizers.
Functions:
-
get_cached_tokenizer–By default, transformers will recompute multiple tokenizer properties
-
maybe_make_thread_pool–If
tokenizeris aTokenizersBackend, modify the tokenizer
ThreadSafeHFTokenizerMixin ¶
get_cached_tokenizer(tokenizer) ¶
By default, transformers will recompute multiple tokenizer properties each time they are called, leading to a significant slowdown. This proxy caches these properties for faster access.
Source code in vllm/tokenizers/hf.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
maybe_make_thread_pool(tokenizer, copies=1) ¶
If tokenizer is a TokenizersBackend, modify the tokenizer in-place to make the public interface thread-safe by routing calls through a deep-copied tokenizer pool.
Note that: - Only TokenizerLike's public interface is thread-safe. This doesn't include _tokenizer property nor any mutation methods like add_special_tokens or add_tokens. - Adjacent method calls could happen on different deep copies.