vllm.renderers ¶
Modules:
| Name | Description |
|---|---|
deepseek_v32 | |
embed_utils | |
grok2 | |
hf | |
mistral | |
params | |
protocol | |
registry | |
terratorch | |
__all__ module-attribute ¶
__all__ = [
"BaseRenderer",
"RendererRegistry",
"renderer_from_config",
"ChatParams",
"TokenizeParams",
"merge_kwargs",
]
BaseRenderer ¶
Bases: ABC
Source code in vllm/renderers/protocol.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 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 196 | |
__init__ ¶
__init__(config: ModelConfig) -> None
from_config abstractmethod classmethod ¶
from_config(
config: ModelConfig, tokenizer_kwargs: dict[str, Any]
) -> BaseRenderer
get_async_tokenizer ¶
get_async_tokenizer() -> AsyncMicrobatchTokenizer
get_tokenizer ¶
get_tokenizer() -> TokenizerLike
render_completion ¶
render_completion(
prompt_raw: str | list[int] | bytes,
) -> TextPrompt | TokensPrompt | EmbedsPrompt
Source code in vllm/renderers/protocol.py
render_completions ¶
render_completions(
prompt_input: str
| list[str]
| list[int]
| list[list[int]]
| None = None,
prompt_embeds: bytes | list[bytes] | None = None,
) -> list[TextPrompt | TokensPrompt | EmbedsPrompt]
Source code in vllm/renderers/protocol.py
render_completions_async async ¶
render_completions_async(
prompt_input: str
| list[str]
| list[int]
| list[list[int]]
| None = None,
prompt_embeds: bytes | list[bytes] | None = None,
) -> list[TextPrompt | TokensPrompt | EmbedsPrompt]
Source code in vllm/renderers/protocol.py
render_messages abstractmethod ¶
render_messages(
messages: list[ChatCompletionMessageParam],
params: ChatParams,
) -> tuple[
list[ConversationMessage],
TextPrompt | TokensPrompt | EmbedsPrompt,
]
render_messages_async async ¶
render_messages_async(
messages: list[ChatCompletionMessageParam],
params: ChatParams,
) -> tuple[
list[ConversationMessage],
TextPrompt | TokensPrompt | EmbedsPrompt,
]
tokenize_prompt ¶
tokenize_prompt(
prompt: TextPrompt | TokensPrompt | EmbedsPrompt,
params: TokenizeParams,
) -> TokensPrompt | EmbedsPrompt
Source code in vllm/renderers/protocol.py
tokenize_prompt_async async ¶
tokenize_prompt_async(
prompt: TextPrompt | TokensPrompt | EmbedsPrompt,
params: TokenizeParams,
) -> TokensPrompt | EmbedsPrompt
Source code in vllm/renderers/protocol.py
tokenize_prompts ¶
tokenize_prompts(
prompts: list[TextPrompt | TokensPrompt | EmbedsPrompt],
params: TokenizeParams,
) -> list[TokensPrompt | EmbedsPrompt]
tokenize_prompts_async async ¶
tokenize_prompts_async(
prompts: list[TextPrompt | TokensPrompt | EmbedsPrompt],
params: TokenizeParams,
) -> list[TokensPrompt | EmbedsPrompt]
Source code in vllm/renderers/protocol.py
ChatParams dataclass ¶
Configuration to control how to parse chat messages.
Source code in vllm/renderers/params.py
chat_template class-attribute instance-attribute ¶
chat_template: str | None = None
The chat template to apply.
chat_template_content_format class-attribute instance-attribute ¶
chat_template_content_format: ChatTemplateContentFormatOption = "auto"
The format of the chat template.
chat_template_kwargs class-attribute instance-attribute ¶
The kwargs to pass to the chat template.
__init__ ¶
__init__(
chat_template: str | None = None,
chat_template_content_format: ChatTemplateContentFormatOption = "auto",
chat_template_kwargs: dict[str, Any] = dict(),
) -> None
get_apply_chat_template_kwargs ¶
The arguments to pass to tokenizer.apply_chat_template.
with_defaults ¶
Source code in vllm/renderers/params.py
RendererRegistry dataclass ¶
Source code in vllm/renderers/registry.py
renderers class-attribute instance-attribute ¶
load_renderer ¶
load_renderer(
renderer_mode: str,
config: ModelConfig,
tokenizer_kwargs: dict[str, Any],
) -> BaseRenderer
load_renderer_cls ¶
load_renderer_cls(renderer_mode: str) -> type[BaseRenderer]
Source code in vllm/renderers/registry.py
register ¶
Source code in vllm/renderers/registry.py
TokenizeParams dataclass ¶
Configuration to control how prompts are tokenized.
Source code in vllm/renderers/params.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 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 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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
add_special_tokens class-attribute instance-attribute ¶
add_special_tokens: bool = True
Whether to add special tokens.
do_lower_case class-attribute instance-attribute ¶
do_lower_case: bool = False
Whether to normalize text to lower case before tokenization.
max_output_tokens class-attribute instance-attribute ¶
max_output_tokens: int = 0
Maximum requested number of output tokens.
max_output_tokens_param class-attribute instance-attribute ¶
max_output_tokens_param: str = 'max_output_tokens'
Override this to edit the message for validation errors.
max_total_tokens instance-attribute ¶
max_total_tokens: int | None
Maximum allowed number of input + output tokens.
Usually, this refers to the model's context length.
max_total_tokens_param class-attribute instance-attribute ¶
max_total_tokens_param: str = 'max_total_tokens'
Override this to edit the message for validation errors.
needs_detokenization class-attribute instance-attribute ¶
needs_detokenization: bool = False
Whether the tokenized prompt needs to contain the original text.
Not to be confused with SamplingParams.detokenize which deals with the output generated by the model.
pad_prompt_tokens class-attribute instance-attribute ¶
pad_prompt_tokens: int | None = None
Number of tokens to pad to: - None means no padding. - -1 maps to max_input_tokens.
truncate_prompt_tokens class-attribute instance-attribute ¶
truncate_prompt_tokens: int | None = None
Number of tokens to keep: - None means no truncation. - -1 maps to max_input_tokens.
truncate_prompt_tokens_param class-attribute instance-attribute ¶
truncate_prompt_tokens_param: str = "truncate_prompt_tokens"
Override this to edit the message for validation errors.
__init__ ¶
__init__(
max_total_tokens: int | None,
max_output_tokens: int = 0,
pad_prompt_tokens: int | None = None,
truncate_prompt_tokens: int | None = None,
do_lower_case: bool = False,
add_special_tokens: bool = True,
needs_detokenization: bool = False,
max_total_tokens_param: str = "max_total_tokens",
max_output_tokens_param: str = "max_output_tokens",
truncate_prompt_tokens_param: str = "truncate_prompt_tokens",
) -> None
__post_init__ ¶
Source code in vllm/renderers/params.py
_apply_length_check ¶
_apply_length_check(
tokenizer: TokenizerLike | None, tokens: _S
) -> _S
Apply length checks to a token sequence.
Source code in vllm/renderers/params.py
_apply_lowercase ¶
_apply_lowercase(
tokenizer: TokenizerLike | None, text: str
) -> str
_apply_padding ¶
_apply_padding(
tokenizer: TokenizerLike | None, tokens: _S
) -> _S
Apply padding to a token sequence.
Source code in vllm/renderers/params.py
_apply_truncation ¶
_apply_truncation(
tokenizer: TokenizerLike | None, tokens: _S
) -> _S
Apply truncation to a token sequence.
Source code in vllm/renderers/params.py
_validate_text ¶
_validate_text(
tokenizer: TokenizerLike | None, text: str
) -> str
Apply all validators to prompt text.
Source code in vllm/renderers/params.py
_validate_tokens ¶
_validate_tokens(
tokenizer: TokenizerLike | None, tokens: _S
) -> _S
Apply all validators to a token sequence.
Source code in vllm/renderers/params.py
apply_post_tokenization ¶
apply_post_tokenization(
tokenizer: TokenizerLike | None,
prompt: TokensPrompt | EmbedsPrompt,
) -> TokensPrompt | EmbedsPrompt
Ensure that the prompt meets the requirements set out by this config. If that is not possible, raise a VLLMValidationError.
This method is run after tokenization occurs.
Source code in vllm/renderers/params.py
apply_pre_tokenization ¶
apply_pre_tokenization(
tokenizer: TokenizerLike | None, prompt: TextPrompt
) -> TextPrompt
Ensure that the prompt meets the requirements set out by this config. If that is not possible, raise a VLLMValidationError.
This method is run before tokenization occurs.
Source code in vllm/renderers/params.py
get_encode_kwargs ¶
The arguments to pass to tokenizer.encode.
Source code in vllm/renderers/params.py
with_kwargs ¶
Source code in vllm/renderers/params.py
merge_kwargs ¶
merge_kwargs(
defaults: dict[str, Any] | None,
overrides: dict[str, Any] | None,
/,
*,
unset_values: tuple[object, ...] = (None, "auto"),
) -> dict[str, Any]
Source code in vllm/renderers/params.py
renderer_from_config ¶
renderer_from_config(config: ModelConfig, **kwargs)