code: def get_train_op(
      loss,
      variables=None,
      optimizer=None,
      learning_rate=None,
      global_step=None,
      increment_global_step=True,
      hparams=None,
  ):
      """Creates a training op.
  
      This is a wrapper of :tf_main:`tf.contrib.layers.optimize_loss
      <contrib/layers/optimize_loss>`.
  
      Args:
          loss: A scalar Tensor representing the loss to minimize.
          variables (optional): A list of Variables to optimize. If
              `None`, all trainable variables are used.
          optimizer (optional): An tf.train.Optimizer instance. If `None`,
              use the setting in `hparams` to create the optimizer.
          learning_rate (float or Tensor, optional): If `None`, learning rate
              specified in :attr:`hparams`, or the default learning rate
              of the optimizer will be used (if exists).
          global_step (optional): A scalar int Tensor. Step counter to update on
              each step unless :attr:`increment_global_step` is `False`.
              Learning rate decay uses :attr:`global_step`.
              If `None`, it will be fetched from the default graph (see
              :tf_main:`tf.train.get_global_step <train/get_global_step>` for
              more details). If it has not been created, no step will be
              incremented with each weight update.
          increment_global_step (bool): Whether to increment
              :attr:`global_step`. This is useful if the :attr:`global_step` is
              used in multiple training ops per training step (e.g. to optimize
              different parts of the model) to avoid incrementing
              :attr:`global_step` more times than necessary.
          hparams (dict or HParams, optional): hyperparameters. Missing
              hyperparameters are set to default values automatically. See
              :func:`~texar.tf.core.default_optimization_hparams` for
              all hyperparameters and default values.
  
      Returns:
          train_op: the operator used for variables optimization.
      """
      hparams = HParams(hparams, default_optimization_hparams())
      grad_clip_fn = get_gradient_clip_fn(hparams["gradient_clip"])
  
      if not isinstance(optimizer, tf.train.Optimizer):
          opt_hparams = hparams["optimizer"]
          optimizer_fn, optimizer_class = get_optimizer_fn(opt_hparams)
          learning_rate = _get_static_lr(
              learning_rate, optimizer_class, hparams
          )
          lr_decay_fn = get_learning_rate_decay_fn(
              hparams["learning_rate_decay"]
          )
          train_op = tf.contrib.layers.optimize_loss(
              loss=loss,
              global_step=global_step,
              learning_rate=learning_rate,
              optimizer=optimizer_fn,
              gradient_noise_scale=hparams["gradient_noise_scale"],
              clip_gradients=grad_clip_fn,
              learning_rate_decay_fn=lr_decay_fn,
              variables=variables,
              name=hparams["name"],
              increment_global_step=increment_global_step,
          )
  
      else:
          train_op = tf.contrib.layers.optimize_loss(
              loss=loss,
              global_step=global_step,
              learning_rate=None,
              optimizer=optimizer,
              gradient_noise_scale=hparams["gradient_noise_scale"],
              clip_gradients=grad_clip_fn,
              variables=variables,
              name=hparams["name"],
              increment_global_step=increment_global_step,
          )
  
      return train_op
  
file_path: texar/texar/tf/core/optimization.py
imports: import re
  import tensorflow
  from texar.tf.hyperparams import HParams
  from texar.tf.utils import utils
label_desc: Use image node_id 7 for calling a global function with example usage: get_train_op(loss, variables, optimizer, learning_rate, global_step, increment_global_step, hparams) and returns: train_op