code: def get_computed_and_true_norms(
      model_generator: type_aliases.ModelGenerator,
      layer_generator: type_aliases.LayerGenerator,
      input_dims: Sequence[int],
      output_dims: Sequence[int],
      per_example_loss_fn: Optional[
          Callable[[tf.Tensor, tf.Tensor], tf.Tensor]
      ],
      num_microbatches: Optional[int],
      is_eager: bool,
      x_batch: tf.Tensor,
      weight_batch: Optional[tf.Tensor] = None,
      rng_seed: int = 777,
      registry: layer_registry.LayerRegistry = None,
      partial: bool = False,
  ) -> tuple[tf.Tensor, tf.Tensor]:
      """Obtains the true and computed gradient norms for a model and batch input.
  
      Helpful testing wrapper function used to avoid code duplication.
  
      Args:
        model_generator: A function which takes in three arguments:
          `layer_generator`, `idim`, and `odim`. Returns a `tf.keras.Model` that
          accepts input tensors of dimension `idim` and returns output tensors of
          dimension `odim`. Layers of the model are based on the `layer_generator`
          (see below for its description).
        layer_generator: A function which takes in two arguments: `idim` and `odim`.
          Returns a `tf.keras.layers.Layer` that accepts input tensors of dimension
          `idim` and returns output tensors of dimension `odim`.
        input_dims: The input dimension(s) of the test `tf.keras.Model` instance.
        output_dims: The output dimension(s) of the test `tf.keras.Model` instance.
        per_example_loss_fn: If not None, used as vectorized per example loss
          function.
        num_microbatches: The number of microbatches. None or an integer.
        is_eager: whether the model should be run eagerly.
        x_batch: inputs to be tested.
        weight_batch: optional weights passed to the loss.
        rng_seed: used as a seed for random initialization.
        registry: required for fast clipping.
        partial: Whether to compute the gradient norm with respect to a partial set
          of varibles. If True, only consider the variables in the first layer.
  
      Returns:
        A `tuple` `(computed_norm, true_norms)`. The first element contains the
        clipped gradient norms that are generated by
        `clip_grads.compute_gradient_norms()` under the setting given by the given
        model and layer generators. The second element contains the true clipped
        gradient norms under the aforementioned setting.
      """
      model = get_model_from_generator(
          model_generator=model_generator,
          layer_generator=layer_generator,
          input_dims=input_dims,
          output_dims=output_dims,
          is_eager=is_eager,
      )
      return get_computed_and_true_norms_from_model(
          model=model,
          per_example_loss_fn=per_example_loss_fn,
          num_microbatches=num_microbatches,
          x_batch=x_batch,
          weight_batch=weight_batch,
          rng_seed=rng_seed,
          registry=registry,
          partial=partial,
      )
  
imports: from collections.abc import Callable, MutableSequence, Sequence
  from typing import Optional
  import numpy
  import tensorflow
  import tensorflow.compat.v2
  from tensorflow_privacy.privacy.fast_gradient_clipping import clip_grads
  from tensorflow_privacy.privacy.fast_gradient_clipping import layer_registry
  from tensorflow_privacy.privacy.fast_gradient_clipping import type_aliases
label_desc: Use image node_id 8 for calling a global function with example usage: get_computed_and_true_norms(model_generator, layer_generator, input_dims, output_dims, per_example_loss_fn, num_microbatches, is_eager, x_batch, weight_batch, rng_seed, registry, partial) and returns: get_computed_and_true_norms_from_model