Skip to main content

A library for providing a simple interface to create new metrics and an easy-to-use toolkit for metric computations and checkpointing.

Project description

TorchEval

This library is currently in Alpha and currently does not have a stable release. The API may change and may not be backward compatible. If you have suggestions for improvements, please open a GitHub issue. We'd love to hear your feedback.

A library that contains a rich collection of performant PyTorch model metrics, a simple interface to create new metrics, a toolkit to facilitate metric computation in distributed training and tools for PyTorch model evaluations.

Installing TorchEval

Requires Python >= 3.7 and PyTorch >= 1.11

From pip:

pip install torcheval

For nighly build version

pip install --pre torcheval-nightly

From source:

git clone https://github.com/facebookresearch/torcheval
cd torcheval
pip install -r requirements.txt
python setup.py install

Quick Start

cd torcheval
python examples/simple_example.py

Using TorchEval

TorchEval can be run on CPU, GPU, and Multi-GPUs/Muti-Nodes.

For the multiple devices usage:

import torch
from torcheval.metrics.toolkit import sync_and_compute
from torcheval.metrics import MulticlassAccuracy

local_rank = int(os.environ["LOCAL_RANK"])
global_rank = int(os.environ["RANK"])
world_size  = int(os.environ["WORLD_SIZE"])

device = torch.device(
    f"cuda:{local_rank}"
    if torch.cuda.is_available() and torch.cuda.device_count() >= world_size
    else "cpu"
)

metric = MulticlassAccuracy().to(device)
num_epochs, num_batches = 4, 8

for epoch in range(num_epochs):
    for i in range(num_batches):
        input = torch.randint(high=5, size=(10,), device=device)
        target = torch.randint(high=5, size=(10,), device=device)

        # metric.update() updates the metric state with new data
        metric.update(preds, target)


        # metric.compute() returns metric value from all seen data on the local process.
        local_compute_result = metric.compute()

        # sync_and_compute(metric) returns metric value from all seen data on all processes.
        # It gives the same result as ``metric.compute()`` if it's run on single process.
        global_compute_result = sync_and_compute(metric)

        # The final result is collected by rank 0
        if global_rank == 0:
            print(global_compute_result)

    # metric.reset() cleans up all seen data
    metric.reset()

See the example directory for more examples.

Contributing

We welcome PRs! See the CONTRIBUTING file.

License

TorchEval is BSD licensed, as found in the LICENSE file.

Project details


Download files

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

Source Distribution

torcheval-0.0.2.tar.gz (46.2 kB view details)

Uploaded Source

Built Distributions

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

torcheval-0.0.2-py3.9.egg (167.8 kB view details)

Uploaded Egg

torcheval-0.0.2-py3-none-any.whl (85.3 kB view details)

Uploaded Python 3

File details

Details for the file torcheval-0.0.2.tar.gz.

File metadata

  • Download URL: torcheval-0.0.2.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for torcheval-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ccd2be94ffdcd554fdb780dd9193bb9e178f24b7de1ac6adb12f3f8c254fc406
MD5 5454b0234671f1350dcfcb53d8cea22b
BLAKE2b-256 f0af4cad5e2b5441b48a7b966b74ece824c80c9d2a19ebd89ebd2c0f0b0d8abb

See more details on using hashes here.

File details

Details for the file torcheval-0.0.2-py3.9.egg.

File metadata

  • Download URL: torcheval-0.0.2-py3.9.egg
  • Upload date:
  • Size: 167.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for torcheval-0.0.2-py3.9.egg
Algorithm Hash digest
SHA256 f241410c06f3a28d33b0929fdb7d8d76312cb7580eaf8f1e0ba2af91b3c3d9d7
MD5 7bcb01f5ba280e8e3c84583681afeb9b
BLAKE2b-256 51948f24f064a68afcd8c769ae0b916281bf6f55f63946e2d60496823a48be20

See more details on using hashes here.

File details

Details for the file torcheval-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: torcheval-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 85.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for torcheval-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ee7f1719055d857b5b90e02a599059e5bcdbfb42fb7ea2b67ea9c5a5174c9e84
MD5 529639e16f995e48a05e16eb6545c390
BLAKE2b-256 0bd3a273090ae69d28f0912d109ec50a17837a898e39e98053c6c3002feeca96

See more details on using hashes here.

Supported by

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