torchmetrics icon indicating copy to clipboard operation
torchmetrics copied to clipboard

Conversion from logits to probabilities happens on a batch by batch basis

Open GabrielBianconi opened this issue 2 years ago • 7 comments

🐛 Bug

I'm using BinaryAUROC and calling .update(logits, y) after each batch (validation_step), expecting the following behavior:

"If preds has values outside [0,1] range we consider the input to be logits and will auto apply sigmoid per element."

I noticed some discrepancies in the results, and after investigating realized that the rule above happens on a batch by batch basis rather than across the entire dataset (it happens in _binary_precision_recall_curve_format, which is called by update).

Therefore, if some batch has all logits in [0, 1], then the conversion doesn't happen for that batch.

My use case has batch size = 1, so this happens often.

Expected behavior

I'd expect that the conversion would happen consistently across the entire dataset (i.e., when calling .compute()). If not that, this behavior should be documented more prominently.

Environment

torchmetrics==1.0.3

GabrielBianconi avatar Oct 31 '23 03:10 GabrielBianconi

Hi! thanks for your contribution!, great first issue!

github-actions[bot] avatar Oct 31 '23 03:10 github-actions[bot]

I came to report just this. As a "workaround", I always call sigmoid first, as at least that path is sound.

ocharles avatar Dec 12 '23 16:12 ocharles

Dupe of https://github.com/Lightning-AI/torchmetrics/issues/1604, probably

ocharles avatar Dec 12 '23 17:12 ocharles

@GabrielBianconi could you please clarify how you installed TM 1.0.3, as at the time the latest was already 1.2 :rabbit:

Borda avatar Jan 16 '24 15:01 Borda

I installed it a few months before my post. But I'm pretty sure that the bug was still on master back then.

GabrielBianconi avatar Jan 16 '24 19:01 GabrielBianconi