code: def _compute(self):
      device = (
          f"cuda:{dist.get_rank()}"
          if torch.cuda.is_available()
          else "cpu"
      )
      metric = ConfusionMatrix(
          include_background=True, metric_name="tpr"
      )
  
      def _val_func(engine, batch):
          pass
  
      engine = Engine(_val_func)
      metric.attach(engine, "confusion_matrix")
      if dist.get_rank() == 0:
          y_pred = torch.tensor(
              [
                  [
                      [[0.0, 1.0], [0.0, 0.0]],
                      [[0.0, 0.0], [1.0, 1.0]],
                      [[1.0, 0.0], [0.0, 0.0]],
                  ],
                  [
                      [[0.0, 0.0], [0.0, 1.0]],
                      [[1.0, 0.0], [0.0, 0.0]],
                      [[0.0, 1.0], [1.0, 0.0]],
                  ],
              ],
              device=device,
          )
          y = torch.tensor(
              [
                  [
                      [[0.0, 1.0], [0.0, 0.0]],
                      [[0.0, 0.0], [1.0, 1.0]],
                      [[1.0, 0.0], [0.0, 0.0]],
                  ],
                  [
                      [[0.0, 0.0], [0.0, 1.0]],
                      [[1.0, 0.0], [0.0, 0.0]],
                      [[0.0, 1.0], [1.0, 0.0]],
                  ],
              ],
              device=device,
          )
          metric.update([y_pred, y])
  
      if dist.get_rank() == 1:
          y_pred = torch.tensor(
              [
                  [
                      [[0.0, 1.0], [1.0, 0.0]],
                      [[1.0, 0.0], [1.0, 1.0]],
                      [[0.0, 1.0], [0.0, 0.0]],
                  ]
              ],
              device=device,
          )
          y = torch.tensor(
              [
                  [
                      [[1.0, 1.0], [1.0, 1.0]],
                      [[1.0, 1.0], [1.0, 1.0]],
                      [[1.0, 1.0], [1.0, 1.0]],
                  ]
              ],
              device=device,
          )
          metric.update([y_pred, y])
  
      avg_metric = metric.compute()
      np.testing.assert_allclose(
          avg_metric, 0.7, rtol=1e-04, atol=1e-04
      )
  
file_path: MONAI/tests/test_handler_confusion_matrix_dist.py
imports: from __future__ import annotations
  import unittest
  import numpy
  import torch
  import torch.distributed
  from ignite.engine import Engine
  from monai.handlers import ConfusionMatrix
  from tests.utils import DistCall, DistTestCase
label_desc: Use image node_id 2 for calling the DistributedConfusionMatrix obj's underlying member method code with example usage: obj._compute() without return types