test_sgd_op.py 522 字节
Newer Older
Q
Qiao Longfei 已提交
1
import unittest
Q
qijun 已提交
2 3
import numpy as np
from op_test import OpTest
Q
Qiao Longfei 已提交
4 5


Q
qijun 已提交
6
class TestSGD(OpTest):
Q
Qiao Longfei 已提交
7
    def setUp(self):
Q
qijun 已提交
8 9 10
        self.op_type = "sgd"
        w = np.random.random((102, 105)).astype("float32")
        g = np.random.random((102, 105)).astype("float32")
D
dangqingqing 已提交
11 12 13 14 15
        lr = 0.1

        self.inputs = {'param': w, 'grad': g}
        self.attrs = {'learning_rate': lr}
        self.outputs = {'param_out': w - lr * g}
Q
Qiao Longfei 已提交
16

Q
qijun 已提交
17 18 19
    def test_check_output(self):
        self.check_output()

Q
Qiao Longfei 已提交
20 21 22

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