class_docstr: Test case for package-level functions for correctness.
class_docstr_tok: ["Test","case","for","package-level","functions","for","correctness","."]
docstr: Check if metagrads match for target/ref net.
docstr_tok: ["Check","if","metagrads","match","for","target\/ref","net","."]
code: def testUnrollEqualityBackward(self):
      """Check if metagrads match for target/ref net."""
      for test_it in range(5):
          with higher.innerloop_ctx(self.target_net, self.opt) as (
              fnet,
              diffopt,
          ):
              ref_out, target_out = self._joint_inner_loop(
                  fnet, diffopt=diffopt, num_steps=10
              )
              ref_meta_loss = ref_out[0]
              target_meta_loss = target_out[0]
  
              ref_metagrads = torch.autograd.grad(
                  ref_meta_loss, self.reference_net.parameters()
              )
              target_metagrads = torch.autograd.grad(
                  target_meta_loss, fnet.parameters(time=0)
              )
  
              # Check that metagrads align
              for rg, tg in zip(ref_metagrads, target_metagrads):
                  torch.testing.assert_allclose(rg, tg)
  
imports: import unittest
  import copy
  from collections import OrderedDict
  import numpy
  import torch
  from torch import nn, optim
  from torch.nn import functional
  import higher
label_desc: Use image node_id 6 for calling the TestCorrectness obj's underlying member method code with example usage: obj.testUnrollEqualityBackward() without return types