code: def learning_rate_factor(name, step_num, hparams):
      """Compute the designated learning rate factor from hparams."""
      if name == "constant":
          tf.logging.info(
              "Base learning rate: %f", hparams.learning_rate_constant
          )
          return hparams.learning_rate_constant
      elif name == "linear_warmup":
          return tf.minimum(
              1.0, step_num / hparams.learning_rate_warmup_steps
          )
      elif name == "linear_decay":
          ret = (
              hparams.train_steps - step_num
          ) / hparams.learning_rate_decay_steps
          return tf.minimum(1.0, tf.maximum(0.0, ret))
      elif name == "cosdecay":  # openai gpt
          in_warmup = tf.cast(
              step_num <= hparams.learning_rate_warmup_steps,
              dtype=tf.float32,
          )
          ret = 0.5 * (
              1
              + tf.cos(
                  np.pi * step_num / hparams.learning_rate_decay_steps
              )
          )
          # if in warmup stage return 1 else return the decayed value
          return in_warmup * 1 + (1 - in_warmup) * ret
      elif name == "single_cycle_cos_decay":
          # Cosine decay to zero with a single cycle. This is different from
          # "cosdecay" because it starts at 1 when the warmup steps end.
          x = tf.maximum(step_num, hparams.learning_rate_warmup_steps)
          step = x - hparams.learning_rate_warmup_steps
          if hparams.train_steps <= hparams.learning_rate_warmup_steps:
              raise ValueError(
                  "single_cycle_cos_decay cannot be used unless "
                  "hparams.train_steps > "
                  "hparams.learning_rate_warmup_steps"
              )
          return (
              tf.math.cos(
                  step
                  * np.pi
                  / (
                      hparams.train_steps
                      - hparams.learning_rate_warmup_steps
                  )
              )
              / 2.0
              + 0.5
          )
      elif name == "multi_cycle_cos_decay":
          # Cosine decay with a variable number of cycles. This is different from
          # "cosdecay" because it starts at 1 when the warmup steps end. Use
          # hparams.learning_rate_decay_steps to determine the number of cycles.
          x = tf.maximum(step_num, hparams.learning_rate_warmup_steps)
          step = x - hparams.learning_rate_warmup_steps
          return (
              tf.math.cos(
                  step * np.pi / hparams.learning_rate_decay_steps
              )
              / 2.0
              + 0.5
          )
      elif name == "rsqrt_decay":
          return tf.rsqrt(
              tf.maximum(step_num, hparams.learning_rate_warmup_steps)
          )
      elif name == "rsqrt_normalized_decay":
          scale = tf.sqrt(
              tf.to_float(hparams.learning_rate_warmup_steps)
          )
          return scale * tf.rsqrt(
              tf.maximum(step_num, hparams.learning_rate_warmup_steps)
          )
      elif name == "exp_decay":
          decay_steps = hparams.learning_rate_decay_steps
          warmup_steps = hparams.learning_rate_warmup_steps
          p = (step_num - warmup_steps) / decay_steps
          p = tf.maximum(p, 0.0)
          if hparams.learning_rate_decay_staircase:
              p = tf.floor(p)
          return tf.pow(hparams.learning_rate_decay_rate, p)
      elif name == "rsqrt_hidden_size":
          return hparams.hidden_size**-0.5
      elif name == "legacy":
          return legacy_learning_rate_schedule(hparams)
      else:
          raise ValueError("unknown learning rate factor %s" % name)
  
file_path: tensor2tensor/tensor2tensor/utils/learning_rate.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  from tensor2tensor.utils import mlperf_log
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: learning_rate_factor(name, step_num, hparams) and returns: hparams, tf, tf, unknown, unknown, unknown, tf, unknown, tf, unknown, legacy_learning_rate_schedule