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.

Download files

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

Source Distribution

green_ai_profiler-0.1.0.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

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

green_ai_profiler-0.1.0-py3-none-any.whl (48.3 kB view details)

Uploaded Python 3

File details

Details for the file green_ai_profiler-0.1.0.tar.gz.

File metadata

  • Download URL: green_ai_profiler-0.1.0.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for green_ai_profiler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b61fa9255b03ab053e5bc01ab77a6f73921993e7611980a166f3b359fed8f10
MD5 db01d3dececcd073b82144d7fcb2dc51
BLAKE2b-256 3bd0302e213dc1ae4754cf6dfbf41d9cb311616d35df1acff9a70fc63bb19aa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for green_ai_profiler-0.1.0.tar.gz:

Publisher: release.yml on Md-Sifat-Bin-Jibon/greenai-profiler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file green_ai_profiler-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for green_ai_profiler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af0fa078303943b96bffe24d9cd517881732ac3f39c87d7053207803a8534684
MD5 f3dba62335092cd05ce225f8b9dd3304
BLAKE2b-256 f8e08461f52b4dd620e52675dc4569359369b5be5096f2e2181fe61b8ce35980

See more details on using hashes here.

Provenance

The following attestation bundles were made for green_ai_profiler-0.1.0-py3-none-any.whl:

Publisher: release.yml on Md-Sifat-Bin-Jibon/greenai-profiler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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