Skip to content

enhancement: huggingface should handle ModelOption.THINKING #1212

Closed

Description

@jakelorocco

Problem

The HF (LocalHFBackend) backend silently drops ModelOption.THINKING. Different Granite model families use different Jinja template variable names for thinking — think vs thinking — so there is no single hardcoded key that works across all models.

There is already a failing nightly test that exposes the concrete bug:

File: test/backends/test_huggingface_filter_options.py

AssertionError: 'think' missing from allowlist; got: ['available_tools', 'controls',
'documents', 'loop_messages', 'system_message', 'thinking']
assert 'think' in frozenset({..., 'thinking'})

The test checks for 'think' but the current Granite 4.1 template uses 'thinking'. Both the test expectation and the allowlist need to converge on the correct variable name (or support both).

Root cause

_chat_template_allowlist in LocalHFBackend scans the tokenizer's Jinja template for known variable names to pass through. The allowed list was written against an older template version that used think; the current template uses thinking. The ModelOption.THINKING → template-var mapping is not updated to match.

Proposed fix

  1. Scan the chat template Jinja variables at backend init time (the allowlist mechanism already does this).
  2. Map ModelOption.THINKING to whichever of {'think', 'thinking'} (or any future variant) is present in the detected template variables — prefer the template's own name.
  3. Update the failing test so it checks for the variable name actually present in the template rather than a hardcoded string.

See #406 for the broader cross-backend thinking model abstraction this feeds into.

Acceptance criteria

  • test_granite_allowlist_includes_known_template_vars passes on current Granite 4.1.
  • ModelOption.THINKING=True passed to LocalHFBackend is forwarded as the correct template variable (not silently dropped).
  • No regression on backends / models that do not have a thinking template variable.

Related

Activity

  1. added
    enhancement
    on Jun 5, 2026
  2. added theissue type on Jun 5, 2026
  3. changed the issue type fromtoon Jun 5, 2026
  4. changed the issue type fromtoon Jun 5, 2026
  5. added
    p2
    on Jun 18, 2026
  6. added
    area/backends
    bug
    p1
    and removed
    p2
    on Aug 10, 2026
  7. planetf1 commented on Aug 12, 2026

    @planetf1
    Contributor

    Cross-backend consistency gap

    Looking at this more broadly, the problem isn't just the think vs thinking template variable name — there's a deeper inconsistency in how ModelOption.THINKING is handled across backends:

    • Ollama: ModelOption.THINKING is translated to think= via to_mellea_model_opts_map — works correctly at both construction time and per-call
    • OpenAI / LiteLLM: handled via extra_body.chat_template_kwargs.enable_thinking (addressed by PR feat(backends): add default_extra_body to OpenAIBackend #1536)
    • LocalHFBackend: no translation exists. ModelOption.THINKING is silently dropped. Callers must know the model's specific Jinja template variable name (think, thinking, or enable_thinking depending on model family) and pass it as a raw string key directly in model_options

    This means code that portably suppresses thinking via model_options={ModelOption.THINKING: False} works on Ollama and OpenAI backends but silently does nothing on the HF backend. There's no error, no warning — the model just generates thinking tokens regardless.

    The fix should add a to_mellea_model_opts_map equivalent on LocalHFBackend that translates ModelOption.THINKING to the correct template variable for the loaded model — likely by inspecting _chat_template_allowlist at translation time to pick whichever of think / thinking / enable_thinking the current tokenizer's template actually uses.

  8. self-assigned this
    on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/backendsbugenhancementp1

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions