Skip to content

Example tests leave Ollama models resident, starving subsequent tests #798

Closed

Description

@planetf1

Summary

When running the full docs/examples/ suite, each example runs as a subprocess and loads its Ollama model. Ollama keeps models resident for the default 5-minute keep-alive timeout after each request. Heavyweight models (e.g. ibm/granite3.3-guardian:8b at ~11 GB) then sit in memory long after the example finishes, starving later tests of headroom.

This caused the SOFAI graph-colouring example to crash with a 500 from the model runner — not because the machine lacked memory in total, but because a guardian model from an earlier test was still resident.

Contrast with test/

test/conftest.py already handles this: it warms up CI models with keep_alive: -1 before the ollama group and evicts them with keep_alive: 0 afterwards. docs/examples/conftest.py has no equivalent.

Options

  1. Set OLLAMA_KEEP_ALIVE=0 (or a short timeout) as an env var for example runs — models unload immediately after each example finishes
  2. Add warm-up/eviction hooks to docs/examples/conftest.py, similar to test/conftest.py
  3. Backend-level option — allow OllamaModelBackend to accept a keep_alive parameter passed through to the Ollama API

Related: #783 (VRAM predicate uses static heuristic)

Activity

  1. added
    bug
    on Apr 9, 2026
  2. planetf1 commented on Apr 9, 2026

    @planetf1
    ContributorAuthor

    Worth noting: several examples use heavyweight or multi-model setups with no resource gating at all. The # pytest: comment syntax doesn't support predicates like require_ram, so there's currently no way for an example to declare its memory requirements.

    Examples that would benefit from gating once the mechanism exists:

    Example Models loaded Approx. total RAM
    sofai/sofai_graph_coloring.py phi:2.7b + pielee/qwen3-4b-thinking-2507_q8 ~6.3 GB
    safety/guardian_huggingface.py deepseek-r1:8b + HF granite-guardian-3.3-8b ~16 GB
    m_decompose/python/python_decompose_example.py granite3.3:8b ~5 GB
    image_text_models/vision_openai_examples.py qwen2.5vl:7b ~6 GB

    Proactive eviction (the main ask of this issue) would reduce the pressure, but a resource-gate mechanism for examples would let them skip gracefully on constrained machines rather than crashing mid-run.

  3. psschwei commented on Apr 9, 2026

    @psschwei
    Contributor

    making an assumption you're working this one @planetf1 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugtesting

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions