vllm.renderers
¶
Modules:
-
base– -
chat_utils– -
cohere–Cohere prompt renderer.
-
embed_utils– -
hf– -
hy_v4– -
inkling–Native Inkling chat renderer for the Python frontend.
-
inkling_encoding–Inkling chat-encoding core.
-
inputs– -
kimi_k3– -
metrics–Prometheus metrics for the online renderers.
-
online_derenderer– -
online_renderer– -
params– -
registry– -
unlimited_ocr2–
Classes:
-
BaseRenderer– -
ChatParams–Configuration to control how to parse chat messages.
-
TokenizeParams–Configuration to control how prompts are tokenized.
Functions:
-
apply_max_tokenize_tokens–Validate and apply the server's max_tokenize_tokens limit to TokenizeParams.
-
map_reasoning_effort–Rewrite a requested effort to the one the chat template supports.
BaseRenderer
¶
Methods:
-
clear_mm_cache_async–Serialize clear_mm_cache through the multimodal executor to avoid
-
get_dec_start_token_id–Obtain the decoder start token id employed by an encoder/decoder model,
-
queue_mm_cache_invalidations–Coalesce stale sender entries without interrupting processing.
-
render_completion_suffix–Render OpenAI completion suffix input when the renderer supports FIM.
-
validate_request_chat_template–Check whether this renderer accepts template source from a request.
-
validate_token_ids–Raise VLLMValidationError if a token id is out of vocabulary.
-
warmup–Warm up this renderer to avoid first-request latency.
_apply_chat_media_io_kwargs(prompts, resolved_media_io_kwargs)
¶
Attach the fully-resolved chat media_io_kwargs to the prompts.
_apply_prompt_char_offset(prompt, char_offset)
staticmethod
¶
Map token offsets back to the original prompt after a text pre-trim.
_apply_prompt_media_io_kwargs(prompts, req_media_io_kwargs)
¶
Apply model defaults and request kwargs to prompts.
_build_tokens_prompt(token_ids, prompt, *, offset_mapping=None)
staticmethod
¶
Build a TokensPrompt from already-extracted token ids.
offset_mapping is the per-token (start, end) sequence from
a BatchEncoding; pass it only when offsets were requested, and it
is attached as prompt_token_offsets.
_can_produce_offsets()
¶
Whether this renderer's tokenizer can emit char-level offsets.
Defaults to False; only renderers backed by an HF fast tokenizer
(see HfRenderer) can produce offset_mapping.
_prepare_tokenizer(tokenizer)
¶
Modify the renderer's copy of an HF tokenizer before it is pooled.
Changes made after BaseRenderer.__init__ do not reach the pooled
copies.
_process_tokens(prompt, *, skip_mm_cache=False)
¶
Process token inputs, with multimodal preprocessing offloaded to the shared thread pool in the async variant.
_should_skip_decoder_start_token(decoder_prompt_token_ids)
¶
Whether the decoder prompt already carries its complete prefix.
_tokenize_text_prompt(prompt, params)
¶
Tokenize text and report whether the tokenizer truncated it.
_truncate_expanded_prompt(engine_input, params)
¶
Re-apply truncate_prompt_tokens once placeholders are expanded.
TokenizeParams.apply_post_tokenization truncates the prompt before
multimodal expansion, so a single placeholder token can expand into
many and push the result back over the requested bound.
Multimodal spans are never cut: a request whose spans would not all
survive intact is rejected, matching the post-expansion rejection in
vllm.v1.engine.input_processor._validate_model_input.
Only multimodal inputs can grow after apply_post_tokenization, so
everything else returns immediately.
clear_mm_cache_async()
async
¶
Serialize clear_mm_cache through the multimodal executor to avoid races with concurrent process_inputs on the mm_processor_cache.
get_dec_start_token_id()
¶
Obtain the decoder start token id employed by an encoder/decoder model, raising an error if it is not available.
queue_mm_cache_invalidations(mm_hashes)
¶
Coalesce stale sender entries without interrupting processing.
render_completion_suffix(prompt, suffix)
¶
Render OpenAI completion suffix input when the renderer supports FIM.
validate_request_chat_template()
¶
Check whether this renderer accepts template source from a request.
validate_token_ids(token_ids, *, parameter=None)
¶
Raise VLLMValidationError if a token id is out of vocabulary.
Without a tokenizer, the model vocab size is the only bound.
warmup(chat_params)
¶
Warm up this renderer to avoid first-request latency.
For chat requests: - Jinja2 template compilation
If a background multimodal warmup was launched (to overlap engine-core init) it is joined first so it is not still touching the mm_processor_cache. warmup_mm is idempotent, so the call below is a no-op if the background warmup — or a prior reset_mm_cache that joined it — already ran it.
ChatParams
dataclass
¶
Configuration to control how to parse chat messages.
Methods:
-
get_apply_chat_template_kwargs–The arguments to pass to
tokenizer.apply_chat_template.
Attributes:
-
chat_template(str | None) –The chat template to apply.
-
chat_template_content_format(ChatTemplateContentFormatOption) –The format of the chat template.
-
chat_template_kwargs(dict[str, Any]) –The kwargs to pass to the chat template.
-
media_io_kwargs(dict[str, dict[str, Any]] | None) –Per-modality kwargs for media I/O (loading/decoding images, videos, etc.).
-
mm_processor_kwargs(dict[str, Any] | None) –The kwargs to pass to the multi-modal processor.
-
parallel_tool_calls(bool) –Request-level
parallel_tool_callsfor renderers that need API metadata. -
response_format(Any | None) –Request-level response format for renderers that need API metadata.
-
tool_choice(Any | None) –Request-level tool choice for renderers that need API metadata.
chat_template = None
class-attribute
instance-attribute
¶
The chat template to apply.
chat_template_content_format = 'auto'
class-attribute
instance-attribute
¶
The format of the chat template.
chat_template_kwargs = field(default_factory=dict)
class-attribute
instance-attribute
¶
The kwargs to pass to the chat template.
media_io_kwargs = None
class-attribute
instance-attribute
¶
Per-modality kwargs for media I/O (loading/decoding images, videos, etc.).
mm_processor_kwargs = None
class-attribute
instance-attribute
¶
The kwargs to pass to the multi-modal processor.
parallel_tool_calls = True
class-attribute
instance-attribute
¶
Request-level parallel_tool_calls for renderers that need API metadata.
response_format = None
class-attribute
instance-attribute
¶
Request-level response format for renderers that need API metadata.
tool_choice = None
class-attribute
instance-attribute
¶
Request-level tool choice for renderers that need API metadata.
get_apply_chat_template_kwargs()
¶
The arguments to pass to tokenizer.apply_chat_template.
TokenizeParams
dataclass
¶
Configuration to control how prompts are tokenized.
Methods:
-
apply_post_tokenization–Ensure that the prompt meets the requirements set out by this config.
-
apply_pre_tokenization–Ensure that the prompt meets the requirements set out by this config.
-
get_encode_kwargs–The arguments to pass to
tokenizer.encode.
Attributes:
-
add_special_tokens(bool) –Whether to add special tokens.
-
do_lower_case(bool) –Whether to normalize text to lower case before tokenization.
-
max_input_tokens(int | None) –Maximum allowed number of input tokens.
-
max_output_tokens(int | None) –Maximum requested output tokens;
Nonemeans no explicit limit. -
max_output_tokens_param(str) –Override this to edit the message for validation errors.
-
max_total_tokens(int | None) –Maximum allowed number of input + output tokens.
-
max_total_tokens_param(str) –Override this to edit the message for validation errors.
-
max_truncation_tokens(int | None) –Maximum prompt length that truncation may reduce a prompt to.
-
needs_detokenization(bool) –Whether the tokenized prompt needs to contain the original text.
-
pad_prompt_tokens(int | None) –Number of tokens to pad to:
-
return_token_offsets(bool) –If true, request char-level (start, end) offsets per token. Honored
-
truncate_prompt_tokens(int | None) –Number of tokens to keep:
-
truncate_prompt_tokens_param(str) –Override this to edit the message for validation errors.
-
truncation_side(Literal['left', 'right'] | None) –Which side to truncate from when
truncate_prompt_tokensis active:
add_special_tokens = True
class-attribute
instance-attribute
¶
Whether to add special tokens.
do_lower_case = False
class-attribute
instance-attribute
¶
Whether to normalize text to lower case before tokenization.
max_input_tokens
property
¶
Maximum allowed number of input tokens.
max_output_tokens is not subtracted here: the value represents the
actual model context length, not a reservation of output space.
Downstream clamping of the sampling max_tokens is handled by
get_max_tokens() in the entrypoint layer.
max_output_tokens = 0
class-attribute
instance-attribute
¶
Maximum requested output tokens; None means no explicit limit.
Zero indicates a request that does not need generated tokens, such as pooling.
max_output_tokens_param = 'max_output_tokens'
class-attribute
instance-attribute
¶
Override this to edit the message for validation errors.
max_total_tokens
instance-attribute
¶
Maximum allowed number of input + output tokens.
Usually, this refers to the model's context length.
max_total_tokens_param = 'max_total_tokens'
class-attribute
instance-attribute
¶
Override this to edit the message for validation errors.
max_truncation_tokens
property
¶
Maximum prompt length that truncation may reduce a prompt to.
For generative requests this is max_input_tokens less one, holding a
token of context back for output. Truncating to the full
max_total_tokens would leave get_max_tokens() clamping the sampling
budget to 0, turning an over-long prompt into a silent zero-token
generation.
Pooling requests set max_output_tokens = 0 and emit an embedding
rather than generated tokens, so they keep the full input budget.
needs_detokenization = False
class-attribute
instance-attribute
¶
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 = None
class-attribute
instance-attribute
¶
Number of tokens to pad to:
- None means no padding.
- -1 maps to max_input_tokens.
return_token_offsets = False
class-attribute
instance-attribute
¶
If true, request char-level (start, end) offsets per token. Honored only for Fast (Rust-backed) tokenizers with text input and no multimodal data; otherwise silently ignored.
truncate_prompt_tokens = None
class-attribute
instance-attribute
¶
Number of tokens to keep:
- None means no truncation.
- -1 maps to max_input_tokens.
truncate_prompt_tokens_param = 'truncate_prompt_tokens'
class-attribute
instance-attribute
¶
Override this to edit the message for validation errors.
truncation_side = None
class-attribute
instance-attribute
¶
Which side to truncate from when truncate_prompt_tokens is active:
- "right" keeps the first N tokens (truncate from the end).
- "left" keeps the last N tokens (truncate from the start).
- None falls back to the tokenizer default.
_get_text_truncation_offset(tokenizer, text)
¶
Return the number of source characters removed from the left.
_text_len_check pre-truncates long text before tokenization when
an explicit truncation side is requested. Fast-tokenizer offsets are
then relative to that shortened string, so callers need this prefix
length to map them back to the original prompt.
_text_len_check(tokenizer, text)
¶
Apply length checks to prompt text if necessary.
_text_lowercase(tokenizer, text)
¶
Apply lowercase to prompt text if necessary.
_token_len_check(tokenizer, tokens)
¶
Apply length checks to prompt tokens if necessary.
_token_padding(tokenizer, tokens)
¶
Apply padding to prompt tokens if necessary.
_token_truncation(tokenizer, tokens)
¶
Apply truncation to prompt tokens if necessary.
_tokenizer_truncation_probe(num_tokens)
¶
Params to re-encode a text prompt with one more token of room.
Without an explicit truncation_side the tokenizer truncates by itself,
so a prompt cut to max_length tokens looks like one that fits exactly.
None unless num_tokens == max_length.
_truncation_slice(tokenizer, length)
¶
The slice truncation applies to a sequence of length tokens.
None means no truncation. Anything parallel to the prompt tokens
must be reduced with this same slice to stay aligned with them; list
such keys in _PARALLEL_TO_PROMPT_TOKENS.
_validate_text(tokenizer, text)
¶
Apply all validators to prompt text.
_validate_tokens(tokenizer, tokens)
¶
Apply all validators to a token sequence.
apply_post_tokenization(tokenizer, prompt)
¶
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.
apply_pre_tokenization(tokenizer, prompt)
¶
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.
get_encode_kwargs()
¶
The arguments to pass to tokenizer.encode.
apply_max_tokenize_tokens(tok_params, max_tokenize_tokens)
¶
Validate and apply the server's max_tokenize_tokens limit to TokenizeParams.
map_reasoning_effort(effort, effort_map)
¶
Rewrite a requested effort to the one the chat template supports.