未验证 提交 6220b8b9 编写于 作者: C chengduo 提交者: GitHub

[Speed] Make test_dyn_rnn faster (#16761)

* make test_dyn_rnn faster
上级 06809ebb
...@@ -24,15 +24,15 @@ from paddle.fluid.layers.control_flow import max_sequence_len ...@@ -24,15 +24,15 @@ from paddle.fluid.layers.control_flow import max_sequence_len
from paddle.fluid.layers.control_flow import lod_tensor_to_array from paddle.fluid.layers.control_flow import lod_tensor_to_array
from paddle.fluid.layers.control_flow import array_to_lod_tensor from paddle.fluid.layers.control_flow import array_to_lod_tensor
from paddle.fluid.layers.control_flow import shrink_memory from paddle.fluid.layers.control_flow import shrink_memory
from fake_reader import fake_imdb_reader
class TestDynRNN(unittest.TestCase): class TestDynRNN(unittest.TestCase):
def setUp(self): def setUp(self):
self.word_dict = paddle.dataset.imdb.word_dict() self.word_dict_len = 5147
self.BATCH_SIZE = 2 self.BATCH_SIZE = 2
self.train_data = paddle.batch( reader = fake_imdb_reader(self.word_dict_len, self.BATCH_SIZE * 100)
paddle.dataset.imdb.train(self.word_dict), self.train_data = paddle.batch(reader, batch_size=self.BATCH_SIZE)
batch_size=self.BATCH_SIZE)
def test_plain_while_op(self): def test_plain_while_op(self):
main_program = fluid.Program() main_program = fluid.Program()
...@@ -42,7 +42,7 @@ class TestDynRNN(unittest.TestCase): ...@@ -42,7 +42,7 @@ class TestDynRNN(unittest.TestCase):
sentence = fluid.layers.data( sentence = fluid.layers.data(
name='word', shape=[1], dtype='int64', lod_level=1) name='word', shape=[1], dtype='int64', lod_level=1)
sent_emb = fluid.layers.embedding( sent_emb = fluid.layers.embedding(
input=sentence, size=[len(self.word_dict), 32], dtype='float32') input=sentence, size=[self.word_dict_len, 32], dtype='float32')
label = fluid.layers.data(name='label', shape=[1], dtype='float32') label = fluid.layers.data(name='label', shape=[1], dtype='float32')
...@@ -109,7 +109,7 @@ class TestDynRNN(unittest.TestCase): ...@@ -109,7 +109,7 @@ class TestDynRNN(unittest.TestCase):
sentence = fluid.layers.data( sentence = fluid.layers.data(
name='word', shape=[1], dtype='int64', lod_level=1) name='word', shape=[1], dtype='int64', lod_level=1)
sent_emb = fluid.layers.embedding( sent_emb = fluid.layers.embedding(
input=sentence, size=[len(self.word_dict), 32], dtype='float32') input=sentence, size=[self.word_dict_len, 32], dtype='float32')
rnn = fluid.layers.DynamicRNN() rnn = fluid.layers.DynamicRNN()
......
...@@ -175,7 +175,7 @@ class TestTransformer(TestParallelExecutorBase): ...@@ -175,7 +175,7 @@ class TestTransformer(TestParallelExecutorBase):
self.check_network_convergence(transformer, use_cuda=True) self.check_network_convergence(transformer, use_cuda=True)
self.check_network_convergence( self.check_network_convergence(
transformer, use_cuda=True, enable_sequential_execution=True) transformer, use_cuda=True, enable_sequential_execution=True)
self.check_network_convergence(transformer, use_cuda=False, iter=5) self.check_network_convergence(transformer, use_cuda=False, iter=2)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册