--- id: torchmetrics version: "1.9.0" license: Apache-2.0 license_treatment: permissive maintenance: active --- # torchmetrics — PyTorch native Metrics License: permissive · Maintenance: active · Downloads: 12.3M/mo ## 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 above — 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 pip install torchmetrics uv add torchmetrics 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_current - Install friction: low - Maintenance: active - Downloads: 12.3M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags pytorch metrics library, distributed training metrics, batch accumulation metrics, multi-gpu metric synchronization, machine learning evaluation metrics, pytorch model evaluation, scalable ml metrics, distributed-training, pytorch-ecosystem, ml-evaluation [View on SkillFed](https://skillfed.io/packages/torchmetrics) · [View on PyPI](https://pypi.org/project/torchmetrics/)