Repository: Project-MONAI/MONAI

Issue:
torch 1.9 compatibility test_surface_distance
```
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_not_predicted_not_present (tests.test_surface_dice.TestAllSurfaceDiceMetrics)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_dice.py", line 366, in test_not_predicted_not_present
[2023-10-05T00:02:00.061Z]     res_bgr_classes = sur_metric_bgr(predictions_hot, labels_hot)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 103, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_surface_dice(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 278, in compute_surface_dice
[2023-10-05T00:02:00.061Z]     nsd[b, c] = torch.nan
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_tolerance_euclidean_distance (tests.test_surface_dice.TestAllSurfaceDiceMetrics)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_dice.py", line 99, in test_tolerance_euclidean_distance
[2023-10-05T00:02:00.061Z]     res0 = sd0(predictions_hot, labels_hot)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 103, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_surface_dice(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 278, in compute_surface_dice
[2023-10-05T00:02:00.061Z]     nsd[b, c] = torch.nan
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_tolerance_euclidean_distance_3d (tests.test_surface_dice.TestAllSurfaceDiceMetrics)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_dice.py", line 143, in test_tolerance_euclidean_distance_3d
[2023-10-05T00:02:00.061Z]     res0 = sd0(predictions_hot, labels_hot)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 103, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_surface_dice(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 278, in compute_surface_dice
[2023-10-05T00:02:00.061Z]     nsd[b, c] = torch.nan
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_tolerance_euclidean_distance_with_spacing (tests.test_surface_dice.TestAllSurfaceDiceMetrics)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_dice.py", line 39, in test_tolerance_euclidean_distance_with_spacing
[2023-10-05T00:02:00.061Z]     res0 = sd0(predictions_hot, labels_hot, spacing=test_spacing)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 103, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_surface_dice(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 278, in compute_surface_dice
[2023-10-05T00:02:00.061Z]     nsd[b, c] = torch.nan
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_nans_0 (tests.test_hausdorff_distance.TestHausdorffDistance)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func
[2023-10-05T00:02:00.061Z]     return func(*(a + p.args), **p.kwargs, **kw)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_hausdorff_distance.py", line 201, in test_nans
[2023-10-05T00:02:00.061Z]     hd_metric(batch_seg_1, batch_seg_2, spacing=spacing)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 107, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_hausdorff_distance(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in compute_hausdorff_distance
[2023-10-05T00:02:00.061Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in <listcomp>
[2023-10-05T00:02:00.061Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 211, in _compute_percentile_hausdorff_distance
[2023-10-05T00:02:00.061Z]     return torch.tensor(torch.nan, dtype=torch.float, device=surface_distance.device)
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_nans_1 (tests.test_hausdorff_distance.TestHausdorffDistance)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func
[2023-10-05T00:02:00.061Z]     return func(*(a + p.args), **p.kwargs, **kw)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_hausdorff_distance.py", line 201, in test_nans
[2023-10-05T00:02:00.061Z]     hd_metric(batch_seg_1, batch_seg_2, spacing=spacing)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.062Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 107, in _compute_tensor
[2023-10-05T00:02:00.062Z]     return compute_hausdorff_distance(
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in compute_hausdorff_distance
[2023-10-05T00:02:00.062Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in <listcomp>
[2023-10-05T00:02:00.062Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 211, in _compute_percentile_hausdorff_distance
[2023-10-05T00:02:00.062Z]     return torch.tensor(torch.nan, dtype=torch.float, device=surface_distance.device)
[2023-10-05T00:02:00.062Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.062Z] 
[2023-10-05T00:02:00.062Z] ======================================================================
[2023-10-05T00:02:00.062Z] ERROR: test_compute (tests.test_handler_hausdorff_distance.TestHandlerHausdorffDistance)
[2023-10-05T00:02:00.062Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.062Z] Traceback (most recent call last):
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_handler_hausdorff_distance.py", line 84, in test_compute
[2023-10-05T00:02:00.062Z]     hd_metric.update([y_pred, y])
[2023-10-05T00:02:00.062Z]   File "/opt/conda/lib/python3.8/site-packages/ignite/metrics/metric.py", line 607, in wrapper
[2023-10-05T00:02:00.062Z]     func(self, *args, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/handlers/ignite_metric.py", line 112, in update
[2023-10-05T00:02:00.062Z]     self.metric_fn(y_pred, y)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.062Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.062Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 107, in _compute_tensor
[2023-10-05T00:02:00.062Z]     return compute_hausdorff_distance(
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in compute_hausdorff_distance
[2023-10-05T00:02:00.062Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in <listcomp>
[2023-10-05T00:02:00.062Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 211, in _compute_percentile_hausdorff_distance
[2023-10-05T00:02:00.062Z]     return torch.tensor(torch.nan, dtype=torch.float, device=surface_distance.device)
[2023-10-05T00:02:00.062Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.062Z] 
[2023-10-05T00:02:00.062Z] ======================================================================
[2023-10-05T00:02:00.062Z] ERROR: test_compute (tests.test_handler_surface_distance.TestHandlerSurfaceDistance)
[2023-10-05T00:02:00.062Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.062Z] Traceback (most recent call last):
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_handler_surface_distance.py", line 84, in test_compute
[2023-10-05T00:02:00.062Z]     sur_metric.update([y_pred, y])
[2023-10-05T00:02:00.062Z]   File "/opt/conda/lib/python3.8/site-packages/ignite/metrics/metric.py", line 607, in wrapper
[2023-10-05T00:02:00.062Z]     func(self, *args, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/handlers/ignite_metric.py", line 112, in update
[2023-10-05T00:02:00.062Z]     self.metric_fn(y_pred, y)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.062Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.062Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_distance.py", line 93, in _compute_tensor
[2023-10-05T00:02:00.062Z]     return compute_average_surface_distance(
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_distance.py", line 184, in compute_average_surface_distance
[2023-10-05T00:02:00.062Z]     asd[b, c] = torch.nan if surface_distance.shape == (0,) else surface_distance.mean()
[2023-10-05T00:02:00.062Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.062Z] 
[2023-10-05T00:02:00.062Z] ======================================================================
[2023-10-05T00:02:00.062Z] ERROR: test_nans_0 (tests.test_surface_distance.TestAllSurfaceMetrics)
[2023-10-05T00:02:00.062Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.062Z] Traceback (most recent call last):
[2023-10-05T00:02:00.062Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func
[2023-10-05T00:02:00.062Z]     return func(*(a + p.args), **p.kwargs, **kw)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_distance.py", line 178, in test_nans
[2023-10-05T00:02:00.062Z]     sur_metric(batch_seg_1, batch_seg_2, spacing=spacing)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.062Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 73, in __call__
[2023-10-05T00:02:00.062Z]     return self._compute_list(y_pred, y, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 97, in _compute_list
[2023-10-05T00:02:00.062Z]     ret = [
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 98, in <listcomp>
[2023-10-05T00:02:00.062Z]     self._compute_tensor(p.detach().unsqueeze(0), y_.detach().unsqueeze(0), **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_distance.py", line 93, in _compute_tensor
[2023-10-05T00:02:00.062Z]     return compute_average_surface_distance(
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_distance.py", line 184, in compute_average_surface_distance
[2023-10-05T00:02:00.062Z]     asd[b, c] = torch.nan if surface_distance.shape == (0,) else surface_distance.mean()
[2023-10-05T00:02:00.062Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.062Z] 
[2023-10-05T00:02:00.062Z] ======================================================================
[2023-10-05T00:02:00.062Z] ERROR: test_nans_1 (tests.test_surface_distance.TestAllSurfaceMetrics)
[2023-10-05T00:02:00.062Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.062Z] 
```
torch 1.9 compatibility test_surface_distance
```
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_not_predicted_not_present (tests.test_surface_dice.TestAllSurfaceDiceMetrics)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_dice.py", line 366, in test_not_predicted_not_present
[2023-10-05T00:02:00.061Z]     res_bgr_classes = sur_metric_bgr(predictions_hot, labels_hot)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 103, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_surface_dice(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 278, in compute_surface_dice
[2023-10-05T00:02:00.061Z]     nsd[b, c] = torch.nan
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_tolerance_euclidean_distance (tests.test_surface_dice.TestAllSurfaceDiceMetrics)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_dice.py", line 99, in test_tolerance_euclidean_distance
[2023-10-05T00:02:00.061Z]     res0 = sd0(predictions_hot, labels_hot)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 103, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_surface_dice(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 278, in compute_surface_dice
[2023-10-05T00:02:00.061Z]     nsd[b, c] = torch.nan
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_tolerance_euclidean_distance_3d (tests.test_surface_dice.TestAllSurfaceDiceMetrics)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_dice.py", line 143, in test_tolerance_euclidean_distance_3d
[2023-10-05T00:02:00.061Z]     res0 = sd0(predictions_hot, labels_hot)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 103, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_surface_dice(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 278, in compute_surface_dice
[2023-10-05T00:02:00.061Z]     nsd[b, c] = torch.nan
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_tolerance_euclidean_distance_with_spacing (tests.test_surface_dice.TestAllSurfaceDiceMetrics)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_dice.py", line 39, in test_tolerance_euclidean_distance_with_spacing
[2023-10-05T00:02:00.061Z]     res0 = sd0(predictions_hot, labels_hot, spacing=test_spacing)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 103, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_surface_dice(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_dice.py", line 278, in compute_surface_dice
[2023-10-05T00:02:00.061Z]     nsd[b, c] = torch.nan
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_nans_0 (tests.test_hausdorff_distance.TestHausdorffDistance)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func
[2023-10-05T00:02:00.061Z]     return func(*(a + p.args), **p.kwargs, **kw)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_hausdorff_distance.py", line 201, in test_nans
[2023-10-05T00:02:00.061Z]     hd_metric(batch_seg_1, batch_seg_2, spacing=spacing)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.061Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 107, in _compute_tensor
[2023-10-05T00:02:00.061Z]     return compute_hausdorff_distance(
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in compute_hausdorff_distance
[2023-10-05T00:02:00.061Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in <listcomp>
[2023-10-05T00:02:00.061Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 211, in _compute_percentile_hausdorff_distance
[2023-10-05T00:02:00.061Z]     return torch.tensor(torch.nan, dtype=torch.float, device=surface_distance.device)
[2023-10-05T00:02:00.061Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.061Z] 
[2023-10-05T00:02:00.061Z] ======================================================================
[2023-10-05T00:02:00.061Z] ERROR: test_nans_1 (tests.test_hausdorff_distance.TestHausdorffDistance)
[2023-10-05T00:02:00.061Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.061Z] Traceback (most recent call last):
[2023-10-05T00:02:00.061Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func
[2023-10-05T00:02:00.061Z]     return func(*(a + p.args), **p.kwargs, **kw)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_hausdorff_distance.py", line 201, in test_nans
[2023-10-05T00:02:00.061Z]     hd_metric(batch_seg_1, batch_seg_2, spacing=spacing)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.061Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.061Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.062Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 107, in _compute_tensor
[2023-10-05T00:02:00.062Z]     return compute_hausdorff_distance(
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in compute_hausdorff_distance
[2023-10-05T00:02:00.062Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in <listcomp>
[2023-10-05T00:02:00.062Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 211, in _compute_percentile_hausdorff_distance
[2023-10-05T00:02:00.062Z]     return torch.tensor(torch.nan, dtype=torch.float, device=surface_distance.device)
[2023-10-05T00:02:00.062Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.062Z] 
[2023-10-05T00:02:00.062Z] ======================================================================
[2023-10-05T00:02:00.062Z] ERROR: test_compute (tests.test_handler_hausdorff_distance.TestHandlerHausdorffDistance)
[2023-10-05T00:02:00.062Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.062Z] Traceback (most recent call last):
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_handler_hausdorff_distance.py", line 84, in test_compute
[2023-10-05T00:02:00.062Z]     hd_metric.update([y_pred, y])
[2023-10-05T00:02:00.062Z]   File "/opt/conda/lib/python3.8/site-packages/ignite/metrics/metric.py", line 607, in wrapper
[2023-10-05T00:02:00.062Z]     func(self, *args, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/handlers/ignite_metric.py", line 112, in update
[2023-10-05T00:02:00.062Z]     self.metric_fn(y_pred, y)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.062Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.062Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 107, in _compute_tensor
[2023-10-05T00:02:00.062Z]     return compute_hausdorff_distance(
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in compute_hausdorff_distance
[2023-10-05T00:02:00.062Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 196, in <listcomp>
[2023-10-05T00:02:00.062Z]     percentile_distances = [_compute_percentile_hausdorff_distance(d, percentile) for d in distances]
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/hausdorff_distance.py", line 211, in _compute_percentile_hausdorff_distance
[2023-10-05T00:02:00.062Z]     return torch.tensor(torch.nan, dtype=torch.float, device=surface_distance.device)
[2023-10-05T00:02:00.062Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.062Z] 
[2023-10-05T00:02:00.062Z] ======================================================================
[2023-10-05T00:02:00.062Z] ERROR: test_compute (tests.test_handler_surface_distance.TestHandlerSurfaceDistance)
[2023-10-05T00:02:00.062Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.062Z] Traceback (most recent call last):
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_handler_surface_distance.py", line 84, in test_compute
[2023-10-05T00:02:00.062Z]     sur_metric.update([y_pred, y])
[2023-10-05T00:02:00.062Z]   File "/opt/conda/lib/python3.8/site-packages/ignite/metrics/metric.py", line 607, in wrapper
[2023-10-05T00:02:00.062Z]     func(self, *args, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/handlers/ignite_metric.py", line 112, in update
[2023-10-05T00:02:00.062Z]     self.metric_fn(y_pred, y)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.062Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 77, in __call__
[2023-10-05T00:02:00.062Z]     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_distance.py", line 93, in _compute_tensor
[2023-10-05T00:02:00.062Z]     return compute_average_surface_distance(
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_distance.py", line 184, in compute_average_surface_distance
[2023-10-05T00:02:00.062Z]     asd[b, c] = torch.nan if surface_distance.shape == (0,) else surface_distance.mean()
[2023-10-05T00:02:00.062Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.062Z] 
[2023-10-05T00:02:00.062Z] ======================================================================
[2023-10-05T00:02:00.062Z] ERROR: test_nans_0 (tests.test_surface_distance.TestAllSurfaceMetrics)
[2023-10-05T00:02:00.062Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.062Z] Traceback (most recent call last):
[2023-10-05T00:02:00.062Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func
[2023-10-05T00:02:00.062Z]     return func(*(a + p.args), **p.kwargs, **kw)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_surface_distance.py", line 178, in test_nans
[2023-10-05T00:02:00.062Z]     sur_metric(batch_seg_1, batch_seg_2, spacing=spacing)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 344, in __call__
[2023-10-05T00:02:00.062Z]     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 73, in __call__
[2023-10-05T00:02:00.062Z]     return self._compute_list(y_pred, y, **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 97, in _compute_list
[2023-10-05T00:02:00.062Z]     ret = [
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/metric.py", line 98, in <listcomp>
[2023-10-05T00:02:00.062Z]     self._compute_tensor(p.detach().unsqueeze(0), y_.detach().unsqueeze(0), **kwargs)
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_distance.py", line 93, in _compute_tensor
[2023-10-05T00:02:00.062Z]     return compute_average_surface_distance(
[2023-10-05T00:02:00.062Z]   File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/metrics/surface_distance.py", line 184, in compute_average_surface_distance
[2023-10-05T00:02:00.062Z]     asd[b, c] = torch.nan if surface_distance.shape == (0,) else surface_distance.mean()
[2023-10-05T00:02:00.062Z] AttributeError: module 'torch' has no attribute 'nan'
[2023-10-05T00:02:00.062Z] 
[2023-10-05T00:02:00.062Z] ======================================================================
[2023-10-05T00:02:00.062Z] ERROR: test_nans_1 (tests.test_surface_distance.TestAllSurfaceMetrics)
[2023-10-05T00:02:00.062Z] ----------------------------------------------------------------------
[2023-10-05T00:02:00.062Z] 
```


