Skip to content

Commit 6e5eae1

Browse files
author
xuwei06
committed
Unittest for fluid.backward.calc_gradient()
1 parent 585dec3 commit 6e5eae1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
3+
import paddle.v2.fluid as fluid
4+
import paddle.v2.fluid.layers as layers
5+
import paddle.v2.fluid.framework as framework
6+
import paddle.v2.fluid.optimizer as optimizer
7+
from paddle.v2.fluid.backward import calc_gradient
8+
9+
10+
class TestCalcGradient(unittest.TestCase):
11+
def test_calc_gradient(self):
12+
x = layers.create_parameter(dtype="float32", shape=[5, 10])
13+
y = layers.create_parameter(dtype="float32", shape=[10, 8])
14+
mul_out = layers.mul(x=x, y=y)
15+
mean_out = layers.mean(x=mul_out)
16+
a = calc_gradient(mean_out, mul_out)
17+
b = calc_gradient(mean_out, x)
18+
place = fluid.CPUPlace()
19+
exe = fluid.Executor(place)
20+
exe.run(fluid.default_startup_program())
21+
exe.run(fluid.default_main_program(), feed={}, fetch_list=[a, b])
22+
23+
24+
if __name__ == "__main__":
25+
unittest.main()

0 commit comments

Comments
 (0)