code: def _batch_clip_by_global_norm(
      vals: List[tf.Tensor],
      normalize: bool,
      l2_norm_clip: Optional[float],
  ) -> List[tf.Tensor]:
      """Batch clips by global norm with normalize option."""
      batch_global_norm = _batch_global_norm(vals)
      if l2_norm_clip is None:
          l2_norm_clip = 1.0
      clip_ratio = l2_norm_clip / tf.maximum(batch_global_norm, 1e-8)
      if not normalize:
          clip_ratio = tf.minimum(1.0, clip_ratio)
  
      def _expand_dims(e, v):
          new_shape = tf.concat(
              [
                  tf.shape(v)[0:1],
                  tf.ones_like(tf.shape(v), dtype=tf.int32)[:-1],
              ],
              axis=0,
          )
          return tf.reshape(e, new_shape)
  
      return [
          v * _expand_dims(tf.cast(clip_ratio, v.dtype), v)
          if v is not None
          else None
          for v in vals
      ]
  
imports: from typing import Any, Dict, List, Optional, Tuple, TypeVar, Union
  import tensorflow
  from tensorflow.python.ops.parallel_for import control_flow_ops
label_desc: Use image node_id 3 for calling a global function with example usage: _batch_clip_by_global_norm(vals, normalize, l2_norm_clip) and returns: unknown, tf