code: def _assert_all_close_regardless_of_order(
      pl_result: Any,
      sk_result: Any,
      atol: float = 1e-8,
      key: Optional[str] = None,
  ) -> None:
      """Recursively asserting that two results are within a certain tolerance regardless of the order."""
      # single output compare
      if isinstance(pl_result, Tensor):
          assert np.allclose(
              pl_result.detach().cpu().numpy().mean(-1),
              sk_result.mean(-1),
              atol=atol,
              equal_nan=True,
          )
      # multi output compare
      elif isinstance(pl_result, Sequence):
          for pl_res, sk_res in zip(pl_result, sk_result):
              _assert_allclose(pl_res, sk_res, atol=atol)
      elif isinstance(pl_result, Dict):
          if key is None:
              raise KeyError(
                  "Provide Key for Dict based metric results."
              )
          assert np.allclose(
              pl_result[key].detach().cpu().numpy().mean(-1),
              sk_result.mean(-1),
              atol=atol,
              equal_nan=True,
          )
      else:
          raise ValueError("Unknown format for comparison")
  
imports: import pickle
  import sys
  from functools import partial, wraps
  from typing import Any, Callable, Dict, Optional, Sequence, Union
  import numpy
  import pytest
  import torch
  from torch import Tensor
  from torchmetrics import Metric
  from unittests import NUM_PROCESSES
  from unittests.helpers.testers import MetricTester, _assert_allclose, _assert_requires_grad, _assert_tensor
label_desc: Use image node_id 1 for calling a global function with example usage: _assert_all_close_regardless_of_order(pl_result, sk_result, atol, key) without return types