Skip to main content

Green AI Profiler

CI PyPI License Python

Open-source AI model profiler for PyTorch (and ONNX) that measures latency, throughput, memory, energy consumption, and layer-wise bottlenecks—so you can build faster, cheaper, and greener models without guessing.

Search terms this project covers: AI model profiler, PyTorch latency benchmark, ML energy measurement, green AI, model efficiency toolkit, inference performance profiler, NVML / RAPL energy, layer-wise profiling, sustainable machine learning.

pip install "green-ai-profiler[torch]"
greenai profile model.pt --allow-pickle --input-shape 1,28,28

What you can measure

Goal What Green AI Profiler does
Inference latency & throughput Warmup + timed runs on CPU or CUDA
Memory footprint Process RSS and CUDA allocator stats
Energy / power Real hardware telemetry (NVIDIA NVML, Intel RAPL)—never fabricated joules
Layer bottlenecks Per-module latency to find expensive ops
Optimization hints Actionable recommendations from profile data

Why this exists

Accuracy alone is not enough. ML engineers, researchers, and MLOps teams also need:

  • model latency and samples/sec
  • memory and peak RSS behavior
  • parameter count and model size
  • energy per inference and carbon-aware efficiency (when measurable)

Energy is hardware-dependent. This project never fabricates joules. If a backend is unavailable, you get an explicit status and reason.

How people run this

1. Install from PyPI (recommended)

Requirements: Python 3.11+

python -m venv .venv

# Windows
.venv\Scripts\activate

# macOS / Linux
source .venv/bin/activate

pip install -U pip
pip install "green-ai-profiler[torch]"

Useful extras:

Extra Install Purpose
torch pip install "green-ai-profiler[torch]" Profile PyTorch models (recommended)
onnx pip install "green-ai-profiler[onnx]" ONNX inspection / runtime support
nvidia pip install "green-ai-profiler[nvidia]" NVIDIA NVML energy via nvidia-ml-py
viz pip install "green-ai-profiler[viz]" Plotting helpers
dev pip install "green-ai-profiler[dev]" Tests and lint tools
all pip install "green-ai-profiler[all]" Everything above

Verify the install:

greenai --version
greenai --help
greenai system-info

From source (contributors)

git clone https://github.com/Md-Sifat-Bin-Jibon/greenai-profiler.git
cd greenai-profiler
python -m venv .venv
# activate the venv, then:
pip install -e ".[torch,dev]"

2. Profile a model (CLI)

Try the built-in example first:

python examples/save_example_model.py

greenai inspect examples/artifacts/tiny_cnn.pt --allow-pickle --input-shape 1,28,28
greenai benchmark examples/artifacts/tiny_cnn.pt --allow-pickle --input-shape 1,28,28
greenai profile examples/artifacts/tiny_cnn.pt --allow-pickle --input-shape 1,28,28 --output results.json
greenai report results.json --html report.html

Then point greenai at your own checkpoint:

# CPU
greenai profile path/to/model.pt --allow-pickle --input-shape 3,224,224

# CUDA (if PyTorch CUDA is available)
greenai profile path/to/model.pt --allow-pickle --device cuda --input-shape 3,224,224

# Save JSON for later comparison / HTML report
greenai profile path/to/model.pt --allow-pickle --input-shape 3,224,224 --output results.json
greenai compare baseline.json optimized.json
greenai report results.json --html report.html

--allow-pickle is required for full torch.save(model, ...) module checkpoints. Only use it for models you trust. Prefer a state_dict plus reconstructed architecture — see examples/state_dict_workflow.py and docs/security.md.

3. Use it from Python

import torch
from greenai.benchmark import BenchmarkConfig, run_benchmark
from greenai.models.pytorch import PyTorchModelAdapter

model = torch.nn.Sequential(
    torch.nn.Flatten(),
    torch.nn.Linear(64, 32),
    torch.nn.ReLU(),
    torch.nn.Linear(32, 4),
)
adapter = PyTorchModelAdapter(model, device="cpu", example_input_shape=[64])
result = run_benchmark(
    adapter,
    BenchmarkConfig(device="cpu", input_shape=[64], warmup=2, iterations=10),
)

print(f"mean latency: {result.latency.mean_seconds * 1000:.3f} ms")
print(f"energy status: {result.energy.status if result.energy else 'n/a'}")

