Repository navigation
fix(hf): forward string THINKING levels as reasoning_effort, not low_effort - #1639
Merged
Merged
Conversation
LocalHFBackend._filter_for_chat_template only set the chat template's thinking variable when ModelOption.THINKING was a bool, so a string level like "low" was silently dropped and Granite fell back to full default thinking with no error. Granite 4.2's chat template implements a separate boolean `low_effort` variable, distinct from the bool-valued thinking vars (think/thinking/ enable_thinking), driven by a string reasoning-effort level. Mirror the OpenAI backend's reasoning_effort handling: translate THINKING="low" into low_effort=True when the template declares that variable. Other string levels remain no-ops, matching Granite's template (no "high" branch on the model side). Verified end-to-end against ibm-granite/granite-4.2-3b: with THINKING="low" the model now produces short reasoning and reaches an answer, instead of exhausting the token budget in full-length reasoning. Fixes generative-computing#1636 Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
…effort Code review found the previous fix targeted the wrong mechanism: Granite 4.2's chat template derives its boolean `low_effort` variable from `reasoning_effort == "low"` (chat_template.jinja), and gpt-oss's HF chat template reads `reasoning_effort` directly. Forward the string THINKING value verbatim as `reasoning_effort` when the template declares that variable, instead of translating "low" into a template-specific derived boolean — this is what actually mirrors the OpenAI backend's reasoning_effort handling, covers gpt-oss for free, and preserves the documented sentinel-wins precedence when a raw reasoning_effort key is also present. Also fixes the ModelOption.THINKING docstring in model_options.py, which stated HF supports boolean values only — now false. Verified end-to-end against ibm-granite/granite-4.2-3b: THINKING="low" reaches a short answer within the token budget via the corrected reasoning_effort path. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
Contributor
|
one nit: there's a bit of drift between what the PR fixes vs. what's specified in the title. Maybe retitle similar to the 2nd commit? |
Contributor
Author
|
Good catch — retitled to match the second commit. The title was left over from the first pass ( |
psschwei
approved these changes
Sep 10, 2026
Merged
via the queue into
generative-computing:main
with commit Sep 10, 2026
ad41c60
17 checks passed
planetf1
added a commit
that referenced
this pull request
Sep 10, 2026
Documents ModelOption.THINKING string levels and result.thinking as supported on LocalHFBackend too, matching the state after #1639 (HF string forwarding fix) and #1616 (HF <think> tag parsing) merge. Both are still open — this docs PR should merge after them, or the LocalHFBackend row will describe behaviour that isn't live yet. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
planetf1
added a commit
that referenced
this pull request
Sep 10, 2026
- Qualify the OpenAIBackend/LiteLLM `False` cell: real OpenAI reasoning models and non-Ollama LiteLLM targets never receive `reasoning_effort= "none"` (openai.py's server-type guard, litellm.py's ollama-prefix guard), so `False` does not actually disable thinking there. - Add an inline callout marking the LocalHFBackend string-forwarding and result.thinking claims as contingent on #1639/#1616 merging, instead of only noting it in the PR description/comment. - Correct "same mechanism as the OpenAI backend" — HF forwards through a gated chat-template variable, OpenAI sends an ungated top-level param. - Note the runtime-forwarding dependency for the cross-backend Granite claim, add a `> Full example:` link, fix the unresolvable bare "#1617" reference, add a non-determinism note to the new code block, drop the unnecessary `qualitative` marker, and fix US-English spelling in new content per CONTRIBUTING_DOCS.md. - Add cheap assertions to docs/examples/thinking_mode.py pinning the documented per-arm behaviour; reran live against granite4.2:3b, all pass. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
planetf1
added a commit
that referenced
this pull request
Sep 15, 2026
Documents ModelOption.THINKING string levels and result.thinking as supported on LocalHFBackend too, matching the state after #1639 (HF string forwarding fix) and #1616 (HF <think> tag parsing) merge. Both are still open — this docs PR should merge after them, or the LocalHFBackend row will describe behaviour that isn't live yet. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
planetf1
added a commit
that referenced
this pull request
Sep 15, 2026
- Qualify the OpenAIBackend/LiteLLM `False` cell: real OpenAI reasoning models and non-Ollama LiteLLM targets never receive `reasoning_effort= "none"` (openai.py's server-type guard, litellm.py's ollama-prefix guard), so `False` does not actually disable thinking there. - Add an inline callout marking the LocalHFBackend string-forwarding and result.thinking claims as contingent on #1639/#1616 merging, instead of only noting it in the PR description/comment. - Correct "same mechanism as the OpenAI backend" — HF forwards through a gated chat-template variable, OpenAI sends an ungated top-level param. - Note the runtime-forwarding dependency for the cross-backend Granite claim, add a `> Full example:` link, fix the unresolvable bare "#1617" reference, add a non-determinism note to the new code block, drop the unnecessary `qualitative` marker, and fix US-English spelling in new content per CONTRIBUTING_DOCS.md. - Add cheap assertions to docs/examples/thinking_mode.py pinning the documented per-arm behaviour; reran live against granite4.2:3b, all pass. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
planetf1
added a commit
that referenced
this pull request
Sep 15, 2026
#1639 (HF string-forwarding) merged 2026-09-10; only #1616 (result.thinking parsing) remains open. Also note that #1616's <think>-tag split is skipped for streaming (m serve) calls, per its own PR description. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
planetf1
added a commit
that referenced
this pull request
Sep 16, 2026
#1616 and #1639 have both merged, so LocalHFBackend's result.thinking split is now current-main behaviour, not a future dependency. Assisted-by: Claude Code Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Nigel Jones <[email protected]>
akihikokuroda
pushed a commit
to akihikokuroda/mellea
that referenced
this pull request
Sep 16, 2026
…-computing#1645) * docs: document ModelOption.THINKING behaviour for Granite and add example Adds a per-backend reasoning/thinking-mode reference table (native Ollama, OpenAI/LiteLLM, HF) to configure-model-options.md, including Granite 4.2's "low"-only effort distinction and its default-on behaviour, and cross-links it from openai.md's existing Qwen3/vLLM extra_body section as the preferred portable entry point. Adds docs/examples/thinking_mode.py demonstrating THINKING=True/False/"low" against a local Ollama Granite model, verified live against granite4.2:3b. Fixes generative-computing#1638 Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: describe THINKING doc as post-generative-computing#1639/generative-computing#1616 target state Documents ModelOption.THINKING string levels and result.thinking as supported on LocalHFBackend too, matching the state after generative-computing#1639 (HF string forwarding fix) and generative-computing#1616 (HF <think> tag parsing) merge. Both are still open — this docs PR should merge after them, or the LocalHFBackend row will describe behaviour that isn't live yet. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: address code-review findings on THINKING docs - Qualify the OpenAIBackend/LiteLLM `False` cell: real OpenAI reasoning models and non-Ollama LiteLLM targets never receive `reasoning_effort= "none"` (openai.py's server-type guard, litellm.py's ollama-prefix guard), so `False` does not actually disable thinking there. - Add an inline callout marking the LocalHFBackend string-forwarding and result.thinking claims as contingent on generative-computing#1639/generative-computing#1616 merging, instead of only noting it in the PR description/comment. - Correct "same mechanism as the OpenAI backend" — HF forwards through a gated chat-template variable, OpenAI sends an ungated top-level param. - Note the runtime-forwarding dependency for the cross-backend Granite claim, add a `> Full example:` link, fix the unresolvable bare "generative-computing#1617" reference, add a non-determinism note to the new code block, drop the unnecessary `qualitative` marker, and fix US-English spelling in new content per CONTRIBUTING_DOCS.md. - Add cheap assertions to docs/examples/thinking_mode.py pinning the documented per-arm behaviour; reran live against granite4.2:3b, all pass. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: fix stale THINKING dependency note now that generative-computing#1639 merged generative-computing#1639 (HF string-forwarding) merged 2026-09-10; only generative-computing#1616 (result.thinking parsing) remains open. Also note that generative-computing#1616's <think>-tag split is skipped for streaming (m serve) calls, per its own PR description. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: drop merged-PR references from THINKING doc generative-computing#1616 and generative-computing#1639 have both merged, so LocalHFBackend's result.thinking split is now current-main behaviour, not a future dependency. Assisted-by: Claude Code Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Nigel Jones <[email protected]> --------- Signed-off-by: Nigel Jones <[email protected]> Co-authored-by: Claude Sonnet 5 <[email protected]>
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.
What this fixes
If you passed
ModelOption.THINKING="low"to aLocalHFBackendsession (e.g. Granite 4.2), it was silently ignored — the model reasoned at full length anyway, with no error or warning. In practice this could burn your whole token budget on reasoning and never produce an answer.After this fix,
THINKING="low"genuinely engages Granite's low-effort reasoning mode, producing a short reasoning trace and reaching an answer within the token budget. The same fix also makesTHINKING="low"/"medium"/"high"work foropenai/gpt-oss-20bandgpt-oss-120bonLocalHFBackend, which had the same gap.Why it was broken
LocalHFBackendonly forwardedTHINKINGto the chat template when it was a bool (True/False). A string level like"low"failed that check and was dropped before it ever reached the template.How it's fixed
Granite 4.2's chat template computes its low-effort behaviour from a
reasoning_effortvariable:{%- set low_effort = reasoning_effort == "low" %}. The fix forwards a stringTHINKINGvalue verbatim asreasoning_effortwhenever the tokenizer's chat template declares that variable — the same mechanism the OpenAI backend already uses (_map_thinking_optioninopenai.py). This also preserves the existing precedence rule: an explicitModelOption.THINKINGalways wins over a rawreasoning_effortkey set some other way.The
ModelOption.THINKINGdocstring is also corrected — it previously said HuggingFace only supports boolean values, which is no longer true.Verification
ibm-granite/granite-4.2-3b. Before:THINKING="low"produced full-length reasoning and exhausted a 400-token budget with no answer. After: short reasoning, correct answer, well within budget.ibm-granite/granite-4.2-3btokenizer/chat-template, confirming the rendered prompt text actually changes ({reasoning effort: low}appears/disappears).reasoning_effort, are a no-op when it doesn't, an explicitTHINKINGsentinel wins over a conflicting rawreasoning_effortkey, and boolTHINKINGvalues are unaffected.uv run pytest test/backends/test_huggingface_filter_options.py— 41 passed, 3 skipped (pre-existing skips, unrelated model not cached locally).uv sync --all-extras --all-groups;uv run pytest test/ -m "not qualitative") — 3629+ passed, no failures from this change.ruff format --check/ruff check/mypy— all clean.Fixes #1636
Assisted-by: Claude Code