docstr: Test if PrivateGradValues without clipping / noise is the same as non-private GradValues.
docstr_tok: ["Test","if","PrivateGradValues","without","clipping","\/","noise","is","the","same","as","non-private","GradValues","."]
code: def test_private_gradvalues_compare_nonpriv(self):
      """Test if PrivateGradValues without clipping / noise is the same as non-private GradValues."""
      l2_norm_clip = 1e10
      noise_multiplier = 0
  
      for use_norm_accumulation in [True, False]:
          for microbatch in [1, 10, self.ntrain]:
              gv_priv = objax.Jit(
                  objax.privacy.dpsgd.PrivateGradValues(
                      self.loss,
                      self.model_vars,
                      noise_multiplier,
                      l2_norm_clip,
                      microbatch,
                      batch_axis=(0, 0),
                      use_norm_accumulation=use_norm_accumulation,
                  )
              )
              gv = objax.GradValues(self.loss, self.model_vars)
              g_priv, v_priv = gv_priv(self.data, self.labels)
              g, v = gv(self.data, self.labels)
  
              # Check the shape of the gradient.
              self.assertEqual(g_priv[0].shape, tuple([self.nclass]))
              self.assertEqual(
                  g_priv[1].shape, tuple([self.ndim, self.nclass])
              )
  
              # Check if the private gradient is similar to the non-private gradient.
              np.testing.assert_allclose(g[0], g_priv[0], atol=1e-7)
              np.testing.assert_allclose(g[1], g_priv[1], atol=1e-7)
              np.testing.assert_allclose(
                  v_priv[0],
                  self.loss(self.data, self.labels)[0],
                  atol=1e-7,
              )
  
imports: import inspect
  import unittest
  from typing import Tuple, Dict, List
  import jax
  import jax.numpy
  import numpy
  from scipy.stats.distributions import chi2
  import objax
  from objax.typing import JaxArray
  from objax.zoo.dnnet import DNNet
label_desc: Use image node_id 2 for calling the TestPrivateGradValues obj's underlying member method code with example usage: obj.test_private_gradvalues_compare_nonpriv() without return types