From c9e5c1e41b429ce8e2697f0ec114be7182df1165 Mon Sep 17 00:00:00 2001 From: qingqing01 Date: Tue, 18 Sep 2018 20:00:30 +0800 Subject: [PATCH] Hidden ParallelDo. (#13454) --- paddle/fluid/API.spec | 6 ------ python/paddle/fluid/layers/control_flow.py | 3 +-- .../paddle/fluid/tests/book/notest_understand_sentiment.py | 3 ++- python/paddle/fluid/tests/book/test_recognize_digits.py | 3 ++- python/paddle/fluid/tests/book/test_word2vec.py | 3 ++- .../book_memory_optimization/test_memopt_fit_a_line.py | 3 ++- python/paddle/fluid/tests/unittests/test_parallel_op.py | 3 ++- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 41ed774bf84..8baea326e59 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -237,12 +237,6 @@ paddle.fluid.layers.StaticRNN.step_input ArgSpec(args=['self', 'x'], varargs=Non paddle.fluid.layers.StaticRNN.step_output ArgSpec(args=['self', 'o'], varargs=None, keywords=None, defaults=None) paddle.fluid.layers.StaticRNN.update_memory ArgSpec(args=['self', 'mem', 'var'], varargs=None, keywords=None, defaults=None) paddle.fluid.layers.reorder_lod_tensor_by_rank ArgSpec(args=['x', 'rank_table'], varargs=None, keywords=None, defaults=None) -paddle.fluid.layers.ParallelDo.__init__ ArgSpec(args=['self', 'places', 'use_nccl', 'name'], varargs=None, keywords=None, defaults=(False, None)) -paddle.fluid.layers.ParallelDo.do ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None) -paddle.fluid.layers.ParallelDo.get_parameters ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None) -paddle.fluid.layers.ParallelDo.parent_block ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None) -paddle.fluid.layers.ParallelDo.read_input ArgSpec(args=['self', 'var'], varargs=None, keywords=None, defaults=None) -paddle.fluid.layers.ParallelDo.write_output ArgSpec(args=['self', 'var'], varargs=None, keywords=None, defaults=None) paddle.fluid.layers.Print ArgSpec(args=['input', 'first_n', 'message', 'summarize', 'print_tensor_name', 'print_tensor_type', 'print_tensor_shape', 'print_tensor_lod', 'print_phase'], varargs=None, keywords=None, defaults=(-1, None, -1, True, True, True, True, 'both')) paddle.fluid.layers.is_empty ArgSpec(args=['x', 'cond'], varargs=None, keywords='ignored', defaults=(None,)) paddle.fluid.layers.mean ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None) diff --git a/python/paddle/fluid/layers/control_flow.py b/python/paddle/fluid/layers/control_flow.py index c9a2f8a0abf..d7cee042959 100644 --- a/python/paddle/fluid/layers/control_flow.py +++ b/python/paddle/fluid/layers/control_flow.py @@ -41,7 +41,6 @@ __all__ = [ 'DynamicRNN', 'StaticRNN', 'reorder_lod_tensor_by_rank', - 'ParallelDo', 'Print', 'is_empty', ] @@ -259,7 +258,7 @@ class ParallelDo(object): # ParallelDo version & Single-thread version if thread_num > 1: places = fluid.layers.get_places(thread_num) - pd = fluid.layers.ParallelDo(places) + pd = fluid.layers.control_flow.ParallelDo(places) with pd.do(): images = pd.read_input(images) label = pd.read_input(label) diff --git a/python/paddle/fluid/tests/book/notest_understand_sentiment.py b/python/paddle/fluid/tests/book/notest_understand_sentiment.py index 82f1c6615f3..a666507bd9a 100644 --- a/python/paddle/fluid/tests/book/notest_understand_sentiment.py +++ b/python/paddle/fluid/tests/book/notest_understand_sentiment.py @@ -15,6 +15,7 @@ from __future__ import print_function from paddle.fluid.layers.device import get_places +from paddle.fluid.layers.control_flow import ParallelDo import unittest import paddle.fluid as fluid import paddle @@ -147,7 +148,7 @@ def train(word_dict, data, label, input_dim=dict_dim, class_dim=class_dim) else: places = get_places() - pd = fluid.layers.ParallelDo(places) + pd = ParallelDo(places) with pd.do(): cost, acc, _ = net_method( pd.read_input(data), diff --git a/python/paddle/fluid/tests/book/test_recognize_digits.py b/python/paddle/fluid/tests/book/test_recognize_digits.py index da216d0cc4a..135f11d24c8 100644 --- a/python/paddle/fluid/tests/book/test_recognize_digits.py +++ b/python/paddle/fluid/tests/book/test_recognize_digits.py @@ -25,6 +25,7 @@ import numpy import paddle import paddle.fluid as fluid from paddle.fluid.layers.device import get_places +from paddle.fluid.layers.control_flow import ParallelDo BATCH_SIZE = 64 @@ -81,7 +82,7 @@ def train(nn_type, if parallel: places = get_places() - pd = fluid.layers.ParallelDo(places) + pd = ParallelDo(places) with pd.do(): img_ = pd.read_input(img) label_ = pd.read_input(label) diff --git a/python/paddle/fluid/tests/book/test_word2vec.py b/python/paddle/fluid/tests/book/test_word2vec.py index fe063eb4629..9191f0fc203 100644 --- a/python/paddle/fluid/tests/book/test_word2vec.py +++ b/python/paddle/fluid/tests/book/test_word2vec.py @@ -17,6 +17,7 @@ from __future__ import print_function import paddle import paddle.fluid as fluid from paddle.fluid.layers.device import get_places +from paddle.fluid.layers.control_flow import ParallelDo import unittest import os import numpy as np @@ -84,7 +85,7 @@ def train(use_cuda, is_sparse, is_parallel, save_dirname, is_local=True): [first_word, second_word, third_word, forth_word, next_word]) else: places = get_places() - pd = fluid.layers.ParallelDo(places) + pd = ParallelDo(places) with pd.do(): avg_cost, predict_word = __network__( list( diff --git a/python/paddle/fluid/tests/book_memory_optimization/test_memopt_fit_a_line.py b/python/paddle/fluid/tests/book_memory_optimization/test_memopt_fit_a_line.py index f530f8f4882..dab2a52bc90 100644 --- a/python/paddle/fluid/tests/book_memory_optimization/test_memopt_fit_a_line.py +++ b/python/paddle/fluid/tests/book_memory_optimization/test_memopt_fit_a_line.py @@ -20,6 +20,7 @@ import sys import paddle import paddle.fluid as fluid from paddle.fluid.layers.device import get_places +from paddle.fluid.layers.control_flow import ParallelDo # need to fix random seed and training data to compare the loss # value accurately calculated by the default and the memory optimization @@ -38,7 +39,7 @@ if fluid.core.is_compiled_with_cuda(): place = fluid.CUDAPlace(0) places = get_places(device_count=0, device_type=device_type) -pd = fluid.layers.ParallelDo(places, use_nccl=use_nccl) +pd = ParallelDo(places, use_nccl=use_nccl) with pd.do(): x_ = pd.read_input(x) y_ = pd.read_input(y) diff --git a/python/paddle/fluid/tests/unittests/test_parallel_op.py b/python/paddle/fluid/tests/unittests/test_parallel_op.py index d7b9af8bac6..380e1728442 100644 --- a/python/paddle/fluid/tests/unittests/test_parallel_op.py +++ b/python/paddle/fluid/tests/unittests/test_parallel_op.py @@ -18,6 +18,7 @@ import unittest import paddle.fluid as fluid from paddle.fluid.layers.device import get_places +from paddle.fluid.layers.control_flow import ParallelDo import paddle.fluid.profiler as profiler import numpy import six @@ -120,7 +121,7 @@ class BaseParallelForTest(unittest.TestCase): thread_num = fluid.core.get_cuda_device_count( ) if use_gpu else 8 places = get_places(thread_num) - pd = fluid.layers.ParallelDo(places, use_nccl=use_nccl) + pd = ParallelDo(places, use_nccl=use_nccl) data = next(generator) if isinstance(data, fluid.framework.Variable): -- GitLab