code: def predict_target_lengths(
      encoder_output, inputs_mask, hparams, length_diff=None
  ):
      """Predict target lengths."""
      bound = hparams.lendiff_bound
      inputs_length = tf.cast(tf.reduce_sum(inputs_mask, 1), tf.int32)
      targets_length = inputs_length
      loss = None
      if hparams.predict_target_length:
          encoder_output = gops.reduce_mean_over_l(
              encoder_output, inputs_mask
          )
          logits = tf.stop_gradient(encoder_output)
          logits = lenpred_mlp(
              "lenpred", logits, hparams.hidden_size, bound
          )
          if length_diff is not None:
              labels = tf.maximum(
                  tf.minimum(length_diff, bound), -bound
              )
              labels = tf.cast(labels + bound, tf.int32)
              labels = tf.stop_gradient(labels)
              loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
                  labels=labels, logits=logits
              )
              loss = tf.reduce_mean(loss)
          diff_pred = tf.argmax(logits, 1)
          diff_pred = tf.cast(diff_pred - bound, tf.int32)
          targets_length = inputs_length + diff_pred
          targets_length = tf.maximum(targets_length, 1)
      divi = 4
      targets_length = tf.ceil(targets_length / divi) * divi
      targets_length = tf.cast(targets_length, tf.int32)
      return targets_length, loss
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from six.moves import range
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import transformer_glow_layers_ops
  from tensor2tensor.models.transformer import transformer_decoder_layer
  from tensor2tensor.models.transformer import transformer_encoder
  from tensor2tensor.models.transformer import transformer_prepare_encoder
  from tensor2tensor.utils import learning_rate
  from tensor2tensor.utils import mlperf_log
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 12 for calling a global function with example usage: predict_target_lengths(encoder_output, inputs_mask, hparams, length_diff) and returns: targets_length,  loss