Lightning-AI / pytorch-lightning

Pretrain, finetune ANY AI model of ANY size on multiple GPUs, TPUs with zero code changes.
https://lightning.ai
Apache License 2.0
28.51k stars 3.39k forks source link

Native support for Torchmetrics MetricCollection #13254

Closed SkafteNicki closed 1 year ago

SkafteNicki commented 2 years ago

🚀 Feature

Add native support in self.log for the MetricCollection object from Torchmetrics: https://torchmetrics.readthedocs.io/en/latest/pages/overview.html#metriccollection

Motivation

The MetricCollection object is used to chain together multiple metrics into a single object that can be update at once:

import torchmetrics as tm
metrics = tm.MetricCollection([tm.Accuracy(), tm.Precision(), tm.Recall()])
metrics.update(preds, target)

however, when one want to log such an object in PL it is often done on the individual metric:

self.log_dict({k:v for k,v in collection.items()})

However, this actually does not work with the compute_group feature that we implemented in v0.8 for faster computation of metrics that share the same computations.

This issue proposed that PL natively supports MetricCollection in the same way that Metric is support in self.log.

Pitch

Alternatives

Additional context

Already discussed on slack with @Borda and @justusschock


If you enjoy Lightning, check out our other projects! âš¡

cc @borda @carmocca @edward-io @ananthsub @rohitgr7 @kamil-kaczmarek @Raalsky @Blaizzy @akihironitta

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team!

carmocca commented 2 years ago

Setting this to "future" for now as it might not make the 1.7 release