import tensorflow as tf

        beta1_t = math_ops.cast(self._beta1_t, var.dtype.base_dtype)
        beta2_t = math_ops.cast(self._beta2_t, var.dtype.base_dtype)
        if var.dtype.base_dtype == tf.float16:
            eps = 1e-7  # Can't use 1e-8 due to underflow -- not sure if it makes a big difference.
        else:
            eps = 1e-8

        v = self.get_slot(var, "v")
        v_t = v.assign(beta2_t * v + (1. - beta2_t) * tf.square(grad))
        m = self.get_slot(var, "m")
        m_t = m.assign(beta1_t * m + (1. - beta1_t) * grad)
        v_t_hat = tf.div(v_t, 1. - beta2_t)
        m_t_hat = tf.div(m_t, 1. - beta1_t)

        g_t = tf.div(m_t_hat, tf.sqrt(v_t_hat) + eps)
        g_t_1 = self.get_slot(var, "g")
