You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using torchmetrics with multiple metrics classes implemented along with DDP. I use these classes inside a MetricCollection defined as part of the model. The DDP module transfers the model to 4 GPUs but during the call to the metrics forward method, I get the following error:
RuntimeError: Encountered different devices in metric calculation (see stacktrace for details). This could be due to the metric class not being on the same device as input. Instead of metric=CrossEntropy(...) try to do metric=CrossEntropy(...).to(device) where device corresponds to the device of the input.
I define metrics like this in the model's init method:
This means all metrics are on 4 different GPUs but still the individual metrics do not seem to be moved to GPU.
What am I missing in the code to move the torchmetrics to the GPU?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am using torchmetrics with multiple metrics classes implemented along with DDP. I use these classes inside a MetricCollection defined as part of the model. The DDP module transfers the model to 4 GPUs but during the call to the metrics forward method, I get the following error:
I define metrics like this in the model's init method:
Methods defined in the distributed class:
Call to metrics while training:
When I print the metric object reference from the model here, I can see MetricCollection and all metrics inside it being printed 4 times:
This means all metrics are on 4 different GPUs but still the individual metrics do not seem to be moved to GPU.
What am I missing in the code to move the torchmetrics to the GPU?
Beta Was this translation helpful? Give feedback.
All reactions