class_docstr: Adam with SGD updates every n steps with accumulated gradients.
class_docstr_tok: ["Adam","with","SGD","updates","every","n","steps","with","accumulated","gradients","."]
docstr: Apply conditionally if counter is zero.
docstr_tok: ["Apply","conditionally","if","counter","is","zero","."]
code: def _apply_cond(self, apply_fn, grad, var, *args, **kwargs):
      """Apply conditionally if counter is zero."""
      grad_acc = self.get_slot(var, "grad_acc")
  
      def apply_adam(grad_acc, apply_fn, grad, var, *args, **kwargs):
          total_grad = (grad_acc + grad) / tf.cast(
              self._n_t, grad.dtype
          )
          adam_op = apply_fn(total_grad, var, *args, **kwargs)
          with tf.control_dependencies([adam_op]):
              grad_acc_to_zero_op = grad_acc.assign(
                  tf.zeros_like(grad_acc), use_locking=self._use_locking
              )
          return tf.group(adam_op, grad_acc_to_zero_op)
  
      def accumulate_gradient(grad_acc, grad):
          assign_op = tf.assign_add(
              grad_acc, grad, use_locking=self._use_locking
          )
          return tf.group(assign_op)  # Strip return value
  
      return tf.cond(
          tf.equal(self._get_iter_variable(), 0),
          lambda: apply_adam(
              grad_acc, apply_fn, grad, var, *args, **kwargs
          ),
          lambda: accumulate_gradient(grad_acc, grad),
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow.compat.v1
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.training import training_ops
label_desc: Use image node_id 6 for calling the MultistepAdamOptimizer obj's underlying member method code with example usage: obj._apply_cond(apply_fn, grad, var) and returns: tf, tf, tf