class_docstr: Test case for the optim module.
code: def testDiffOptGroupedParamLearnStepwise(
      self, _, model_builder, opt_builder, kwargs=None
  ):
      kwargs = {} if kwargs is None else kwargs
      lr = 0.1
      left_lr = 0.2
      model = model_builder(self)
      full_parameters = list(model.parameters())
      half = len(full_parameters) // 2
      left_parameters = full_parameters[:half]
      right_parameters = full_parameters[half:]
      param_groups = [
          {"params": left_parameters, "lr": left_lr},
          {"params": right_parameters},
      ]
      opt = opt_builder(param_groups, lr=lr, **kwargs)
  
      override = {
          "lr": [torch.tensor(0.3, requires_grad=True)],
          "betas": [
              (
                  torch.tensor(0.9, requires_grad=True),
                  torch.tensor(0.999, requires_grad=True),
              ),
              (
                  torch.tensor(0.8, requires_grad=True),
                  torch.tensor(0.888, requires_grad=True),
              ),
          ],
      }
      meta_params = higher.utils.flatten(override)
  
      for i in range(1):
          fmodel = higher.patch.monkeypatch(model)
          diffopt = higher.optim.get_diff_optim(
              opt, model.parameters(), fmodel, override=None
          )
          for j in range(3):
              x = torch.rand(10, 4)
              y_fmodel = fmodel(x)
              loss_fmodel = y_fmodel.pow(2).sum()
              diffopt.step(loss_fmodel, override=override)
          param_sum = sum(p.sum() for p in fmodel.parameters())
          for g in torch.autograd.grad(param_sum, meta_params):
              self.assertTrue(
                  torch.isfinite(g).all().item(),
                  "Nan or Inf found in hyperparameter gradients.",
              )
  
imports: import unittest
  import copy
  from parameterized import parameterized
  import torch
  from torch import nn, optim
  import higher
label_desc: Use image node_id 9 for calling the TestOptim obj's underlying member method code with example usage: obj.testDiffOptGroupedParamLearnStepwise(_, model_builder, opt_builder, kwargs) without return types