Skip to content

vllm.renderers.inputs.preprocess

Schemas and utilites for preprocessing inputs.

DecoderDictPrompt module-attribute

DecoderDictPrompt: TypeAlias = TextPrompt | TokensPrompt

A DecoderPrompt that has been standardized into a dictionary.

DecoderOnlyDictPrompt module-attribute

DecoderOnlyDictPrompt: TypeAlias = (
    TextPrompt | TokensPrompt | EmbedsPrompt
)

A DecoderOnlyPrompt that has been standardized into a dictionary.

DictPrompt module-attribute

A PromptType that has been standardized into a dictionary.

EncoderDictPrompt module-attribute

EncoderDictPrompt: TypeAlias = TextPrompt | TokensPrompt

A EncoderPrompt that has been standardized into a dictionary.

SingletonDictPrompt module-attribute

A SingletonPrompt that has been standardized into a dictionary.

EncoderDecoderDictPrompt

Bases: TypedDict

A EncoderDecoderPrompt that has been standardized into a dictionary.

Source code in vllm/renderers/inputs/preprocess.py
class EncoderDecoderDictPrompt(TypedDict):
    """
    A [`EncoderDecoderPrompt`][vllm.inputs.data.EncoderDecoderPrompt]
    that has been standardized into a dictionary.
    """

    encoder_prompt: EncoderDictPrompt

    decoder_prompt: DecoderDictPrompt | None

parse_dec_only_prompt

parse_dec_only_prompt(
    prompt: object,
) -> DecoderOnlyDictPrompt

Parse a prompt for a decoder-only model and normalize it to a dictionary.

Source code in vllm/renderers/inputs/preprocess.py
def parse_dec_only_prompt(prompt: object) -> DecoderOnlyDictPrompt:
    """
    Parse a prompt for a decoder-only model and normalize it to a dictionary.
    """
    if isinstance(prompt, str):
        return TextPrompt(prompt=prompt)

    if isinstance(prompt, list):
        if not is_list_of(prompt, int):
            raise TypeError("Token prompt should be a list of integers")

        return TokensPrompt(prompt_token_ids=prompt)

    if isinstance(prompt, dict):
        if "encoder_prompt" in prompt:
            raise TypeError("Cannot pass encoder-decoder prompt to decoder-only models")

        if (
            "prompt" in prompt
            or "prompt_token_ids" in prompt
            or "prompt_embeds" in prompt
        ):
            return prompt  # type: ignore[return-value]

        raise TypeError("Prompt dictionary must contain text, tokens, or embeddings")

    raise TypeError("Prompt should be a string, list of tokens, or dictionary")

parse_enc_dec_prompt

parse_enc_dec_prompt(
    prompt: object,
) -> EncoderDecoderDictPrompt

Parse a prompt for an encoder-decoder model and normalize it to a dictionary.

Source code in vllm/renderers/inputs/preprocess.py
def parse_enc_dec_prompt(prompt: object) -> EncoderDecoderDictPrompt:
    """
    Parse a prompt for an encoder-decoder model and normalize it to a dictionary.
    """
    if isinstance(prompt, dict) and "encoder_prompt" in prompt:
        enc_prompt: object = prompt["encoder_prompt"]  # type: ignore[typeddict-item]
        dec_prompt: object | None = prompt["decoder_prompt"]  # type: ignore[typeddict-item]
    else:
        enc_prompt = prompt
        dec_prompt = None

    return EncoderDecoderDictPrompt(
        encoder_prompt=_parse_enc_prompt(enc_prompt),
        decoder_prompt=None if dec_prompt is None else _parse_dec_prompt(dec_prompt),
    )