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
      probs: torch tensor with probabilities.
      logits: torch tensor with logits. This test checks that probs and logits are mutually exclusive for
          ``Perplexity`` metric.
      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","probs",":","torch","tensor","with","probabilities",".","logits",":","torch","tensor","with","logits",".","This","test","checks","that","probs","and","logits","are","mutually","exclusive","for","``","Perplexity","``","metric",".","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_perplexity_test(
      self,
      ddp: bool,
      probs: Optional[torch.Tensor],
      logits: Optional[torch.Tensor],
      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
          probs: torch tensor with probabilities.
          logits: torch tensor with logits. This test checks that probs and logits are mutually exclusive for
              ``Perplexity`` metric.
          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(
                  _perplexity_class_test,
                  probs=probs,
                  logits=logits,
                  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:
          _perplexity_class_test(
              0,
              1,
              probs=probs,
              logits=logits,
              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 1 for calling the PerplexityTester obj's underlying member method code with example usage: obj.run_class_perplexity_test(ddp, probs, logits, dist_sync_on_step, metric_args, check_dist_sync_on_step, check_batch) without return types