提交 25fee871 编写于 作者: Y yangyaming

Change program.seed from 0 to 1.

上级 f05330b7
...@@ -8,8 +8,7 @@ from paddle.v2.fluid.framework import Program, switch_main_program ...@@ -8,8 +8,7 @@ from paddle.v2.fluid.framework import Program, switch_main_program
import bisect import bisect
import numpy as np import numpy as np
fluid.default_startup_program().random_seed = 0 fluid.default_startup_program().random_seed = 1
np.random.seed(0)
class TestDyRnnStaticInput(unittest.TestCase): class TestDyRnnStaticInput(unittest.TestCase):
...@@ -166,8 +165,6 @@ class TestDyRnnStaticInput(unittest.TestCase): ...@@ -166,8 +165,6 @@ class TestDyRnnStaticInput(unittest.TestCase):
self.assertTrue(np.allclose(lod, expected_lods[i])) self.assertTrue(np.allclose(lod, expected_lods[i]))
def test_network_gradient(self): def test_network_gradient(self):
pass #still have bug (seed doesn't work)
'''
static_input_grad, loss = self.build_graph() static_input_grad, loss = self.build_graph()
self.exe.run(framework.default_startup_program()) self.exe.run(framework.default_startup_program())
...@@ -175,7 +172,6 @@ class TestDyRnnStaticInput(unittest.TestCase): ...@@ -175,7 +172,6 @@ class TestDyRnnStaticInput(unittest.TestCase):
static_input_shape = self.static_input_tensor.get_dims() static_input_shape = self.static_input_tensor.get_dims()
numeric_gradients = np.zeros(shape=static_input_shape).astype('float32') numeric_gradients = np.zeros(shape=static_input_shape).astype('float32')
print(actual_gradients)
# calculate numeric gradients # calculate numeric gradients
tensor_size = np.product(static_input_shape) tensor_size = np.product(static_input_shape)
for i in xrange(tensor_size): for i in xrange(tensor_size):
...@@ -188,8 +184,8 @@ class TestDyRnnStaticInput(unittest.TestCase): ...@@ -188,8 +184,8 @@ class TestDyRnnStaticInput(unittest.TestCase):
y_neg = self.fetch_value(loss)[0][0] y_neg = self.fetch_value(loss)[0][0]
self.static_input_tensor.set_float_element(i, origin) self.static_input_tensor.set_float_element(i, origin)
numeric_gradients.ravel()[i] = (y_pos - y_neg) / self._delta / 2 numeric_gradients.ravel()[i] = (y_pos - y_neg) / self._delta / 2
print(numeric_gradients) self.assertTrue(np.allclose(actual_gradients, numeric_gradients, 0.001))
''' self.assertTrue(np.allclose(actual_lod, self.static_input_tensor.lod()))
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册