Skip to main content

parallel-inference-tuner

PyPI CI License: MIT Agent skill Guide

Find the fastest and most energy-efficient way to run your model on your machine: how many threads, how many worker processes, and how big a batch. It measures your model, measures the workers together, then simulates your real traffic against a latency target and tells you the settings.

pip install parallel-inference-tuner
parallel-inference-tuner model.json --data rows.csv --rate 300 --slo-ms 20
Time per call (ms) by threads and batch size:
  batch       1 thr      2 thr
      1       0.104      0.126
      8       0.244      0.255
     64       0.447      0.429
    512       2.115      1.195

Fastest single prediction: 1 thread(s), 0.10 ms per call.
Bulk scoring, highest throughput: 2 process(es) x 1 thread(s), batch 64: 276,327 rows/s.

All workers busy at once:
   1 proc x  2 thr, batch   64:      150,301 rows/s  0.553 mJ/row
   2 proc x  1 thr, batch   64:      276,327 rows/s  0.307 mJ/row

Online serving at 300 requests/s with p95 under 20 ms:
  Least energy: 2 worker(s) x 1 thread(s), micro-batches of up to 64, waiting at most 10 ms
    predicted p50 6.85 ms, p95 10.19 ms, p99 10.25 ms, 1.791 mJ per request

(A 300-tree XGBoost model on a 2-CPU cloud VM. Run it on your own hardware: the answer changes with the machine.)

Why

