Skip to content

fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061

Closed

Description

@dan-petty

Problem

Every Ollama tier reserves KV cache for OLLAMA_CONTEXT_LENGTH × OLLAMA_NUM_PARALLEL tokens. It also keeps up to OLLAMA_MAX_LOADED_MODELS models resident (k8s/llm/profiles/ollama-profiles.yaml). With NUM_PARALLEL at 4 and contexts of 48k–256k, a dense ~30B model either doesn't fit or runs mostly from CPU.

What happened in review session 20261003-051015 (gemma4:31b, 2026-10-03), from read-only Ollama logs:

  • ollama-48gib-slow (2× Quadro P6000): allocated n_ctx = 512000 (4 × 128000). That put only 44 of 61 layers on the GPU, and the load then failed with failed to create MTP context. Each request got a 500 after 3–4 minutes of load attempts, in a loop.
  • ollama-48gib (48gib-fast): the same load failure once its node came back.
  • ollama-64gib: served gemma4 with 4 slots of 160000 tokens each, at 18–25 minutes per call (POST /api/chat 200 after 18m25s to 23m21s). That exceeds the client's 1200 s read timeout, and one call hit the gateway's 1500 s timeout.
  • No model call completed on the client side in 25 minutes.

The review asks for at most 28,672 tokens (ai.tasks.analysis.context_window), so most of the reserved cache serves nothing.

Acceptance criteria

  • Every Ollama DaemonSet in k8s/llm/profiles/ollama-profiles.yaml sets OLLAMA_MAX_LOADED_MODELS to "1" and OLLAMA_NUM_PARALLEL to "1". These are 16gib, 24gib, 32gib, 48gib, 48gib-slow, 64gib, 72gib, 96gib and 128gib.
  • An offline test reads the manifest and fails if any Ollama DaemonSet sets either to anything else, or leaves either unset.
  • uv run devops ci passes.
  • Pending a person: after applying, each tier's Ollama log shows the loaded model's n_ctx equal to its OLLAMA_CONTEXT_LENGTH (one sequence). gemma4:31b loads on ollama-48gib-slow without failed to create MTP context.

Key questions

  • Does serving one request at a time cost throughput? For mixture-of-experts models such as qwen3-coder:30b, batching four sequences gave more aggregate tokens per second. Proposed: accept it. It's the owner's call, and the VRAM goes to one model at one context. Requests to a busy tier now queue in Ollama, and queue time counts toward the client's 1200 s and the gateway's 1500 s timeouts.
  • What happens on a tier that serves both an embedding model and a chat model? With one model resident, each switch evicts the other. That's ollama-48gib-slow (bge-m3, embeddinggemma and the chat groups), and 16gib when its embedding deployments return. Proposed: accept it here. Embedding placement and per-deployment concurrency belong to the gateway's health-check routing item.
  • Is the context length changed? No. Each tier keeps its OLLAMA_CONTEXT_LENGTH; only the multiplier goes away.

Activity

  1. added this to the v0.2.25 milestone on Oct 3, 2026
  2. added
    type/bug
    scope/k8s
    priority/p1-high
    on Oct 3, 2026
  3. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1062, merged into release/v0.2.25.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  4. added a commit that references this issue on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/k8stype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions