vllm.entrypoints.renderer ¶
BaseRenderer ¶
Bases: ABC
Base class for unified input processing and rendering.
The Renderer serves as a unified input processor that consolidates tokenization, chat template formatting, and multimodal input handling into a single component. It converts high-level API requests (OpenAI-style JSON) into token IDs and multimodal features ready for engine consumption.
Key responsibilities: - Convert text prompts to token sequences with proper special tokens - Apply chat templates and format conversations - Handle multimodal inputs (images, audio, etc.) when applicable - Manage prompt truncation and length validation - Provide clean separation between API layer and engine core
Source code in vllm/entrypoints/renderer.py
__init__ ¶
__init__(
model_config: ModelConfig,
tokenizer: Optional[AnyTokenizer] = None,
)
render_prompt abstractmethod async ¶
render_prompt(
prompt_or_prompts: Union[
str, list[str], list[int], list[list[int]]
],
max_length: Optional[int] = None,
truncate_prompt_tokens: Optional[
Annotated[int, Field(ge=-1)]
] = None,
add_special_tokens: Optional[bool] = True,
cache_salt: Optional[str] = None,
) -> list[TokensPrompt]
Convert input prompts into tokenized format for engine processing.
This is the core method that transforms various input formats into standardized TokensPrompt objects. Implementations should handle tokenization, special token insertion, truncation, and validation according to model requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt_or_prompts | Union[str, list[str], list[int], list[list[int]]] | Input data in various formats: - str: Single text prompt - list[str]: Batch of text prompts | required |
max_length | Optional[int] | Maximum sequence length (endpoint-specific behavior) | None |
truncate_prompt_tokens | Optional[Annotated[int, Field(ge=-1)]] | Truncate to last N tokens (None=no truncation, 0=empty) | None |
add_special_tokens | Optional[bool] | Add model-specific tokens (e.g., [CLS], [SEP]) to text inputs | True |
cache_salt | Optional[str] | Optional string to disambiguate cached prompts | None |
Returns:
| Type | Description |
|---|---|
list[TokensPrompt] | list[EngineTokensPrompt]: Tokenized prompts ready for engine consumption |
Raises:
| Type | Description |
|---|---|
ValueError | If input format is invalid or length limits exceeded |
Source code in vllm/entrypoints/renderer.py
CompletionRenderer ¶
Bases: BaseRenderer
Source code in vllm/entrypoints/renderer.py
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 | |
__init__ ¶
__init__(
model_config: ModelConfig,
tokenizer: Optional[AnyTokenizer] = None,
async_tokenizer_pool: Optional[
dict[AnyTokenizer, AsyncMicrobatchTokenizer]
] = None,
)
Source code in vllm/entrypoints/renderer.py
_create_tokens_prompt ¶
_create_tokens_prompt(
token_ids: list[int],
max_length: Optional[int] = None,
cache_salt: Optional[str] = None,
) -> TokensPrompt
Create validated EngineTokensPrompt.
Source code in vllm/entrypoints/renderer.py
_get_async_tokenizer ¶
_get_async_tokenizer() -> AsyncMicrobatchTokenizer
Get or create async tokenizer using shared pool.
Source code in vllm/entrypoints/renderer.py
_maybe_apply_truncation ¶
_maybe_apply_truncation(
token_ids: list[int],
truncate_prompt_tokens: Optional[int],
) -> list[int]
Apply truncation to token sequence.
Source code in vllm/entrypoints/renderer.py
_tokenize async ¶
_tokenize(
text: str,
max_length: Optional[int],
truncate_prompt_tokens: Optional[int],
add_special_tokens: Optional[bool],
cache_salt: Optional[str],
) -> TokensPrompt
Tokenize text input asynchronously.
Source code in vllm/entrypoints/renderer.py
render_prompt async ¶
render_prompt(
prompt_or_prompts: Union[
str, list[str], list[int], list[list[int]]
],
max_length: Optional[int] = None,
truncate_prompt_tokens: Optional[
Annotated[int, Field(ge=-1)]
] = None,
add_special_tokens: Optional[bool] = True,
cache_salt: Optional[str] = None,
) -> list[TokensPrompt]
Implementation of prompt rendering for completion-style requests.
Uses async tokenizer pooling for improved performance. See base class for detailed parameter documentation.