Skip to main content

llm-perf-tools

Prerequisites

  • Python 3.10+
  • pyenv (recommended)
  • Poetry
  • OpenAI API access

Setup

pyenv local 3.10
python -m venv .venv
source .venv/bin/activate
make install

Environment

Create .env file:

# OpenAI config
OPENAI_API_KEY=your_api_key_here
OPENAI_BASE_URL=https://api.openai.com/v1/

# Optional: Langfuse config
LANGFUSE_SECRET_KEY=your_secret_key
LANGFUSE_PUBLIC_KEY=your_public_key
LANGFUSE_HOST=https://us.cloud.langfuse.com

Usage

Basic InferenceTracker usage:

import asyncio
import os
from openai import AsyncOpenAI
from llm_perf_tools import InferenceTracker
from dotenv import load_dotenv

load_dotenv()


async def main():
    client = AsyncOpenAI(
        api_key=os.getenv("OPENAI_API_KEY"),
        base_url=os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1"),
    )
    tracker = InferenceTracker(client)

    # Track a request
    response = await tracker.create_chat_completion(
        messages=[{"role": "user", "content": "Hello"}],
        model="gpt-5",
    )
    print(response)

    # Get performance metrics
    stats = tracker.compute_metrics()
    print("Metrics:\n")
    print(f"TTFT: {stats.avg_ttft:.3f}s")
    print(f"Throughput: {stats.rps:.2f} req/s")


asyncio.run(main())

GPU Monitoring

Basic GPU usage tracking:

import asyncio
from openai import AsyncOpenAI
from llm_perf_tools import InferenceTracker, monitor_gpu_usage

async def main():
    # Setup client for local LLM server (e.g., SGLang, vLLM, Ollama)
    client = AsyncOpenAI(base_url="http://localhost:30000/v1", api_key="None")
    
    with monitor_gpu_usage("gpu_metrics.csv", interval=0.1) as gpu_metrics:
        tracker = InferenceTracker(client)
        
        response = await tracker.create_chat_completion(
            messages=[{"role": "user", "content": "Hello"}],
            model="meta-llama/Llama-3.2-8B-Instruct"  # Replace with your model
        )
    
    print(f"Collected {len(gpu_metrics)} GPU samples")
    print("GPU metrics saved to gpu_metrics.csv")

asyncio.run(main())

Visualization

Visualize performance metrics with built-in plotting:

from llm_perf_tools import plot_eval_result

# Plot metrics from saved evaluation results
inference_path = "eval_results/batch_metrics.json"
gpu_path = "eval_results/gpu_metrics.csv"

plots = plot_eval_result(inference_path, gpu_path)

# Save plots
plots[0].savefig("inference_metrics.png", dpi=300, bbox_inches='tight')
plots[1].savefig("gpu_metrics.png", dpi=300, bbox_inches='tight')

print("Performance plots saved")

This generates two comprehensive plots:

Inference Metrics Plot: Inference Metrics

  • Time to First Token (TTFT) distribution and timeline
  • End-to-End Latency trends over time
  • Tokens per Second (TPS) performance
  • Inter-Token Latency (ITL) statistics

GPU Metrics Plot: GPU Metrics

  • GPU utilization percentage over time
  • Memory usage (used vs total)
  • Temperature monitoring
  • Power consumption tracking

Metadata

Release files for llm-perf-tools 0.2.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 llm-perf-tools 0.2.0
File Size Uploaded Provenance
llm_perf_tools-0.2.0.tar.gz 13.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-perf-tools 0.2.0
File Interpreter ABI Platform
llm_perf_tools-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.1 kB

Release files / llm_perf_tools-0.2.0.tar.gz

Download URL llm_perf_tools-0.2.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8a0da7cb7ee9585297a43e83074891a6d6663a4f69c7b5d4c0eec95883178188
BLAKE2b-256 checksum
How to use checksums
79242727c9e18036fef8ee9fba97978ee2ce068b0ce817c7e3815d53a03dba5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.0 CPython/3.13.5 Darwin/24.6.0

Release files / llm_perf_tools-0.2.0-py3-none-any.whl

Download URL llm_perf_tools-0.2.0-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18a8efcda634d24eab548b2b30f2b3290f29eeae2ef6cf474f2e1c312f228930
BLAKE2b-256 checksum
How to use checksums
b6d1c9fe1b5ad0d5061045c6e59cad818616ec7d65b7f1bb8fddef767bacbf84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.0 CPython/3.13.5 Darwin/24.6.0

Security for llm-perf-tools 0.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.2.0 This release

2 release files No 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