Discussion:

Resolving patch:
diff --git a/monai/metrics/hausdorff_distance.py b/monai/metrics/hausdorff_distance.py
--- a/monai/metrics/hausdorff_distance.py
+++ b/monai/metrics/hausdorff_distance.py
@@ -208,7 +208,7 @@ def _compute_percentile_hausdorff_distance(
 
     # for both pred and gt do not have foreground
     if surface_distance.shape == (0,):
-        return torch.tensor(torch.nan, dtype=torch.float, device=surface_distance.device)
+        return torch.tensor(np.nan, dtype=torch.float, device=surface_distance.device)
 
     if not percentile:
         return surface_distance.max()
diff --git a/monai/metrics/surface_dice.py b/monai/metrics/surface_dice.py
--- a/monai/metrics/surface_dice.py
+++ b/monai/metrics/surface_dice.py
@@ -275,7 +275,7 @@ def compute_surface_dice(
             boundary_correct = gt_true + pred_true
         if boundary_complete == 0:
             # the class is neither present in the prediction, nor in the reference segmentation
-            nsd[b, c] = torch.nan
+            nsd[b, c] = torch.tensor(np.nan)
         else:
             nsd[b, c] = boundary_correct / boundary_complete
 
diff --git a/monai/metrics/surface_distance.py b/monai/metrics/surface_distance.py
--- a/monai/metrics/surface_distance.py
+++ b/monai/metrics/surface_distance.py
@@ -181,6 +181,6 @@ def compute_average_surface_distance(
             class_index=c,
         )
         surface_distance = torch.cat(distances)
-        asd[b, c] = torch.nan if surface_distance.shape == (0,) else surface_distance.mean()
+        asd[b, c] = torch.tensor(np.nan) if surface_distance.shape == (0,) else surface_distance.mean()
 
     return convert_data_type(asd, output_type=torch.Tensor, device=y_pred.device, dtype=torch.float)[0]


Test patch: