Search and contents

Changing the inference model

This guide shows how to point Kindred's AI Inference Stack (engine/token_budget.py, engine/inference.py) at a different LLM on the configured Ollama endpoint. You can swap models entirely, or move to a different context-window tier on the same model.

The inference endpoint and model are a Node Type's Configuration Schema values. An integrator changes the inference fragment of a config file, and no code is touched. This is wired through engine/inference_config.py (INFERENCE_CONFIG_SCHEMA and build_inference_profile).

StepWhatKind
1. Get the model onto the Ollama server Pull it Manual, against the live Ollama server
2. Determine the model's real capabilities and context window Read /api/show Manual, against the live Ollama server
3. Confirm VRAM fit Run one call and read /api/ps Manual, against the live Ollama server
4. Update Kindred's own configuration Edit config.inference A config-file edit, not a source change
5. Validate the swap Run the tests Tests

1. Get the model onto the Ollama server

If the model isn't already pulled on the target endpoint:

curl -sf http://<ollama-host>:11434/api/pull \
  -d '{"model": "<model-name>", "stream": false}'

stream: false blocks until the pull completes rather than streaming progress lines, which is simpler for a one-shot script or manual step. Verify it landed:

curl -s http://<ollama-host>:11434/api/tags

2. Determine the model's real capabilities and context window

Don't assume. Check. A model's native maximum context is not necessarily what it will actually run at. A custom model can bake in a smaller default through its own Modelfile.

curl -s http://<ollama-host>:11434/api/show -d '{"model": "<model-name>"}'

Look at three fields:

  • capabilities must include "completion".
    • If it includes "thinking", the model can emit a chain-of-thought trace. Decide InferenceProfile.reasoning_effort deliberately (see the pitfall below).
    • Unset means this target hasn't declared reasoning-trace support at all, so the field is never sent. For a model whose capabilities includes "thinking", that is very likely the wrong choice, not a safe default.
  • model_info.<family>.context_length is the model's native maximum context, not necessarily what it runs at by default.
  • parameters.num_ctx is the model's own baked-in default context window. This is the number to anchor ModelBudgetProfile.context_window_tokens to, not the native maximum above.
    • Kindred's OpenAI-compatible wire convention (engine/inference.py) has no per-request field for context window. The convention treats it as a model-fixed, server-side property, not something a caller declares per call. The live server therefore always runs at this value, unconditionally.
    • context_window_tokens is Token Budget's own local batch-sizing input only. Setting it higher than this value means Token Budget plans batches the live server can't honor.

3. Confirm VRAM fit at the intended context size

The model's baked-in parameters.num_ctx (step 2) is the only context size the live server will ever run at. There is no live override to test a different one against.

Fire one throwaway call at that value through Ollama's native API, then check what is resident. This is a manual diagnostic, independent of what InferenceClient sends on the wire.

curl -s http://<ollama-host>:11434/api/chat -d '{
  "model": "<model-name>", "stream": false, "think": false,
  "messages": [{"role":"user","content":"Reply with a single word: ready."}],
  "options": {"num_ctx": <intended-context>, "num_predict": 20}
}'
curl -s http://<ollama-host>:11434/api/ps

Compare size (total runtime footprint) against size_vram (what is actually in VRAM) for that model in the /api/ps response:

  • size == size_vram: fully GPU-resident. Latency is fast and consistent.
  • size > size_vram: partial CPU offload. This is not necessarily wrong, and it may be the intended, accepted tradeoff for a given hardware tier. But it means real, more variable per-call latency, and any timeout tuned for a fully resident model will be too tight. For example, a larger model at 32K context can spill about 12 GB to system RAM on a 24 GB card, so calls that normally take seconds occasionally take minutes. A smaller model such as example-llm at the same context size can be fully resident and consistently fast.

4. Update Kindred's own configuration

Edit the config.inference fragment of the site's config file. It is validated against INFERENCE_CONFIG_SCHEMA (engine/inference_config.py), the same Configuration Schema mechanism (engine/config_loader.py) that governs every other Node Type field.

FieldWhat to set
model The new name.
context_window_tokens Step 2's parameters.num_ctx exactly, not a smaller or larger value. This is Token Budget's own local batch-sizing input, and the live wire call carries no context-window field (see step 2). It must match what the server will actually run at, or Token Budget plans batches the server can't honor.
reserved_output_tokens The response's hard cap, sent as max_tokens. See Sizing the cap.
reasoning_effort A free string sent verbatim on the wire, not an enum Kindred validates. See Setting reasoning_effort.
timeout_seconds, retry Tune to what step 3 actually showed, not copied from a different model's known-good values.
chars_per_token, safety_margin Optional. Set them if this model's tokenizer behaves very differently from the default of about 3.5 characters per token for English and code.
endpoint Only if the model also moved to a different Ollama host.

