class_docstr: Set of common testing utils. It is meant to be subclassed by your test.
  See other tests as an example of how this is done.
  
  The objective of these tests is to make sure that our DP-friendly reimplementations of
  standard nn.Modules such as LSTM are indeed drop-in replacements: we are checking that all
  outputs and states are the same between the two implementations. Here, we do NOT test for
  grad_samples, which is something we do in the grad_sample tests.
class_docstr_tok: ["Set","of","common","testing","utils",".","It","is","meant","to","be","subclassed","by","your","test",".","See","other","tests","as","an","example","of","how","this","is","done",".","The","objective","of","these","tests","is","to","make","sure","that","our","DP-friendly","reimplementations","of","standard","nn.Modules","such","as","LSTM","are","indeed","drop-in","replacements",":","we","are","checking","that","all","outputs","and","states","are","the","same","between","the","two","implementations",".","Here",",","we","do","NOT","test","for","grad_samples",",","which","is","something","we","do","in","the","grad_sample","tests","."]
code: def _check_values(
      self,
      nn_outs: Tuple[Union[torch.Tensor, PackedSequence]],
      dp_outs: Tuple[Union[torch.Tensor, PackedSequence]],
      atol: float,
      rtol: float,
      output_names: Optional[Tuple[str]] = None,
      batch_first_nn: Optional[bool] = None,
      batch_first_dp: Optional[bool] = None,
  ) -> None:
      output_names = output_names or [None] * len(nn_outs)
      failed = []
      for i, (out_name, nn_out, dp_out) in enumerate(
          zip(output_names, nn_outs, dp_outs)
      ):
          name = f"'{out_name}'" or f"#{i}"
  
          if isinstance(nn_out, PackedSequence):
              self._check_packed_sequence(
                  name,
                  nn_out,
                  dp_out,
                  batch_first_nn,
                  batch_first_dp,
                  atol,
                  rtol,
                  failed,
              )
              continue
  
          msg = (
              f"Output {name}: DP module L2 norm = : {dp_out.norm(2)}, ",
              f"Reference nn.Module L2 norm = : {nn_out.norm(2)}, ",
              f"MSE = {F.mse_loss(dp_out, nn_out)}, ",
              f"L1 Loss = {F.l1_loss(dp_out, nn_out)}",
          )
          try:
              assert_close(
                  actual=dp_out,
                  expected=nn_out,
                  atol=atol,
                  rtol=rtol,
              )
          except AssertionError:
              failed.append(msg)
      if failed:
          failed_str = "\n\t".join(
              f"{i}. {s}" for i, s in enumerate(failed, 1)
          )
          raise AssertionError(
              f"A total of {len(failed)} values do not match:\n\t{failed_str}"
          )
  
file_path: opacus/opacus/tests/dp_layers/common.py
imports: import io
  import unittest
  from typing import Callable, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.utils.rnn import PackedSequence, pad_packed_sequence
  from torch.testing import assert_close
label_desc: Use image node_id 4 for calling the DPModules_test obj's underlying member method code with example usage: obj._check_values(nn_outs, dp_outs, atol, rtol, output_names, batch_first_nn, batch_first_dp) without return types