Manage multiple Ollama servers and fan out parallel inference across them.
Project description
polyollama
Spin up multiple Ollama servers and fan out parallel inference across them — with optional NVIDIA MPS support for true GPU concurrency.
Performance
Using multiple servers with MPS enabled yields up to ~2.9x throughput over single-server sequential inference.
Install
pip install "polyollama[inference]" # includes langchain-ollama
pip install "polyollama[all]" # + datasets, ipywidgets
Requires Python ≥ 3.12 and a running Ollama instance.
Usage
Pool only (infrastructure layer)
from polyollama import OllamaPool
with OllamaPool(ports=[11435, 11436, 11437], num_parallel=2) as pool:
print(pool.urls) # ["http://127.0.0.1:11435", ...]
Parallel batch inference
import asyncio
from polyollama import OllamaPool
from polyollama.inference import parallel_batch_inference
async def main():
pool = OllamaPool(ports=[11435, 11436, 11437], num_parallel=2)
await pool.start_async()
try:
results = await parallel_batch_inference(
urls=pool.urls,
query_list=[{"question": q} for q in questions],
prompt="Answer politely: {question}",
model="gemma2:2b",
model_kwargs={"temperature": 0},
)
finally:
pool.stop()
asyncio.run(main())
With NVIDIA MPS (best performance)
Servers must be started inside the MPSContext block so their CUDA contexts connect to the MPS daemon.
from polyollama import OllamaPool, MPSContext
from polyollama.inference import parallel_batch_inference
async def main():
with MPSContext(gpu_id=0):
pool = OllamaPool(ports=[11435, 11436, 11437], num_parallel=4)
await pool.start_async()
try:
results = await parallel_batch_inference(
urls=pool.urls,
query_list=[{"question": q} for q in questions],
prompt="Answer politely: {question}",
model="gemma2:2b",
model_kwargs={"temperature": 0, "num_ctx": 2048},
)
finally:
pool.stop()
VRAM note: with many servers and high
num_parallel, reducenum_ctxto limit KV-cache size (e.g.num_ctx=2048). Default is 8k which can OOM at scale.
Architecture
OllamaPool (pool.py) — spawns/stops OllamaServer processes, exposes URLs
OllamaServer (server.py) — wraps a single `ollama serve` process
MPSContext (mps.py) — starts/stops the nvidia-cuda-mps-control daemon
parallel_batch_inference — splits query list into chunks, one chunk per server
parallel_inference — round-robin fan-out across servers
MPS requirements
- NVIDIA GPU (Compute Capability ≥ 3.5)
nvidia-cuda-mps-controlin PATH (comes with the NVIDIA driver)- Do not start servers before entering
MPSContext— they will bypass the daemon
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polyollama-0.2.0.tar.gz.
File metadata
- Download URL: polyollama-0.2.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef8bf8877596c52eda5af170dbf513820d0312a19e542e9d3d45c15bfd046807
|
|
| MD5 |
3199643af27627e7f9d5873ca9d360eb
|
|
| BLAKE2b-256 |
8ca469c79fc5424ce0f4ec9e55cdfa358dfbaa7c26523378242a7271e9c8858d
|
File details
Details for the file polyollama-0.2.0-py3-none-any.whl.
File metadata
- Download URL: polyollama-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b09486e5e1c1a139e7c8351b72abef540ca9eb7f54ad2a0fa55511702073511
|
|
| MD5 |
1336400e921bf4682056e18c7bad76dd
|
|
| BLAKE2b-256 |
aab2f0a9ba3d3abd6f3c26521f51a84905cbc531d32feee5d4206695cdf9a569
|