Skip to content

vllm.renderers.base

Classes:

BaseRenderer

Bases: ABC, Generic[_T]

Methods:

_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.

_SwappableExecutor

Bases: Executor

Executor whose inner pool can be replaced without changing identity.

make_async captures the executor object at wrap time. Replacing self._executor with a new ThreadPoolExecutor would leave those wrappers (tokenize, decode, pooling, derender) bound to a shutdown pool.