Skip to content

feat(selfhost): tune Ollama concurrency for a shared embed+vision GPU (#4327) - #4352

Merged
JSONbored merged 2 commits into
mainfrom
claude/ollama-concurrency-tuning
Jul 9, 2026
Merged

feat(selfhost): tune Ollama concurrency for a shared embed+vision GPU (#4327)#4352
JSONbored merged 2 commits into
mainfrom
claude/ollama-concurrency-tuning

Conversation

@JSONbored

@JSONbored JSONbored commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Ollama had no concurrency/residency configuration — everything was Ollama's own defaults, and OLLAMA_MEM_LIMIT (container RAM ceiling, not VRAM) was still sized for a single embedding model only (8g).
  • Adds OLLAMA_NUM_PARALLEL/OLLAMA_MAX_LOADED_MODELS/OLLAMA_KEEP_ALIVE, mirroring the existing OLLAMA_MEM_LIMIT env-override pattern, and raises the memory ceiling to 20g — sized for an embed model + one vision model resident and concurrently in use on a single 24GB-class GPU without either starving the other under a busy review queue.
  • See the comment on the ollama service in docker-compose.yml for the full VRAM/KV-cache reasoning (worst-case ~14-15GB of 24GB at these defaults).

Closes #4327 -- all 5 deliverables satisfied: GPU passthrough confirmed (nvidia-smi + docker inspect device reservation), before/after latency numbers posted to the issue, a batch-size recommendation shipped (#4350), and this PR promotes the previously-local-only compose changes into the tracked repo now that cutover has happened. Companion to #4350, both stemming from the GPU-migration epic #4325.

Scope

Validation

  • git diff --check
  • npm run actionlint (via npm run test:ci)
  • npm run typecheck (via npm run test:ci)
  • npm run test:coverage locally — new structural assertions added to test/unit/selfhost-compose-resource-limits.test.ts
  • npm run test:workers (via npm run test:ci)
  • npm run build:mcp / npm run test:mcp-pack (via npm run test:ci)
  • npm run ui:openapi:check / npm run ui:lint / npm run ui:typecheck / npm run ui:build (via npm run test:ci) — no UI/API surface touched
  • npm audit --audit-level=moderate — 0 vulnerabilities
  • New behavior has structural tests: docker-compose.yml's ollama environment: block and .env.example documentation are both asserted directly (mirroring this file's existing memory-limit test pattern)

Ran npm run test:ci (full unsharded suite) end-to-end — green.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth/cookie/CORS/GitHub App/Cloudflare/session changes include negative-path tests. — N/A, no such surface touched.
  • API/OpenAPI/MCP behavior is updated and tested where needed. — N/A, no API/OpenAPI/MCP surface touched.
  • UI changes use live API data or real empty/error/loading states. — N/A, infra-config-only change.
  • Visible UI changes include a UI Evidence section. — N/A, no UI change.
  • Public docs updated where needed (.env.example documents every new var).

Notes

  • No migration, OpenAPI, or cf-typegen regeneration needed — docker-compose.yml/.env.example aren't scanned by any of those generators.

…#4327)

Ollama had no concurrency/residency configuration -- all defaults,
including OLLAMA_MEM_LIMIT still sized for a single embedding model
only (8g). Adds OLLAMA_NUM_PARALLEL/OLLAMA_MAX_LOADED_MODELS/
OLLAMA_KEEP_ALIVE (mirroring the existing OLLAMA_MEM_LIMIT override
pattern) and raises the memory ceiling to 20g, sized for an embed
model + one vision model resident and concurrently in use on a single
24GB-class GPU without either starving the other under a busy queue.

See docker-compose.yml's comment on the ollama service for the full
VRAM/KV-cache reasoning.
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.95%. Comparing base (06d3856) to head (e467e08).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4352   +/-   ##
=======================================
  Coverage   93.95%   93.95%           
=======================================
  Files         399      399           
  Lines       36786    36786           
  Branches    13440    13440           
=======================================
  Hits        34561    34561           
  Misses       1569     1569           
  Partials      656      656           
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored
JSONbored merged commit e432f96 into main Jul 9, 2026
8 checks passed
@JSONbored
JSONbored deleted the claude/ollama-concurrency-tuning branch July 9, 2026 03:42
JSONbored added a commit that referenced this pull request Jul 9, 2026
…#4369)

The self-host Ollama concurrency tuning (#4327/#4352) sized VRAM
headroom assuming a bounded per-request context; vision calls had no
num_ctx cap, so under concurrent load a large context is the real
OOM/thrashing risk on a shared embed+vision GPU. Adds a generic
providerOptions passthrough on the OpenAI-compatible chat path
(Ollama-specific request extension, ignored by every other provider)
and sets num_ctx: 4096 on the self-host visual-vision call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

GPU passthrough for Ollama + embedding benchmark vs. the current CPU-bound setup

1 participant