code: def _assert_requires_grad(
      metric: Metric, pl_result: Any, key: Optional[str] = None
  ) -> None:
      if isinstance(pl_result, dict) and key is None:
          for res in pl_result.values():
              _core_assert_requires_grad(metric, res)
      else:
          _core_assert_requires_grad(metric, pl_result, key)
  
imports: import inspect
  from functools import partial
  from typing import Any, Callable, Dict, Optional
  from unittest import mock
  import numpy
  import pandas
  import pytest
  import torch
  from fairlearn.metrics import MetricFrame, selection_rate, true_positive_rate
  from scipy.special import expit
  from torch import Tensor
  from torchmetrics import Metric
  from torchmetrics.classification.group_fairness import BinaryFairness
  from torchmetrics.functional.classification.group_fairness import binary_fairness
  from torchmetrics.utilities.imports import _PYTHON_LOWER_3_8
  from unittests import THRESHOLD
  from unittests.classification.inputs import _group_cases
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester, _assert_dtype_support, inject_ignore_index, remove_ignore_index_groups
  from unittests.helpers.testers import _assert_allclose
  from unittests.helpers.testers import _assert_requires_grad
  from unittests.helpers.testers import _assert_tensor
label_desc: Use image node_id 4 for calling a global function with example usage: _assert_requires_grad(metric, pl_result, key) without return types