code: def _functional_test(
      preds: TEXT_METRIC_INPUT,
      targets: TEXT_METRIC_INPUT,
      metric_functional: Callable,
      ref_metric: Callable,
      metric_args: Optional[dict] = None,
      atol: float = 1e-8,
      device: str = "cpu",
      fragment_kwargs: bool = False,
      key: Optional[str] = None,
      **kwargs_update: Any,
  ):
      """Comparison between functional metric and reference metric.
  
      Args:
          preds: torch tensor with predictions
          targets: torch tensor with targets
          metric_functional: metric functional that should be tested
          ref_metric: callable function that is used for comparison
          metric_args: dict with additional arguments used for class initialization
          atol: absolute tolerance used for comparison of results
          device: determine which device to run on, either 'cuda' or 'cpu'
          fragment_kwargs: whether tensors in kwargs should be divided as `preds` and `targets` among processes
          key: The key passed onto the `_assert_allclose` to compare the respective metric from the Dict output against
              the ref_metric.
          kwargs_update: Additional keyword arguments that will be passed with preds and
              targets when running update on the metric.
  
      """
      if not metric_args:
          metric_args = {}
  
      metric = partial(metric_functional, **metric_args)
  
      # Move to device
      kwargs_update = {
          k: v.to(device) if isinstance(v, Tensor) else v
          for k, v in kwargs_update.items()
      }
  
      for i in range(NUM_BATCHES):
          extra_kwargs = {
              k: v[i] if isinstance(v, Tensor) else v
              for k, v in kwargs_update.items()
          }
          tm_result = metric(preds[i], targets[i], **extra_kwargs)
  
          extra_kwargs = {
              k: v.cpu() if isinstance(v, Tensor) else v
              for k, v in (
                  extra_kwargs if fragment_kwargs else kwargs_update
              ).items()
          }
          sk_result = ref_metric(preds[i], targets[i], **extra_kwargs)
  
          # assert its the same
          _assert_allclose(tm_result, sk_result, atol=atol, key=key)
  
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 3 for calling a global function with example usage: _functional_test(preds, targets, metric_functional, ref_metric, metric_args, atol, device, fragment_kwargs, key) without return types