class_docstr: Decorator for specifying a list of optimizers over which to run a test.
class_docstr_tok: ["Decorator","for","specifying","a","list","of","optimizers","over","which","to","run","a","test","."]
code: def _parametrize_test(self, test, generic_cls, device_cls):
      if device_cls is None:
          raise RuntimeError(
              "The @optims decorator is only intended to be used in a device-specific "
              "context; use it with instantiate_device_type_tests() instead of "
              "instantiate_parametrized_tests()"
          )
  
      for optim_info, dtype in itertools.product(
          self.optim_info_list, self.dtypes
      ):
          # Construct the test name; device / dtype parts are handled outside.
          # See [Note: device and dtype suffix placement]
          test_name = optim_info.name
  
          # Construct parameter kwargs to pass to the test.
          param_kwargs = {"optim_info": optim_info, "dtype": dtype}
  
          try:
  
              @functools.wraps(test)
              def test_wrapper(*args, **kwargs):
                  return test(*args, **kwargs)
  
              decorator_fn = functools.partial(
                  optim_info.get_decorators,
                  generic_cls.__name__,
                  test.__name__,
                  device_cls.device_type,
                  dtype,
              )
  
              yield (
                  test_wrapper,
                  test_name,
                  param_kwargs,
                  decorator_fn,
              )
          except Exception as ex:
              # Provides an error message for debugging before rethrowing the exception
              print(
                  f"Failed to instantiate {test_name} for module {optim_info.name}!"
              )
              raise ex
  
imports: import functools
  import itertools
  import math
  import unittest
  from copy import deepcopy
  from enum import Enum
  from typing import Any, Dict, List, Tuple, Union
  import torch
  from torch import Tensor
  from torch.nn import Parameter
  from torch.optim import Adadelta, Adagrad, Adam, Adamax, AdamW, ASGD, LBFGS, NAdam, Optimizer, RAdam, RMSprop, Rprop, SGD, SparseAdam
  from torch.testing._internal.common_device_type import tol, toleranceOverride
  from torch.testing._internal.common_methods_invocations import DecorateInfo
  from torch.testing._internal.common_utils import _TestParametrizer, set_single_threaded_if_parallel_tbb, skipIfMps, skipIfTorchDynamo, TEST_WITH_TORCHDYNAMO
  from torch.utils._foreach_utils import _get_foreach_kernels_supported_devices, _get_fused_kernels_supported_devices
label_desc: Use image node_id 2 for calling the optims obj's underlying member method code with example usage: obj._parametrize_test(test, generic_cls, device_cls) and returns: test