vllm.tokenizers.detokenizer_utils ¶
Functions:
-
convert_ids_list_to_tokens–Detokenize the input ids individually.
-
convert_prompt_ids_to_tokens–Converts the prompt ids to tokens and returns the tokens and offsets
-
detokenize_incrementally–Detokenizes the input ids incrementally and returns the new tokens
_get_leading_space_marker(tokenizer) ¶
Read the space marker from the tokenizer's pre_tokenizer config.
Only Metaspace pre_tokenizers (used by SentencePiece-based models like Llama, Mistral, T5) have a replacement character whose leading instance gets stripped by decode(). ByteLevel (GPT-2), BertPreTokenizer (BERT), and others do not have this issue.
Returns the marker character, or None if decode() is safe for single tokens.
Source code in vllm/tokenizers/detokenizer_utils.py
_restore_leading_spaces(raw_token, token_str, marker) ¶
Restore leading spaces that decode() stripped from a raw vocab piece.
Source code in vllm/tokenizers/detokenizer_utils.py
convert_ids_list_to_tokens(tokenizer, token_ids) ¶
Detokenize the input ids individually.
Uses decode() for human-readable output, then checks the raw vocab piece via convert_ids_to_tokens() to restore any leading spaces that decode() stripped (SentencePiece add_dummy_prefix inverse).
Parameters:
-
(tokenizer¶TokenizerLike) –tokenizer used by model under test
-
(token_ids¶list[int]) –convert these tokens (Python list form)
Returns:
Source code in vllm/tokenizers/detokenizer_utils.py
convert_prompt_ids_to_tokens(tokenizer, prompt_ids, skip_special_tokens=False) ¶
Converts the prompt ids to tokens and returns the tokens and offsets for incremental detokenization.
Note that not all tokens are converted to strings. Only the tokens that are necessary for incremental detokenization are converted to strings.
Source code in vllm/tokenizers/detokenizer_utils.py
detokenize_incrementally(tokenizer, all_input_ids, prev_tokens, prefix_offset, read_offset, skip_special_tokens=False, spaces_between_special_tokens=True) ¶
Detokenizes the input ids incrementally and returns the new tokens and the new text.
If prev_tokens is None, this function will convert the input ids to tokens and return the tokens and the new text. Otherwise, it will return the new tokens and the new text.
This function will also return the new prefix offset and the new read offset to be used in the next iteration.
The offsets are necessary to defeat cleanup algorithms in the decode which decide to add a space or not depending on the surrounding ids.
Parameters:
-
(tokenizer¶TokenizerLike) –The tokenizer to use.
-
(all_input_ids¶list[int]) –The input ids. The last id is the new token id.
-
(prev_tokens¶list[str] | None) –The previous tokens. If None, this function will convert the input ids to tokens and return the tokens and the new text.
-
(prefix_offset¶int) –The prefix offset.
-
(read_offset¶int) –The read offset.
-
(skip_special_tokens¶bool, default:False) –Whether to skip special tokens.
-
(spaces_between_special_tokens¶bool, default:True) –Whether to add spaces between special tokens.
Source code in vllm/tokenizers/detokenizer_utils.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |