Skip to content

Commit

Permalink
Imperative fix ptb rnn place bug (#16632)
Browse files Browse the repository at this point in the history
* Fix bug of gradient interface

* shrink transformer

* Right transformer

* Change from width-first backward to deep-first backward process

test=develop

* Reverse iterator op's input

test=develop

* Polish code

* Change the iteration direction in ingrads' map slots

test=develop

* Polish code

test=develop

* Add GPU place in static mode of ptb rnn

test=develop

* Polish code

test=develop
  • Loading branch information
velconia authored and JiabinYang committed Apr 3, 2019
1 parent 044ae24 commit cf307d0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions python/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import unittest
import paddle.fluid as fluid
import paddle.fluid.core as core
from paddle.fluid.dygraph.nn import Embedding
import paddle.fluid.framework as framework
from paddle.fluid.optimizer import SGDOptimizer
Expand Down Expand Up @@ -278,7 +279,8 @@ def test_ptb_rnn_cpu_float32(self):
num_steps=num_steps,
init_scale=init_scale)

exe = fluid.Executor(fluid.CPUPlace())
exe = fluid.Executor(fluid.CPUPlace(
) if not core.is_compiled_with_cuda() else fluid.CUDAPlace(0))
sgd = SGDOptimizer(learning_rate=1e-3)
x = fluid.layers.data(
name="x", shape=[-1, num_steps, 1], dtype='int64')
Expand Down Expand Up @@ -331,18 +333,16 @@ def test_ptb_rnn_cpu_float32(self):
for k in range(3, len(out)):
static_param_updated[static_param_name_list[k -
3]] = out[k]
self.assertTrue(np.allclose(static_loss_value, dy_loss._numpy()))
self.assertTrue(np.allclose(static_last_cell_value, last_cell._numpy()))

self.assertTrue(np.array_equal(static_loss_value, dy_loss._numpy()))
self.assertTrue(
np.array_equal(static_last_cell_value, last_cell._numpy()))
self.assertTrue(
np.allclose(static_last_hidden_value, last_hidden._numpy()))
np.array_equal(static_last_hidden_value, last_hidden._numpy()))
for key, value in six.iteritems(static_param_init):
# print("static_init name: {}, value {}".format(key, value))
# print("dy_init name: {}, value {}".format(key, dy_param_init[key]))
self.assertTrue(np.allclose(value, dy_param_init[key]))
self.assertTrue(np.array_equal(value, dy_param_init[key]))
for key, value in six.iteritems(static_param_updated):
# print("static name: {}, value {}".format(key, value))
# print("dy name: {}, value {}".format(key, dy_param_updated[key]))
self.assertTrue(np.allclose(value, dy_param_updated[key]))
self.assertTrue(np.array_equal(value, dy_param_updated[key]))


if __name__ == '__main__':
Expand Down

0 comments on commit cf307d0

Please sign in to comment.