class_docstr: Class used for efficiently run alot 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 should subclass from this and implement a new method called
      `test_metric_name`
  where the method `self.run_metric_test` is called inside.
class_docstr_tok: ["Class","used","for","efficiently","run","alot","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","should","subclass","from","this","and","implement","a","new","method","called","`","test_metric_name","`","where","the","method","`","self.run_metric_test","`","is","called","inside","."]
docstr: Main 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
      target: torch tensor with targets
      metric_class: lightning metric class that should be tested
      sk_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)
docstr_tok: ["Main","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","target",":","torch","tensor","with","targets","metric_class",":","lightning","metric","class","that","should","be","tested","sk_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",")"]
code: def run_class_metric_test(
      self,
      ddp: bool,
      preds: torch.Tensor,
      target: torch.Tensor,
      metric_class: Metric,
      sk_metric: Callable,
      dist_sync_on_step: bool,
      metric_args: dict = {},
      check_dist_sync_on_step: bool = True,
      check_batch: bool = True,
  ):
      """Main 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
          target: torch tensor with targets
          metric_class: lightning metric class that should be tested
          sk_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)
      """
      if ddp:
          if sys.platform == "win32":
              pytest.skip("DDP not supported on windows")
  
          self.pool.starmap(
              partial(
                  _class_test,
                  preds=preds,
                  target=target,
                  metric_class=metric_class,
                  sk_metric=sk_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,
              ),
              [(rank, self.poolSize) for rank in range(self.poolSize)],
          )
      else:
          _class_test(
              0,
              1,
              preds=preds,
              target=target,
              metric_class=metric_class,
              sk_metric=sk_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,
          )
  
imports: import os
  import pickle
  import sys
  from functools import partial
  from typing import Callable, Optional
  import numpy
  import pytest
  import torch
  from scipy.stats import entropy
  from torch.distributions.utils import logits_to_probs
  from torch.multiprocessing import Pool, set_start_method
  from torchmetrics import Metric
  from nemo.collections.common.metrics import GlobalAverageLossMetric, Perplexity
label_desc: Use image node_id 4 for calling the MetricTester obj's underlying member method code with example usage: obj.run_class_metric_test(ddp, preds, target, metric_class, sk_metric, dist_sync_on_step, metric_args, check_dist_sync_on_step, check_batch) without return types