class_docstr: Test case for the patch module.
class_docstr_tok: ["Test","case","for","the","patch","module","."]
code: def testRNNCellUnrollSGD(self, _, cell_constructor, output_selector):
      num_layers = 2
      hidden_size = 20
      num_feats = 10
  
      batch_size = 3
      seq_length = 5
  
      for _ in range(10):
          cell = cell_constructor(num_feats, hidden_size, num_layers)
          fcell = higher.patch.monkeypatch(cell)
  
          state = None
          for _ in range(seq_length):
              inputs = torch.randn(batch_size, num_feats)
              state = fcell(inputs, state)
  
          output = output_selector(state)
          loss = output.sum().pow(2)
          grads = torch.autograd.grad(
              loss,
              fcell.parameters(),
              allow_unused=True,
              create_graph=True,
          )
          fcell.fast_params = [
              p - self.lr * g if g is not None else p
              for p, g in zip(fcell.parameters(), grads)
          ]
          final_inputs = torch.randn(batch_size, num_feats)
          final_loss = (
              output_selector(fcell(final_inputs, state)).sum().pow(2)
          )
          final_grads = torch.autograd.grad(
              final_loss, fcell.parameters(time=0)
          )
          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 11 for calling the TestPatch obj's underlying member method code with example usage: obj.testRNNCellUnrollSGD(_, cell_constructor, output_selector) without return types