test_rmsprop_op.py 1.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
import unittest
import numpy as np
from op_test import OpTest


class TestRmspropOp(OpTest):
    def setUp(self):
        self.op_type = "rmsprop"

        param = np.random.random((123, 321)).astype("float32")
        grad = np.random.random((123, 321)).astype("float32")
        moment = np.zeros((123, 321)).astype("float32")
K
Kavya Srinet 已提交
13
        learning_rate = np.array([0.01]).astype("float32")
14 15 16 17

        epsilon = 1e-6
        decay_rate = 0.9

K
Kavya Srinet 已提交
18 19 20 21 22
        self.inputs = {
            'Param': param,
            'Grad': grad,
            'Moment': moment,
            'LearningRate': learning_rate
23 24
        }

K
Kavya Srinet 已提交
25 26
        self.attrs = {'epsilon': epsilon, 'decayRate': decay_rate}

27 28 29 30 31 32 33 34 35 36 37 38
        moment_out = decay_rate * moment + (1 - decay_rate) * grad * grad
        param_out = param - learning_rate * grad / (np.sqrt(moment_out) +
                                                    epsilon)

        self.outputs = {'ParamOut': param_out, 'MomentOut': moment_out}

    def test_check_output(self):
        self.check_output()


if __name__ == "__main__":
    unittest.main()