skillfed

torchmetrics

PyTorch native Metrics

torchmetrics v1.9.0 12.3M downloads/30d#1,331 on PyPI2,458
Permissive license Apache-2.0 Active released

What it is and what it does

Torchmetrics is a PyTorch library that standardizes metric computation for machine learning models, particularly in distributed and multi-device training scenarios. It provides a collection of pre-built metrics (accuracy, F1, precision, recall, and many others) alongside an API for defining custom metrics. The library handles the boilerplate of accumulating metric state across batches and synchronizing results across multiple GPUs or nodes automatically, so you can focus on model logic rather than metric plumbing.

The package works as a PyTorch module—you instantiate a metric, move it to your device, call it with predictions and targets in a training loop, and it tracks state internally. It supports single-GPU, multi-GPU with DDP, and multi-node setups without code changes. It also integrates tightly with PyTorch Lightning, where metrics are automatically placed on the correct device and logged with minimal extra code.

Use it for:

  • Evaluate classification models on multi-GPU training runs without manually synchronizing accuracy or F1 scores across devices.
  • Track cumulative metrics over an entire epoch or dataset without storing all predictions in memory.
  • Implement custom metrics by subclassing Metric and defining update() and compute() methods for domain-specific evaluation.
  • Log metrics to PyTorch Lightning training runs with automatic device placement and distributed synchronization.
  • Benchmark model performance reproducibly using a standardized metric interface across different training frameworks.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Torchmetrics provides a collection of PyTorch metrics implementations with automatic batch accumulation and multi-device synchronization, designed for distributed training workflows.

Yes. Torchmetrics is a mature, actively maintained library (2458 stars, recent releases) with low install friction and no known vulnerabilities. It solves a real problem—metric computation in distributed PyTorch training—with a clean API and tight Lightning integration. Use it if you train models on multiple GPUs or need reproducible, standardized metric evaluation; skip it only if you compute metrics outside PyTorch or have highly specialized evaluation logic.

Install

torchmetrics on PyPI

pip

pip install torchmetrics

uv

uv add torchmetrics

poetry

poetry add torchmetrics

Installing torchmetrics

Before you install

Low install friction with a pure-Python wheel distribution. Active maintenance with recent releases and 2458 repository stars. Requires torch and three lightweight dependencies (numpy, packaging, lightning-utilities).

License in practice

Apache-2.0 permissive license allows commercial and private use with minimal restrictions—standard for ML tooling.

Quickstart

pip install torchmetrics

import torch
import torchmetrics

metric = torchmetrics.classification.Accuracy(task="multiclass", num_classes=5)
device = "cuda" if torch.cuda.is_available() else "cpu"
metric.to(device)

preds = torch.randn(10, 5).softmax(dim=-1).to(device)
target = torch.randint(5, (10,)).to(device)
acc = metric(preds, target)

Requires PyTorch (torch) to be installed; Python 3.10 or later.

Verify before relying

  • Whether the 100+ built-in metrics cover your specific evaluation needs
  • Performance overhead of automatic synchronization in very large distributed setups
  • Compatibility with custom PyTorch training loops vs. PyTorch Lightning integration benefits

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 4 — numpy, packaging, torch, lightning-utilities
Maintenance actively maintained — 158 days since the last release
Last repo commit
First released
Downloads 12,257,228/month — #1,331 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: torchmetrics-1.9.0-py3-none-any.whl

Keywords: deep learning, machine learning, pytorch, metrics, AI

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Topic :: Scientific/Engineering :: Artificial IntelligenceTopic :: Scientific/Engineering :: Image RecognitionTopic :: Scientific/Engineering :: Information Analysis

Tags

pytorch metrics librarydistributed training metricsbatch accumulation metricsmulti-gpu metric synchronizationmachine learning evaluation metricspytorch model evaluationscalable ml metrics
distributed-trainingpytorch-ecosystemml-evaluation

More Artificial Intelligence packages