Sizing the cap

reserved_output_tokens is conceptually the same "reserve this many tokens for the response" budget that Ollama's own num_predict names.

  • Size it above the longest answer you expect, and no higher than the model's speed allows.
  • At S tokens per second, a runaway generation lasts reserved_output_tokens / S seconds before the cap ends it. Keep that under half of timeout_seconds.
  • Example: for a model that generates about 84 tokens/s, a cap of 2048 ends a runaway in about 25 s and leaves about 30,700 of a 32,768-token window for input.
  • An answer that reaches the cap is rejected as truncated and retried (see inference-backend-configuration.md). A cap set too low therefore fails calls rather than shortening them silently.

Setting reasoning_effort

For a reasoning-capable model, set it to whatever value the target itself accepts to suppress or bound the trace. Ollama's own OpenAI-compatible endpoint accepts "none". Leave it unset only for a target that genuinely doesn't support the concept. The pitfall below describes what happens when a reasoning-capable model gets no value at all.

The low-tier baseline

Kindred's own documented low-tier baseline is the config file tests/fixtures/low_tier_inference_config.json. tests/test_inference_live.py loads it through load_node_config and build_inference_profile rather than hardcoding these values in Python.

5. Validate the swap

poetry run pytest tests/test_inference_live.py -v -s   # the specific model + hardware claim
poetry run pytest tests/test_inference_contract.py -v  # model-agnostic wire-contract sanity check

test_inference_live.py skips itself, rather than failing, if the named model isn't present on the reachable endpoint. Confirm it actually ran, and didn't just report green through a skip. If you edited tests/fixtures/low_tier_inference_config.json, that is now the file the skip check reads the model name from, so a typo there shows up as a skip, not a failure.

Checking that the cap is enforced

Do this once for a new server or model, before trusting reserved_output_tokens. Ask for a long answer with a tiny cap, and read usage.completion_tokens and finish_reason in the reply:

curl -s http://<host>:11434/v1/chat/completions -H 'Content-Type: application/json' -d '{
  "model": "<model>", "stream": false, "max_tokens": 20,
  "messages": [{"role": "user", "content": "Count from 1 to 200, one number per line."}]
}'

An enforced cap gives completion_tokens of 20 and finish_reason of length. A far larger count means the server ignores max_tokens, and Kindred's cap does nothing against it. Do not rely on reserved_output_tokens to stop a runaway response with that server.

Pitfalls

  • A cap the server ignores looks like a slow server. Ollama 0.22.1 accepts max_completion_tokens and does not apply it. Nothing then bounds the response, and an example-llm call that falls into a repetition loop in its reasoning runs until the 120 s client timeout.
    • It shows up as runs that take minutes instead of seconds, with a retry at a higher temperature then succeeding in seconds.
    • The cause is the cap and the unset reasoning_effort, not the server's load.
    • Check with the request above, and read a failed call's failure_reasons (a ReadTimeout per attempt) before blaming the hardware.
  • reasoning_effort unset is not a safe default for a reasoning-capable model.
    • InferenceProfile.reasoning_effort defaults to None, meaning "this target hasn't declared reasoning-trace support", so the field is never sent. That is the right default for a target that genuinely doesn't support the concept.
    • A reasoning-capable model given no value can consume its entire reserved_output_tokens budget on the trace itself and return empty content. This is a failure mode of reasoning-capable models such as example-llm. Explicitly configuring "reasoning_effort": "none" for that target resolves it.
    • Check capabilities in step 2 and decide deliberately. Don't assume the default is conservative here.
  • A written spec can go stale. Cross-check against the live endpoint (/api/tags) before trusting any document's model name, including this one.
  • Native max context is not what the model actually runs at. Check parameters.num_ctx in /api/show, not just model_info.*.context_length.
  • VRAM fit isn't visible from the model's file size alone. Two models can look similarly sized on disk and behave completely differently once a large context window is allocated. Always check /api/ps's size against size_vram at your real intended context size, not a guess.
  • context_window_tokens must equal the model's baked-in num_ctx, not just be "close enough" or "safely smaller". InferenceClient does not send num_ctx. The OpenAI-compatible convention has no per-request context-window field, so the server always runs at its own baked-in default regardless of config. A context_window_tokens set higher than that default means Token Budget plans batches the server silently can't honor, with no error surfaced anywhere in the call chain.

Release: v0.11.0