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
{{ message }}
Repository navigation
[Bug] GlobalMutualInformationLoss: bin_centers not registered as buffer — silent gradient tracking + wrong device placement #8866
In GlobalMutualInformationLoss.__init__ (monai/losses/image_dissimilarity.py, ~line 210), the bin_centers tensor is assigned as a plain Python attribute:
This is the same pattern as the bug fixed in #8819 for LocalNormalizedCrossCorrelationLoss. Because bin_centers is not registered via self.register_buffer(...), it has two related problems:
Problem 1: Wrong device placement
When the user calls loss_fn.cuda() or loss_fn.to(device), PyTorch only moves register_buffer-registered tensors. The plain self.bin_centers stays on CPU, causing a RuntimeError: Expected all tensors to be on the same device when the loss is computed on a GPU.
Problem 2: Silent gradient tracking bin_centers is a constant — it should never accumulate gradients. However, because it is not registered as a buffer, it is not guaranteed to have requires_grad=False across all code paths, and it will not be excluded properly from gradient-related checks.
Activity
Register GlobalMutualInformationLoss bin_centers as buffer (#8869)