class_docstr: Simplified version of tf.train.AdamOptimizer that behaves identically when used with dnnlib.tflib.Optimizer.
class_docstr_tok: ["Simplified","version","of","tf.train.AdamOptimizer","that","behaves","identically","when","used","with","dnnlib.tflib.Optimizer","."]
code: def apply_gradients(self, grads_and_vars):
      with tf.name_scope(self.name):
          state_vars = []
          update_ops = []
  
          # Adjust learning rate to deal with startup bias.
          with tf.control_dependencies(None):
              b1pow_var = tf.Variable(
                  dtype=tf.float32, initial_value=1, trainable=False
              )
              b2pow_var = tf.Variable(
                  dtype=tf.float32, initial_value=1, trainable=False
              )
              state_vars += [b1pow_var, b2pow_var]
          b1pow_new = b1pow_var * self.beta1
          b2pow_new = b2pow_var * self.beta2
          update_ops += [
              tf.assign(b1pow_var, b1pow_new),
              tf.assign(b2pow_var, b2pow_new),
          ]
          lr_new = (
              self.learning_rate
              * tf.sqrt(1 - b2pow_new)
              / (1 - b1pow_new)
          )
  
          # Construct ops to update each variable.
          for grad, var in grads_and_vars:
              with tf.control_dependencies(None):
                  m_var = tf.Variable(
                      dtype=tf.float32,
                      initial_value=tf.zeros_like(var),
                      trainable=False,
                  )
                  v_var = tf.Variable(
                      dtype=tf.float32,
                      initial_value=tf.zeros_like(var),
                      trainable=False,
                  )
                  state_vars += [m_var, v_var]
              m_new = self.beta1 * m_var + (1 - self.beta1) * grad
              v_new = self.beta2 * v_var + (1 - self.beta2) * tf.square(
                  grad
              )
              var_delta = (
                  lr_new * m_new / (tf.sqrt(v_new) + self.epsilon)
              )
              update_ops += [
                  tf.assign(m_var, m_new),
                  tf.assign(v_var, v_new),
                  tf.assign_sub(var, var_delta),
              ]
  
          # Group everything together.
          self.all_state_vars += state_vars
          return tf.group(*update_ops)
  
imports: import numpy
  import tensorflow
  from collections import OrderedDict
  from typing import List, Union
  from .None import autosummary
  from .None import tfutil
  from ..None import util
  from .tfutil import TfExpression, TfExpressionEx
label_desc: Use image node_id 4 for calling the SimpleAdam obj's underlying member method code with example usage: obj.apply_gradients(grads_and_vars) and returns: tf