datamol-io / graphium

Graphium: Scaling molecular GNNs to infinity.
https://graphium-docs.datamol.io/
Apache License 2.0
197 stars 12 forks source link

Support metrics with NaNs in them on IPU #129

Closed DomInvivo closed 1 year ago

DomInvivo commented 2 years ago

When working with IPU's, NaNs cannot be filtered out as is typically done on GPU/CPU. We need fancier ways of masking NaNs on the targets. I have started implementing a few metrics/losses such as BCE, MSE, and L1 in the ipu_metrics.py file, but other metrics need to be implemented.

Classification metrics

Regression metrics

Unit-tests

DomInvivo commented 2 years ago

Currently working on that with @odymov

DomInvivo commented 2 years ago

A better way to make metrics invariant to NaNs for Accuracy, Precision and Recall!

Accuracy and Recall metrics are invariant to the number of False positive. So everywhere there's a NaN, convert it to a False positive!

# Make all NaNs into false positives for **Accuracy** and **Recall**
nans = torch.isnan(targets)
targets[nans] = 0 # Make it a negative target
preds[nans] = 1 # Make it a positive pred

For Precision, convert all to false negative

# Make all NaNs into false positives for **Precision**
nans = torch.isnan(targets)
targets[nans] = 1 # Make it a negative target
preds[nans] = 0 # Make it a positive pred

image