from tensorflow.python.ops import state_ops

        var_update = state_ops.assign_sub(var, lr_t * (scaled_grad + gold))

        return control_flow_ops.group(*[var_update, ])

    def _apply_sparse(self, grad, var):  # sparse grad (only for the shakespeare model)
        return self._apply_sparse_shared(
        grad.values, var, grad.indices, lambda x, i, v: state_ops.scatter_add(x, i, v))

    def set_params(self, cog, avg_gradient, client):
        with client.model.graph.as_default():
            all_vars = tf.trainable_variables()
            for variable, value in zip(all_vars, cog):