Runnable copy: examples/basic_benchmark.py.

4. CLI reference

Command What it does
greenai system-info Detect host CPU/GPU/energy capabilities
greenai inspect <model> Model size, parameters, basic structure
greenai benchmark <model> Latency, throughput, memory, energy
greenai profile <model> Full efficiency profile + layers + recommendations
greenai layer-profile <model> Leaf-module latency breakdown
greenai compare <a.json> <b.json> Diff two saved profiles
greenai report <results.json> Re-print results; optional --html

Common options on profile/benchmark commands:

  • --device cpu|cuda
  • --batch-size N
  • --input-shape C,H,W (no batch dim)
  • --warmup N / --iterations N
  • --allow-pickle
  • --output path / --format json|csv
  • --no-energy

Example output

╭──────── Green AI Profiler ────────╮
Model
  TinyCNN

Performance
  Latency:       0.42 ms
  P95:           0.55 ms
  Throughput:    2380.1 samples/sec

Memory
  Peak/RSS:      184.12 MB

Energy
  Status:        unavailable
  Reason:        No supported hardware energy interface detected.

Model Stats
  Parameters:    11.98K
  Size:          47.92 KB
╰───────────────────────────────────╯

Supported hardware

Capability Status
CPU latency / RSS Supported
CUDA latency / allocator memory Supported (with PyTorch CUDA)
NVIDIA power → energy (NVML) Supported when nvidia-ml-py + driver allow it
Intel RAPL energy Supported on Linux hosts with powercap
Android / edge direct profiling Planned (import protocol only for now)
Exact per-layer energy Unavailable on typical desktop APIs

Details: docs/hardware-support.md, docs/energy-measurement.md.

Architecture

CLI (Typer)
   │
   ▼
Models ──► Benchmark runner ──► Reporting (terminal / JSON / CSV / HTML)
   │              │
   │              ├── Latency / throughput
   │              ├── Memory (CPU RSS, CUDA)
   │              └── Energy monitors (NVML / RAPL / unavailable)
   │
   └── Layer profiler ──► Bottlenecks ──► Recommendations

See docs/architecture.md.

Documentation

Guide Link
Installation docs/installation.md
Quickstart docs/quickstart.md
Benchmarking docs/benchmarking.md
Layer profiling docs/layer-profiling.md
Energy measurement docs/energy-measurement.md
Limitations docs/limitations.md
Security SECURITY.md, docs/security.md
Contributing CONTRIBUTING.md

Limitations

  • Pickle-based .pt files can execute code; safe loading is default, --allow-pickle is explicit.
  • Process RSS is not model-only memory.
  • Energy requires real hardware telemetry; estimates are labeled if ever used.
  • ONNX support is inspection-oriented in this release.
  • Green Score is a project-defined heuristic, not a scientific standard.

Development

pip install -e ".[dev,torch]"
ruff check src tests
mypy src
pytest

Roadmap

  • Broader ONNX Runtime benchmarking
  • Static INT8 calibration workflows
  • Edge/Android measurement import protocol
  • Richer visualization pack
  • Expanded hardware energy backends

License

Apache License 2.0 — see LICENSE.

Metadata

Release files for green-ai-profiler 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 green-ai-profiler 0.1.0
File Size Uploaded
green_ai_profiler-0.1.0.tar.gz 42.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for green-ai-profiler 0.1.0
File Interpreter ABI Platform
green_ai_profiler-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 90.9 kB

Release files / green_ai_profiler-0.1.0.tar.gz

Download URL green_ai_profiler-0.1.0.tar.gz
Size 42.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3b61fa9255b03ab053e5bc01ab77a6f73921993e7611980a166f3b359fed8f10
BLAKE2b-256 checksum
How to use checksums
3bd0302e213dc1ae4754cf6dfbf41d9cb311616d35df1acff9a70fc63bb19aa9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 17, 2026.

Transparency log

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

Download URL green_ai_profiler-0.1.0-py3-none-any.whl
Size 48.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af0fa078303943b96bffe24d9cd517881732ac3f39c87d7053207803a8534684
BLAKE2b-256 checksum
How to use checksums
f8e08461f52b4dd620e52675dc4569359369b5be5096f2e2181fe61b8ce35980
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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