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
Release files for polyollama 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| polyollama-0.2.0.tar.gz | 8.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| polyollama-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.6 kB
Release files / polyollama-0.2.0.tar.gz
| Download URL | polyollama-0.2.0.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef8bf8877596c52eda5af170dbf513820d0312a19e542e9d3d45c15bfd046807
|
|
BLAKE2b-256 checksum How to use checksums |
8ca469c79fc5424ce0f4ec9e55cdfa358dfbaa7c26523378242a7271e9c8858d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / polyollama-0.2.0-py3-none-any.whl
| Download URL | polyollama-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9b09486e5e1c1a139e7c8351b72abef540ca9eb7f54ad2a0fa55511702073511
|
|
BLAKE2b-256 checksum How to use checksums |
aab2f0a9ba3d3abd6f3c26521f51a84905cbc531d32feee5d4206695cdf9a569
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|