torchmetrics
PyTorch native Metrics
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires PyTorch (torch) to be installed; Python 3.10 or later.
- Low install friction with a pure-Python wheel distribution.
- Active maintenance with recent releases and 2458 repository stars.
License · maintenance · safety
Apache-2.0 (permissive) — Apache-2.0 permissive license allows commercial and private use with minimal restrictions—standard for ML tooling.
last release 2026-03-09 (158 days) · last repo commit 2026-07-16 · 2,458 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 12,257,228 downloads/mo, #1,331 on PyPI
Alternatives
Verify before relying
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)- 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
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 on it.
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
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).
Requires PyTorch (torch) to be installed; Python 3.10 or later.
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)
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 packagesnumpypackagingtorchlightning-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 |
| Classifiers | 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 |
Evidence: torchmetrics-1.9.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “batch accumulation metrics”
- torchmetricsTorchmetrics provides a collection of PyTorch metrics implementations…
- trainerTrainer is a PyTorch model training framework that handles the…
- accumulation-treeImplements a red/black tree that stores partial aggregations at each…
Give your agent the search over MCP, or paste the wish link into any chat.
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to call 100+ LLM providers (OpenAI, Anthropic, Gemini, Bedrock, Azure, and others) using OpenAI-compatible API format, available as both a Python SDK and a self-hosted AI Gateway proxy server.
Install it if you need to work with multiple LLM providers or want to centralize LLM routing in your organization.
Client library and CLI tool for downloading, uploading, and managing models, datasets, and repositories on the Hugging Face Hub platform.
Install it if you work with Hugging Face Hub models or datasets.
LangChain provides a framework for building agents and LLM-powered applications by composing language models, tools, and memory through a unified API that abstracts over multiple model providers.
hf-xet provides chunk-based deduplication and efficient file transfer for the Hugging Face Hub, enabling faster uploads and downloads of large files with local disk caching.
Tokenizers converts raw text into token sequences for NLP models, with support for training custom vocabularies and using pre-built tokenizers (BPE, WordPiece) optimized for speed via Rust.
Transformers provides a unified framework for loading, fine-tuning, and running state-of-the-art pretrained models across text, vision, audio, video, and multimodal tasks using PyTorch, JAX, or TensorFlow.
Install it if you need to run or train any transformer-based model for NLP, vision, audio, or multimodal tasks.
See also torcheval · entmax · torchrunx · ema-pytorch · nv-one-logger-pytorch-lightning-integration · lightning · motmetrics · spmd-types · litdata · torch