fix(hf): handle ModelOption.THINKING chat templates - #1588
Open
planetf1 wants to merge 5 commits into
Open
Conversation
Assisted-by: Codex Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Assisted-by: Codex Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Assisted-by: Codex Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Assisted-by: Codex Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
planetf1
marked this pull request as ready for review
August 26, 2026 09:48
planetf1
requested review from
AngeloDanducci,
akihikokuroda,
jakelorocco and
markstur
August 26, 2026 09:48
Assisted-by: Codex Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
jakelorocco
reviewed
Aug 26, 2026
jakelorocco
left a comment
Contributor
There was a problem hiding this comment.
agree with the approach; I think there's a few small concerns
Comment on lines
+2087
to
+2092
| if ( | ||
| thinking_template_var is not None | ||
| and type(model_options.get(ModelOption.THINKING)) is bool | ||
| and thinking_template_var not in backend_opts | ||
| ): | ||
| backend_opts[thinking_template_var] = model_options[ModelOption.THINKING] |
Contributor
There was a problem hiding this comment.
This only forwards the value if it's a bool. That seems to differ slightly from the docstring updates, and I'm not sure it's the correct behavior.
| ) | ||
| if ( | ||
| thinking_template_var is not None | ||
| and type(model_options.get(ModelOption.THINKING)) is bool |
Contributor
There was a problem hiding this comment.
Can you please include a comment here that this is using model_options and specifically not using the backend_opts that have the THINKING flags removed?
Contributor
There was a problem hiding this comment.
This being after the backend specificity flag also causes ordering differences between the other backends and hf. For instance:
dict = {ModelOption.THINKING: True, "thinking": False}
# Ollama
backend_dict = {"thinking": True} # Since _make_backend_specific_and_remove prefers the ModelOption sentinel
# HF
backend_dict = {"thinking": False} # Since _make_backend_specific_and_remove gets rid of the THINKING sentinel; causing the regular "thinking" option to take precedence when looking if it exists in the `backend_opts` dict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Issue
Fixes #1212
Description
LocalHFBackendpreviously removedModelOption.THINKINGbefore applying thetokenizer chat template. This change detects the template's supported thinking
variable (
think,thinking, orenable_thinking) and forwards booleanvalues under that name. It also canonicalises native aliases during option
resolution, so per-call options correctly override backend defaults.
This PR deliberately does not add Granite 4.2 model identifiers or change
defaults; #1587 owns that work and its GPU span coverage. The tokenizer-only
integration test uses the public Granite 4.2 3B ID directly to prove the
generic mapping works with the template that first exposes a thinking control.
During validation, the parallel tool-call regression tests were found to create
a live Ollama backend despite exercising only formatter behaviour. This PR
switches them to the existing mocked backend fixture so the local suite does
not require Ollama for those tests.
Testing
uv run pytest test/backends/test_huggingface_filter_options.py -q: 33 passed, 3 skipped; Granite 4.2 tokenizer regression executeduv run pytest test/backends/test_acall_tools_parallel_execution.py -q: 4 passed without Ollamauv run ruff format --check . && uv run ruff check .: passeduv run mypy .: passeduv run pytest test/ -m "not qualitative": 3,988 passed, 179 skipped, 128 deselected, 1 xpassedAttribution
Adding a new component, requirement, sampling strategy, or tool?
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.