class_docstr: Test case for package-level functions for correctness.
class_docstr_tok: ["Test","case","for","package-level","functions","for","correctness","."]
docstr: Check if unrolled patched and reference nets produce same meta loss.
          
docstr_tok: ["Check","if","unrolled","patched","and","reference","nets","produce","same","meta","loss","."]
code: def testUnrollEqualityForward(self):
      """Check if unrolled patched and reference nets produce same meta loss."""
      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]
              ref_fast_weights = ref_out[1]
              ref_train_losses = ref_out[2]
              ref_train_grads = ref_out[3]
              target_meta_loss = target_out[0]
              target_fast_weights = target_out[1]
              target_train_losses = target_out[2]
              target_train_grads = target_out[3]
  
              # Check final losses match
              self.assertTrue(
                  torch.allclose(ref_meta_loss, target_meta_loss),
                  msg=(
                      "Ref ({}) and target ({}) metaloss differed on test_it "
                      "{} (mse {})"
                  ).format(
                      ref_meta_loss.item(),
                      target_meta_loss.item(),
                      test_it,
                      (ref_meta_loss - target_meta_loss).pow(2).item(),
                  ),
              )
  
              # Check that training losses align
              for rl, tl in zip(ref_train_losses, target_train_losses):
                  torch.testing.assert_allclose(rl, tl)
  
              # Check that fast weights align
              for rw, tw in zip(ref_fast_weights, target_fast_weights):
                  torch.testing.assert_allclose(rw, tw)
  
              # Check that grads align
              for rgs, tgs in zip(ref_train_grads, target_train_grads):
                  for rg, tg in zip(rgs, tgs):
                      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 5 for calling the TestCorrectness obj's underlying member method code with example usage: obj.testUnrollEqualityForward() without return types