【问题标题】:TensorFlow: Where is the actual implementation of RMSprop?TensorFlow:RMSprop 的实际实现在哪里?
【发布时间】:2018-02-07 19:21:52
【问题描述】:

在“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等)。任何帮助将非常感激!

【问题讨论】:

    标签: python-3.x tensorflow gradient-descent


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您可以从Optimizer 类实现自己的优化器。您必须至少实现_apply_dense_apply_sparse 方法之一。

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

      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.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-22
        • 2011-09-02
        • 1970-01-01
        • 1970-01-01
        • 2012-04-13
        • 1970-01-01
        • 2019-10-14
        • 1970-01-01
        相关资源
        最近更新 更多