TensorFlow:RMSprop 的实际实现在哪里?

TensorFlow: Where is the actual implementation of RMSprop?

在"rmsprop.py"中(在TensorFlow中)调用了方法apply_rms_prop。此方法在 "gen_training_ops.py" 中定义。在这个方法的定义中有一条注释描述了它应该做什么:

ms <- rho * ms_{t-1} + (1-rho) * grad * grad
mom <- momentum * mom_{t-1} + lr * grad / sqrt(ms + epsilon)
var <- var - mom

但我似乎找不到上面伪代码的实际 python 实现在哪里。我的猜测是它是在 cpython 中实现的,因为我能够找到文件“__pycache__/rmsprop.cpython-36.pyc”。但同样,执行上述伪代码的 cpython 实现在哪里?

我的目标是实现自己的梯度更新方法,所以我需要看一些具体的实现示例(例如rmsprop、adam等)。任何帮助将非常感激!

您可以从 Optimizer class 实施您自己的优化器。您必须至少实现方法 _apply_dense_apply_sparse 中的一种。

adamax 优化器的完整实现,使用纯粹可用的 tensorflow ops。

class AdamaxOptimizer(optimizer.Optimizer):
..
   you can create slot variables implementing slot fucntion
   def _create_slots(self, var_list):
       ...
   def _apply_dense(self, grad, var):
        implement your logic for gradient updates here.

您可以在 tensorflow/core/kernels. The CPU version is in training_ops.cc and the GPU (CUDA) version in training_ops_gpu.cu.cc 下找到实现(查找模板结构 ApplyRMSProp)。其他优化器更新规则实现也可以在这些文件中找到。

认为 CPython代码是使用文件末尾的内核注册宏自动生成的,将不同的实现分组在一个操作名称下(翻译从骆驼外壳到蛇外壳 Python),您可以独立于设备使用。