Skip to content
Discussion options

You must be logged in to vote

@FeryET — this was a common issue with the old API and Lightning's MetricCollection. The root cause was almost always one of:

Cause 1: Sharing metric instances across stages.

# WRONG — same metric object for train and val
self.metrics = MetricCollection({"acc": Accuracy(), "f1": F1()})
self.train_metrics = self.metrics
self.val_metrics = self.metrics  # shares state!

Fix:

# RIGHT — .clone() creates independent copies
self.train_metrics = MetricCollection({"acc": Accuracy(), "f1": F1()})
self.val_metrics = self.train_metrics.clone(prefix="val_")

Cause 2: Using the old unified API incorrectly.

Here's the correct pattern today (v1.9.0):

from torchmetrics import MetricCollection
from torchmet…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Borda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants