Skip to content

vllm.renderers.inkling

Native Inkling chat renderer for the Python frontend.

Mirrors the Rust frontend's native Inkling renderer (rust/src/chat/src/renderer/inkling/mod.rs): chat messages are rendered directly to token ids — Inkling has no Jinja chat template and no faithful text form.

The encoding logic lives in inkling_encoding.py behind a narrow "OpenAI messages + tools -> token ids" call; see the swap-point comment in :meth:InklingRenderer._render for adopting a standalone Inkling input-processing library (mistral-common style) later.

_HfBackedTmlTokenizer

Adapts an HF tokenizer to the encoding core's tokenizer protocol.

Special-token ids are resolved from the tokenizer vocab at construction (never hardcoded), trying each known spelling — the Inkling HF vocab exposes some semantic slots as <|unused_NNNNNN|> tokens.

Source code in vllm/renderers/inkling.py
class _HfBackedTmlTokenizer:
    """Adapts an HF tokenizer to the encoding core's tokenizer protocol.

    Special-token ids are resolved from the tokenizer vocab at
    construction (never hardcoded), trying each known spelling — the Inkling
    HF vocab exposes some semantic slots as ``<|unused_NNNNNN|>`` tokens.
    """

    def __init__(self, tokenizer: HfTokenizer) -> None:
        self._tokenizer = tokenizer

        vocab = tokenizer.get_vocab()
        special_ids: dict[str, int] = {}
        missing: list[str] = []
        for token, spellings in SPECIAL_TOKEN_SPELLINGS.items():
            for spelling in spellings:
                token_id = vocab.get(spelling)
                if token_id is not None:
                    special_ids[token] = token_id
                    break
            else:
                missing.append(token)
        if missing:
            raise ValueError(f"Inkling tokenizer is missing special tokens: {missing}")
        self._special_ids = special_ids

    def encode_text(self, text: str) -> list[int]:
        return self._tokenizer.encode(text, add_special_tokens=False)

    def encode_special(self, token: str) -> int:
        return self._special_ids[token]