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: Test if a metric is differentiable or not.
  
  Args:
      preds: torch tensor with predictions
      targets: torch tensor with targets
      metric_module: the metric module to test
      metric_functional: the functional metric version to test
      metric_args: dict with additional arguments used for class initialization
      key: The key passed onto the `_assert_allclose` to compare the respective metric from the Dict output
          against the ref_metric.
docstr_tok: ["Test","if","a","metric","is","differentiable","or","not",".","Args",":","preds",":","torch","tensor","with","predictions","targets",":","torch","tensor","with","targets","metric_module",":","the","metric","module","to","test","metric_functional",":","the","functional","metric","version","to","test","metric_args",":","dict","with","additional","arguments","used","for","class","initialization","key",":","The","key","passed","onto","the","`","_assert_allclose","`","to","compare","the","respective","metric","from","the","Dict","output","against","the","ref_metric","."]
code: def run_differentiability_test(
      preds: TEXT_METRIC_INPUT,
      targets: TEXT_METRIC_INPUT,
      metric_module: Metric,
      metric_functional: Callable,
      metric_args: Optional[dict] = None,
      key: Optional[str] = None,
  ) -> None:
      """Test if a metric is differentiable or not.
  
      Args:
          preds: torch tensor with predictions
          targets: torch tensor with targets
          metric_module: the metric module to test
          metric_functional: the functional metric version to test
          metric_args: dict with additional arguments used for class initialization
          key: The key passed onto the `_assert_allclose` to compare the respective metric from the Dict output
              against the ref_metric.
  
      """
      metric_args = metric_args or {}
      # only floating point tensors can require grad
      metric = metric_module(**metric_args)
      out = metric(preds[0], targets[0])
  
      # Check if requires_grad matches is_differentiable attribute
      _assert_requires_grad(metric, out, key=key)
  
      if metric.is_differentiable:
          # check for numerical correctness
          assert torch.autograd.gradcheck(
              partial(metric_functional, **metric_args),
              (preds[0], targets[0]),
          )
  
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 5 for calling the TextTester obj's underlying member method code with example usage: obj.run_differentiability_test(preds, targets, metric_module, metric_functional, metric_args, key) without return types