code: def adafactor_optimizer_from_hparams(hparams, lr):
      """Create an Adafactor optimizer based on model hparams.
  
      Args:
        hparams: model hyperparameters
        lr: learning rate scalar.
      Returns:
        an AdafactorOptimizer
      Raises:
        ValueError: on illegal values
      """
      if hparams.optimizer_adafactor_decay_type == "Adam":
          decay_rate = adafactor_decay_rate_adam(
              hparams.optimizer_adafactor_beta2
          )
      elif hparams.optimizer_adafactor_decay_type == "pow":
          decay_rate = adafactor_decay_rate_pow(
              hparams.optimizer_adafactor_memory_exponent
          )
      else:
          raise ValueError("unknown optimizer_adafactor_decay_type")
      return AdafactorOptimizer(
          multiply_by_parameter_scale=(
              hparams.optimizer_adafactor_multiply_by_parameter_scale
          ),
          learning_rate=lr,
          decay_rate=decay_rate,
          beta1=hparams.optimizer_adafactor_beta1,
          clipping_threshold=hparams.optimizer_adafactor_clipping_threshold,
          factored=hparams.optimizer_adafactor_factored,
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import re
  import gin
  from mesh_tensorflow import layers
  from mesh_tensorflow import ops_with_redefined_builtins
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling a global function with example usage: adafactor_optimizer_from_hparams(hparams, lr) and returns: AdafactorOptimizer