class_docstr: Tester class for text.
  
  Class used for efficiently run a lot of parametrized tests in ddp mode. Makes sure that ddp is only setup once and
  that pool of processes are used for all tests. All tests for text metrics should subclass from this and implement
  a new method called `test_metric_name` where the method `self.run_metric_test` is called inside.
docstr: Core method that should be used for testing class. Call this inside testing methods.
  
  Args:
      ddp: bool, if running in ddp mode or not
      preds: torch tensor with predictions
      targets: torch tensor with targets
      metric_class: metric class that should be tested
      reference_metric: callable function that is used for comparison
      dist_sync_on_step: bool, if true will synchronize metric state across
          processes at each ``forward()``
      metric_args: dict with additional arguments used for class initialization
      check_dist_sync_on_step: bool, if true will check if the metric is also correctly
          calculated per batch per device (and not just at the end)
      check_batch: bool, if true will check if the metric is also correctly
          calculated across devices for each batch (and not just at the end)
      fragment_kwargs: whether tensors in kwargs should be divided as `preds` and `targets` among processes
      check_scriptable: bool indicating if metric should also be tested if it can be scripted
      key: The key passed onto the `_assert_allclose` to compare the respective metric from the Dict output
          against the ref_metric.
      ignore_order: Ignore order of prediction across processes when DDP is used.
      kwargs_update: Additional keyword arguments that will be passed with preds and
          targets when running update on the metric.
docstr_tok: ["Core","method","that","should","be","used","for","testing","class",".","Call","this","inside","testing","methods",".","Args",":","ddp",":","bool",",","if","running","in","ddp","mode","or","not","preds",":","torch","tensor","with","predictions","targets",":","torch","tensor","with","targets","metric_class",":","metric","class","that","should","be","tested","reference_metric",":","callable","function","that","is","used","for","comparison","dist_sync_on_step",":","bool",",","if","true","will","synchronize","metric","state","across","processes","at","each","``","forward","(",")","``","metric_args",":","dict","with","additional","arguments","used","for","class","initialization","check_dist_sync_on_step",":","bool",",","if","true","will","check","if","the","metric","is","also","correctly","calculated","per","batch","per","device","(","and","not","just","at","the","end",")","check_batch",":","bool",",","if","true","will","check","if","the","metric","is","also","correctly","calculated","across","devices","for","each","batch","(","and","not","just","at","the","end",")","fragment_kwargs",":","whether","tensors","in","kwargs","should","be","divided","as","`","preds","`","and","`","targets","`","among","processes","check_scriptable",":","bool","indicating","if","metric","should","also","be","tested","if","it","can","be","scripted","key",":","The","key","passed","onto","the","`","_assert_allclose","`","to","compare","the","respective","metric","from","the","Dict","output","against","the","ref_metric",".","ignore_order",":","Ignore","order","of","prediction","across","processes","when","DDP","is","used",".","kwargs_update",":","Additional","keyword","arguments","that","will","be","passed","with","preds","and","targets","when","running","update","on","the","metric","."]
code: def run_class_metric_test(
      self,
      ddp: bool,
      preds: TEXT_METRIC_INPUT,
      targets: TEXT_METRIC_INPUT,
      metric_class: Metric,
      reference_metric: Callable,
      dist_sync_on_step: bool = False,
      metric_args: Optional[dict] = None,
      check_dist_sync_on_step: bool = True,
      check_batch: bool = True,
      fragment_kwargs: bool = False,
      check_scriptable: bool = True,
      key: Optional[str] = None,
      ignore_order: Optional[bool] = None,
      **kwargs_update: Any,
  ):
      """Core method that should be used for testing class. Call this inside testing methods.
  
      Args:
          ddp: bool, if running in ddp mode or not
          preds: torch tensor with predictions
          targets: torch tensor with targets
          metric_class: metric class that should be tested
          reference_metric: callable function that is used for comparison
          dist_sync_on_step: bool, if true will synchronize metric state across
              processes at each ``forward()``
          metric_args: dict with additional arguments used for class initialization
          check_dist_sync_on_step: bool, if true will check if the metric is also correctly
              calculated per batch per device (and not just at the end)
          check_batch: bool, if true will check if the metric is also correctly
              calculated across devices for each batch (and not just at the end)
          fragment_kwargs: whether tensors in kwargs should be divided as `preds` and `targets` among processes
          check_scriptable: bool indicating if metric should also be tested if it can be scripted
          key: The key passed onto the `_assert_allclose` to compare the respective metric from the Dict output
              against the ref_metric.
          ignore_order: Ignore order of prediction across processes when DDP is used.
          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 = {}
      if ddp:
          if sys.platform == "win32":
              pytest.skip("DDP not supported on windows")
  
          pytest.pool.starmap(
              partial(
                  _class_test,
                  preds=preds,
                  targets=targets,
                  metric_class=metric_class,
                  ref_metric=reference_metric,
                  dist_sync_on_step=dist_sync_on_step,
                  metric_args=metric_args,
                  check_dist_sync_on_step=check_dist_sync_on_step,
                  check_batch=check_batch,
                  atol=self.atol,
                  fragment_kwargs=fragment_kwargs,
                  check_scriptable=check_scriptable,
                  key=key,
                  ignore_order=ignore_order,
                  **kwargs_update,
              ),
              [(rank, NUM_PROCESSES) for rank in range(NUM_PROCESSES)],
          )
      else:
          device = (
              "cuda"
              if (
                  torch.cuda.is_available()
                  and torch.cuda.device_count() > 0
              )
              else "cpu"
          )
  
          _class_test(
              rank=0,
              worldsize=1,
              preds=preds,
              targets=targets,
              metric_class=metric_class,
              ref_metric=reference_metric,
              dist_sync_on_step=dist_sync_on_step,
              metric_args=metric_args,
              check_dist_sync_on_step=check_dist_sync_on_step,
              check_batch=check_batch,
              atol=self.atol,
              device=device,
              fragment_kwargs=fragment_kwargs,
              check_scriptable=check_scriptable,
              key=key,
              **kwargs_update,
          )
  
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 2 for calling the TextTester obj's underlying member method code with example usage: obj.run_class_metric_test(ddp, preds, targets, metric_class, reference_metric, dist_sync_on_step, metric_args, check_dist_sync_on_step, check_batch, fragment_kwargs, check_scriptable, key, ignore_order) without return types