Repository navigation
Description
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
- Scan the chat template Jinja variables at backend init time (the allowlist mechanism already does this).
- Map
ModelOption.THINKINGto whichever of{'think', 'thinking'}(or any future variant) is present in the detected template variables — prefer the template's own name. - 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_varspasses on current Granite 4.1.ModelOption.THINKING=Truepassed toLocalHFBackendis forwarded as the correct template variable (not silently dropped).- No regression on backends / models that do not have a thinking template variable.
Related
- feat: distinguish thinking models #406 — distinguish thinking models (cross-backend abstraction)
- feat(backends): add default_extra_body to OpenAIBackend for vLLM/vendor-specific per-request fields #1453 —
default_extra_bodyonOpenAIBackend(vLLM / OpenAI-compatible path)
Activity
planetf1 commentedon Aug 12, 2026
Cross-backend consistency gap
Looking at this more broadly, the problem isn't just the
thinkvsthinkingtemplate variable name — there's a deeper inconsistency in howModelOption.THINKINGis handled across backends:ModelOption.THINKINGis translated tothink=viato_mellea_model_opts_map— works correctly at both construction time and per-callextra_body.chat_template_kwargs.enable_thinking(addressed by PR feat(backends): add default_extra_body to OpenAIBackend #1536)ModelOption.THINKINGis silently dropped. Callers must know the model's specific Jinja template variable name (think,thinking, orenable_thinkingdepending on model family) and pass it as a raw string key directly inmodel_optionsThis 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_mapequivalent onLocalHFBackendthat translatesModelOption.THINKINGto the correct template variable for the loaded model — likely by inspecting_chat_template_allowlistat translation time to pick whichever ofthink/thinking/enable_thinkingthe current tokenizer's template actually uses.