Every tree library and runtime has its own threading defaults, and they are usually wrong for serving:

  • Threads for one prediction rarely help. For a single row, starting and syncing threads costs more than the work. In the run above, 2 threads were slower than 1 for batches up to 8.
  • Processes often beat threads. Two single-threaded workers did 276k rows/s against 150k for one worker with two threads, at nearly half the energy per row.
  • Containers hide their CPU limit. os.cpu_count() returns the host's CPUs, not your container's quota. A library that sizes its thread pool from the host count runs far more threads than it gets CPU time for: an XGBoost report (issue #7653) measured 28 s with default threads against 0.3 s with one thread, in a one-CPU container on a 16-CPU host. Whether your library version handles this varies, so this tool reads the cgroup quota and affinity mask and measures what actually happens.
  • Oversubscription is silent. Workers x threads above the usable CPUs makes everything slower. Gunicorn workers each running a default-threaded model is the classic case.
  • Batching is a latency trade. Waiting a few milliseconds to group requests can multiply throughput and cut energy per request, but only up to your latency target. Testing every combination live would take hours; simulating it from measured service times takes seconds.

What it does

  1. Reads the machine: usable CPUs (affinity and cgroup v1/v2 quota), physical cores, hyper-threading, NUMA nodes.
  2. Measures the service-time curve: seconds, CPU time and energy per call for each thread count and batch size (median of repeated timed loops, after warm-up).
  3. Measures workers together: several worker processes running at once, each with its thread limit set before the model library loads, to capture memory-bandwidth and cache contention.
  4. Simulates online serving with random (Poisson) arrivals, a shared queue, workers and micro-batching (max batch, max wait), using the measured curves and contention. The simulator reproduces M/D/1 queueing theory in its tests.
  5. Recommends the fastest single-request setting, the best bulk-scoring layout, and the serving setups that meet your latency target with the least energy and with the lowest latency, plus the environment variables to set.

Supported models

XGBoost (.json, .ubj), LightGBM (.txt), CatBoost (.cbm), scikit-learn and anything pickled with joblib or pickle (.joblib, .pkl), ONNX Runtime (.onnx), PyTorch (from a factory), or any object with predict. Threads are set through each library's own option (XGBoost nthread, LightGBM num_threads, CatBoost thread_count, scikit-learn n_jobs, ONNX Runtime intra_op_num_threads, PyTorch set_num_threads), through threadpoolctl for OpenMP and BLAS pools when installed, and through OMP_NUM_THREADS and the BLAS variables for worker processes.

ONNX Runtime sessions are created with thread spinning off: the ONNX Runtime docs note that spinning gives faster inference but uses more CPU and power.

Only load model files you trust: joblib and pickle files can run code when loaded. model-file-guard checks them first.

Options

--data FILE           Sample rows (.csv, .parquet, .npy); --drop COLUMNS removes the target
--threads 1,2,4,8     Thread counts to try (default: powers of 2 up to the usable CPUs)
--batches 1,8,64,512  Batch sizes to try (default: powers of 2 up to 1024)
--rate N --slo-ms MS  Plan online serving for N requests/s with the latency target
--quantile p95        p50, p95, p99 or mean for the target
--no-scaling          Skip the multi-process measurement
--oversubscribe       Also try twice as many processes as fit, to see the cost
--energy auto         rapl, cpu-time or auto; --tdp WATTS for the CPU-time model
--json, --md FILE

From Python:

from parallel_inference_tuner import tune, format_text
report = tune("model.json", X_sample, rate=300, slo_ms=20)
print(format_text(report))
print(report["settings"])  # workers, threads_per_worker, max_batch, max_wait_ms, env

Worker processes load the model themselves, so give a file path or a "package.module:function" factory for the multi-process step. With a model object, only the single-process curve is measured.

Energy

Energy comes from greeninfer: RAPL package counters with idle power subtracted where they are readable (bare-metal Linux, usually as root since CVE-2020-8694), otherwise the Green Algorithms model (CPU time x TDP per logical core). The CPU-time model has no idle power, so in that mode waiting to fill a batch looks free; the report says so. Pass --tdp with your CPU's real TDP for better estimates.

Limits

  • The simulator assumes Poisson arrivals and one shared queue. Bursty traffic needs more headroom than it predicts.
  • Contention is measured with every worker busy; at light load it is lower, so predictions err on the slow side.
  • GPU inference is not covered.
  • Short runs on busy machines are noisy. Close other work and use --min-time 0.5 --repeats 5 for final numbers.

SDG alignment

This tool supports SDG target 7.3 (double the global rate of improvement in energy efficiency): the same model, on the same hardware, often runs at half the energy per prediction with better thread, process and batch settings. It also supports target 9.4 (resource-efficient infrastructure), since a well-tuned server handles more traffic before another machine is needed.

Sources

About

Built by Ahmad Zia, who researches energy-efficient inference for gradient-boosted tree models and teaches parallel and distributed computing. MIT licensed.

Guide, help and author

Built by Ahmad Zia (Muhammad Ahmad Zia), an AI consultant for ecommerce since 2020 and green AI researcher at the University of Lahore. Research · Google Scholar · ORCID · LinkedIn · GitHub

More AI cost control tools

  • llm-cost-shield: Stop surprise LLM bills with per-user budgets, caching and cheap-model routing
  • right-size-model: Find the cheapest LLM that is good enough for each task, with a statistical test
  • green-batch-ai: Run bulk AI jobs at half price and on cleaner power

All 30 tools and agent skills: github.com/MuhammadAhmadZia · ahmadzia.com/tools

Metadata

Release files for parallel-inference-tuner 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parallel-inference-tuner 0.1.0
File Size Uploaded Provenance Actions
parallel_inference_tuner-0.1.0.tar.gz 25.0 kB With provenance Details for parallel_inference_tuner-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for parallel-inference-tuner 0.1.0
File Interpreter ABI Platform Actions
parallel_inference_tuner-0.1.0-py3-none-any.whl Python 3 none any Details for parallel_inference_tuner-0.1.0-py3-none-any.whl

Total release size: 49.1 kB

Release files / parallel_inference_tuner-0.1.0.tar.gz

Download URL parallel_inference_tuner-0.1.0.tar.gz
Size 25.0 kB
Tags Source
SHA-256 checksum
How to use checksums
12bffd7ecf3d14c8f8a2653481686a5965f3155b18b7a6ad4582ed5fd3e19d8a
BLAKE2b-256 checksum
How to use checksums
116764ac50a054b8862be809c837b99dbe9941fadda83ea8e69d03f2980cffed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Release files / parallel_inference_tuner-0.1.0-py3-none-any.whl

Download URL parallel_inference_tuner-0.1.0-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97662c5feb58c9b58d62675f9b04b0db92e46a7d434df3d458ea780994021555
BLAKE2b-256 checksum
How to use checksums
8e813085fb088445c9929290c07eebd1dbd8f8f1f68a02674811c9f0c8c4ba48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Security for parallel-inference-tuner 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for parallel_inference_tuner-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page