docstr: Test if the gradient norm is within l2_norm_clip.
docstr_tok: ["Test","if","the","gradient","norm","is","within","l2_norm_clip","."]
code: def test_private_gradvalues_clipping(self):
      """Test if the gradient norm is within l2_norm_clip."""
      noise_multiplier = 0
      acceptable_float_error = 1e-8
      for use_norm_accumulation in [True, False]:
          for microbatch in [1, 10, self.ntrain]:
              for l2_norm_clip in [0, 1e-2, 1e-1, 1.0]:
                  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,
                      )
                  )
                  g_priv, v_priv = gv_priv(self.data, self.labels)
                  # Get the actual squared norm of the gradient.
                  g_normsquared = sum([np.sum(g**2) for g in g_priv])
                  self.assertLessEqual(
                      g_normsquared,
                      l2_norm_clip**2 + acceptable_float_error,
                  )
                  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 3 for calling the TestPrivateGradValues obj's underlying member method code with example usage: obj.test_private_gradvalues_clipping() without return types