class_docstr: Test case for the patch module.
class_docstr_tok: ["Test","case","for","the","patch","module","."]
code: def testUnrollSGD(self, _, model_builder):
      model = model_builder(self)
      mask = _get_used_params_mask(model, torch.rand(8, 4))
      fmodel = higher.patch.monkeypatch(model)
      for _ in range(10):
          inputs = torch.rand(8, 4)
          loss = fmodel(inputs).sum().pow(2)
          grads = torch.autograd.grad(
              loss,
              fmodel.parameters(),
              allow_unused=True,
              create_graph=True,
          )
          fmodel.fast_params = [
              p - self.lr * g if g is not None else p
              for p, g in zip(fmodel.parameters(), grads)
          ]
      loss = fmodel(torch.rand(8, 4)).sum().pow(2)
      used_params = (
          p for p, g in zip(fmodel.parameters(time=0), mask) if g
      )
      final_grads = torch.autograd.grad(loss, used_params)
      for grad in final_grads:
          self.assertIsNotNone(grad)
  
imports: import unittest
  from parameterized import parameterized
  import torch
  from torch import nn
  import higher
label_desc: Use image node_id 6 for calling the TestPatch obj's underlying member method code with example usage: obj.testUnrollSGD(_, model_builder) without return types