Skip to content

apply_chat_template receives generate-only options from _make_backend_specific_and_remove #1154

Closed

Description

@planetf1

`_make_backend_specific_and_remove` is called at two `apply_chat_template` sites in `LocalHFBackend` (lines 805 and 1087 in `huggingface.py`) and its output is splatted directly into the tokenizer call. This means generate-only options such as `temperature`, `max_new_tokens`, and (since #1149) `do_sample` end up in the Jinja template's variable namespace.

HuggingFace templates silently ignore unknown kwargs, so there is no visible failure today. The risk is that a future template that happens to reference any of those names would be silently shadowed by user-supplied generation parameters, leading to unexpected rendering behaviour.

`_filter_chat_template_only_options` already strips template-only keys (e.g. `guardian_config`, `think`) before passing options to `generate()`. The inverse — stripping generate-only keys before passing to `apply_chat_template` — does not exist.

Spotted during review of #1149.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions