Skip to content

feat(ollama): OllamaModelBackend has no way to reach Granite low_effort/reasoning_effort mode #1637

Closed

Description

@planetf1

Gap

The native OllamaModelBackend forwards ModelOption.THINKING only as Ollama's own boolean think= kwarg (mellea/backends/ollama.py:589 non-streaming, :705 streaming). It never sends reasoning_effort or low_effort, so there is no way to reach Granite's low-effort reasoning mode through this backend — regardless of what value is passed to ModelOption.THINKING.

Contrast with other backends

The OpenAI and LiteLLM backends already translate a string THINKING value (e.g. "low") straight through as reasoning_effort (openai.py:712-751, litellm.py:417-442), and this has been verified to correctly trigger Granite 4.2's low_effort chat-template branch when going through Ollama's own /v1/chat/completions endpoint:

curl http://localhost:11434/v1/chat/completions -d '{"model":"granite4.2:3b","messages":[...],"reasoning_effort":"low"}'

reliably produces markedly shorter reasoning output than "medium"/"high"/unset. So Ollama's server itself supports this — the gap is specifically that mellea's native OllamaModelBackend class (as opposed to routing Ollama through the OpenAI-compatible backend) never sends the parameter.

Suggested fix

Add the same string-to-reasoning_effort (or native equivalent, if Ollama's /api/chat supports one — needs checking, since Ollama's native /api/chat think param is currently boolean-only per its docs) translation that the OpenAI/LiteLLM backends already have, so ModelOption.THINKING="low" behaves consistently whether a Granite model is reached via OllamaModelBackend or via OpenAIBackend/LiteLLMModelBackend pointed at the same Ollama server.

Environment

Verified against granite4.2:3b, Ollama 0.33.3, 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. planetf1 commented on Sep 9, 2026

    @planetf1
    ContributorAuthor

    Closing as not reproducible — this issue's premise was wrong, my error.

    I claimed OllamaModelBackend only forwards ModelOption.THINKING as a bool think= kwarg. Re-checking mellea/backends/ollama.py:589,705: it's a raw passthrough (think=model_opts.get(ModelOption.THINKING, None)) with no bool cast at all. I'd tested bool values against native /api/chat and string values against the /v1 OpenAI-compat endpoint during the original investigation, but never tested a string against native /api/chat directly — and wrongly assumed it was bool-only based on how it's typically documented/typed, rather than testing it.

    Empirical evidence (Ollama server 0.33.3, ollama pip package 0.6.1, granite4.2:3b):

    Through mellea's actual OllamaModelBackend.generate_from_context:

    False → thinking_len=0
    "low" → thinking_len=50
    "high" → thinking_len=566
    

    Raw ollama-py, fixed seed=1/temp=0, 3 repeats each:

    False:  [0, 0, 0]
    "low":  [29, 29, 29]
    "medium": [1168, 1203, 1203]
    "high": [1203, 1203, 1203]
    

    medium/high are statistically identical — consistent with Granite's chat template only branching on reasoning_effort == "low" (see #1636 for that template logic), no distinct "high" tier exists on the model side regardless of backend.

    Byte-identical cross-check, native think="low" vs OpenAI-compat reasoning_effort="low" (same seed/temp/prompt): both return the exact string "Explain Rayleigh scattering.\n" as the reasoning content — confirming native Ollama's think= already reaches the same low-effort branch as the /v1 path, no separate translation needed.

    So: current mellea (main) already works correctly for Granite reasoning-effort strings via the native Ollama backend, with no code change required. Note mellea's pin is ollama>=0.5.1 — this hasn't been verified against that floor version, only against 0.6.1/server 0.33.3, so a regression test pinning this behavior is still worthwhile to guard against an older-Ollama environment silently regressing.

    Thanks to the session that caught this while starting the fix PR — the empirical check here is theirs.

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