Skip to content

fix(hf): ModelOption.THINKING string values (e.g. "low") are silently dropped, falling back to full thinking #1636

Closed

Description

@planetf1

Bug

LocalHFBackend._filter_for_chat_template (mellea/backends/huggingface.py:2596) only sets the chat template's thinking variable if type(thinking_value) is bool. A string value such as "low" fails that check, so nothing is set and Granite falls back to full default thinking — silently, with no error or warning.

Repro

from mellea import start_session
from mellea.backends.model_options import ModelOption
from mellea.backends.model_ids import IBM_GRANITE_4_2_3B

with start_session("hf", model_id=IBM_GRANITE_4_2_3B) as session:
    result = session.chat(
        "A train leaves station A at 60 km/h heading to station B, 300km away. "
        "Another train leaves B at 90 km/h heading to A at the same time. "
        "How far from A do they meet? Answer with just the number in km.",
        model_options={ModelOption.THINKING: "low"},
    )
    print(result.content)

With THINKING="low", the model produces full-length reasoning (indistinguishable from THINKING=True) instead of Granite's low-effort mode. On one run with a 400-token cap this exhausted the budget mid-reasoning without ever producing an answer.

Root cause

Granite 4.2's chat template (chat_template.jinja, identical across 4.2-8b/30b) implements a low_effort boolean template variable:

{%- set low_effort = low_effort if low_effort is defined else False %}
{%- if reasoning_effort is defined and reasoning_effort is not none %}
    {%- set low_effort = reasoning_effort == "low" %}
{%- endif %}
...
{%- if low_effort %}{{- content + '\n\n{reasoning effort: low}' }}{%- endif %}

Passing the raw low_effort=True key directly into model_options (bypassing ModelOption.THINKING entirely) reaches the template correctly and produces genuinely short reasoning — confirming the template supports this, and the gap is purely in mellea's translation layer.

The OpenAI backend already handles this case (openai.py:712-751, _map_thinking_option) by passing a string straight through as reasoning_effort. The HF backend has no equivalent.

Fix

Extend _filter_for_chat_template to translate the string "low" into low_effort=True on the chat template kwargs, mirroring the OpenAI backend's reasoning_effort handling. Values other than "low" should presumably remain no-ops, matching Granite's own template logic (there's no "high" branch on the model side either — see #406 for the broader design discussion this relates to).

Environment

Verified against ibm-granite/granite-4.2-3b, local LocalHFBackend, mellea on main (e6861c418).

Related to #406.

Activity

  1. added
    area/thinking
    on Sep 9, 2026
  2. self-assigned this
    on Sep 9, 2026
  3. added a commit that references this issue on Sep 10, 2026
    ad41c60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/thinking

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions