Skip to main content

Tool for monitoring LLM inference metrics

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_perf_tools-0.2.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_perf_tools-0.2.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file llm_perf_tools-0.2.0.tar.gz.

File metadata

  • Download URL: llm_perf_tools-0.2.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.5 Darwin/24.6.0

File hashes

Hashes for llm_perf_tools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8a0da7cb7ee9585297a43e83074891a6d6663a4f69c7b5d4c0eec95883178188
MD5 8334ccbda4f9e2bc4585b687ceef37fe
BLAKE2b-256 79242727c9e18036fef8ee9fba97978ee2ce068b0ce817c7e3815d53a03dba5c

See more details on using hashes here.

File details

Details for the file llm_perf_tools-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: llm_perf_tools-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.5 Darwin/24.6.0

File hashes

Hashes for llm_perf_tools-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18a8efcda634d24eab548b2b30f2b3290f29eeae2ef6cf474f2e1c312f228930
MD5 26dd2b80ebc292f1cbcadaaa89a0cfd2
BLAKE2b-256 b6d1c9fe1b5ad0d5061045c6e59cad818616ec7d65b7f1bb8fddef767bacbf84

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page