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