diff --git a/python/paddle/distributed/io.py b/python/paddle/distributed/io.py index fe5fde358b0667d076f8ffed1daa97c638557c11..2af170d07aad9a3c3bae4a7d49690f432db86c56 100644 --- a/python/paddle/distributed/io.py +++ b/python/paddle/distributed/io.py @@ -48,7 +48,7 @@ def _save_distributed_persistables(executor, dirname, main_program): paddle.enable_static() exe = paddle.static.Executor(paddle.CPUPlace()) param_path = "./my_paddle_model" - t = distribute_transpiler.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(...) train_program = t.get_trainer_program() _save_distributed_persistables(executor=exe, dirname=param_path, main_program=train_program) diff --git a/python/paddle/distributed/transpiler/__init__.py b/python/paddle/distributed/transpiler/__init__.py index eca2dce114b069bf9b455d77ce670d73b5047fd2..d1c7301d8f4d60faf8c057ab5a66cdaa9e3d50c0 100644 --- a/python/paddle/distributed/transpiler/__init__.py +++ b/python/paddle/distributed/transpiler/__init__.py @@ -11,3 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from .distribute_transpiler import ( + DistributeTranspiler, + DistributeTranspilerConfig, +) +from .memory_optimization_transpiler import memory_optimize, release_memory diff --git a/python/paddle/fluid/transpiler/distribute_transpiler.py b/python/paddle/distributed/transpiler/distribute_transpiler.py similarity index 98% rename from python/paddle/fluid/transpiler/distribute_transpiler.py rename to python/paddle/distributed/transpiler/distribute_transpiler.py index 046e8d931ee73f31783ceb732d0f33bab6ef5d66..265174ff369e91e039e712e1256ba6b469442a75 100644 --- a/python/paddle/fluid/transpiler/distribute_transpiler.py +++ b/python/paddle/distributed/transpiler/distribute_transpiler.py @@ -28,26 +28,29 @@ Steps to transpile pserver: 5. add listen_and_serv op """ +import collections +import logging +import math import os import sys -import math from functools import reduce -import collections -import logging - import numpy as np -from .ps_dispatcher import RoundRobin, PSDispatcher -from .. import core, framework, unique_name -from ..framework import ( - Program, +from paddle import framework +from paddle.fluid.framework import grad_var_name +from paddle.framework import Block, Program, core +from paddle.incubate.distributed.fleet.parameter_server.ir.ps_dispatcher import ( + PSDispatcher, + RoundRobin, +) +from paddle.nn.initializer import Constant +from paddle.static import ( + Parameter, default_main_program, default_startup_program, - Block, - Parameter, - grad_var_name, ) +from paddle.utils import unique_name LOOKUP_TABLE_TYPE = ["lookup_table", "lookup_table_v2"] LOOKUP_TABLE_GRAD_TYPE = ["lookup_table_grad", "lookup_table_v2_grad"] @@ -172,10 +175,10 @@ class DistributeTranspilerConfig: Examples: .. code-block:: python - from paddle.fluid.transpiler.ps_dispatcher import RoundRobin - import paddle.fluid as fluid + from paddle.distributed.transpiler.ps_dispatcher import RoundRobin + import paddle.distributed.transpiler as transpiler - config = fluid.DistributeTranspilerConfig() + config = transpiler.DistributeTranspilerConfig() config.slice_var_up = True config.split_method = RoundRobin config.min_block_size = 81920 @@ -281,11 +284,12 @@ class DistributeTranspiler: import paddle import paddle.fluid as fluid + import paddle.distributed.transpiler as transpiler paddle.enable_static() - x = fluid.data(name='x', shape=[1,13], dtype='float32') - y = fluid.data(name='y', shape=[1], dtype='float32') + x = paddle.static.data(name='x', shape=[1,13], dtype='float32') + y = paddle.static.data(name='y', shape=[1], dtype='float32') y_predict = paddle.static.nn.fc(x, size=1, activation=None) cost =paddle.nn.functional.square_error_cost(input=y_predict, label=y) @@ -301,7 +305,7 @@ class DistributeTranspiler: trainer_id = 0 trainers = 4 role = "PSERVER" - t = fluid.DistributeTranspiler() + t = transpiler.DistributeTranspiler() t.transpile( trainer_id, pservers=pserver_endpoints, trainers=trainers) if role == "PSERVER": @@ -314,12 +318,12 @@ class DistributeTranspiler: # for nccl2 mode trainer_num = 2 trainer_id = 0 - config = fluid.DistributeTranspilerConfig() + config = transpiler.DistributeTranspilerConfig() config.mode = "nccl2" trainer_endpoints = "192.168.0.1:6174,192.168.0.2:6174" - t = fluid.DistributeTranspiler(config=config) + t = transpiler.DistributeTranspiler(config=config) t.transpile(trainer_id=trainer_id, trainers=trainer_endpoints, current_endpoint="192.168.0.1:6174") - exe = fluid.ParallelExecutor( + exe = paddle.static.ParallelExecutor( use_cuda=True, loss_name=avg_loss.name, num_trainers=trainer_num, @@ -588,9 +592,9 @@ class DistributeTranspiler: trainer_id (int): id for current trainer worker, if you have n workers, the id may range from 0 ~ n-1 program (Program|None): program to transpile, - default is fluid.default_main_program(). + default is paddle.static.default_main_program(). startup_program (Program|None): startup_program to transpile, - default is fluid.default_startup_program(). + default is paddle.static.default_startup_program(). pservers (str): comma separated ip:port string for the pserver list. trainers (int|str): in pserver mode this is the number of @@ -598,7 +602,7 @@ class DistributeTranspiler: endpoints. sync_mode (bool): Do sync training or not, default is True. startup_program (Program|None): startup_program to transpile, - default is fluid.default_main_program(). + default is paddle.static.default_main_program(). current_endpoint (str): need pass current endpoint when transpile as nccl2 distributed mode. In pserver mode this argument is not used. @@ -606,7 +610,7 @@ class DistributeTranspiler: Examples: .. code-block:: python - transpiler = fluid.DistributeTranspiler() + transpiler = paddle.distributed.transpiler.DistributeTranspiler() t.transpile( trainer_id=0, pservers="127.0.0.1:7000,127.0.0.1:7001", @@ -1124,12 +1128,12 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler Examples: .. code-block:: python - import paddle.fluid as fluid + import paddle.distributed.transpiler as transpiler #this is an example, find available endpoints in your case pserver_endpoints = "192.168.0.1:6174,192.168.0.2:6174" trainer_id = 0 trainers = 4 - t = fluid.DistributeTranspiler() + t = transpiler.DistributeTranspiler() t.transpile(trainer_id, trainers=trainers, pservers=pserver_endpoints) trainer_program = t.get_trainer_program() """ @@ -1270,13 +1274,13 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler Examples: .. code-block:: python - import paddle.fluid as fluid + import paddle.distributed.transpiler as transpiler #this is an example, find available endpoints in your case pserver_endpoints = "192.168.0.1:6174,192.168.0.2:6174" current_endpoint = "192.168.0.1:6174" trainer_id = 0 trainers = 4 - t = fluid.DistributeTranspiler() + t = transpiler.DistributeTranspiler() t.transpile( trainer_id, pservers=pserver_endpoints, trainers=trainers) pserver_program = t.get_pserver_program(current_endpoint) @@ -1349,8 +1353,8 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler opt_op_on_pserver.append(op) # step 3.3 # prepare if dc asgd is enabled - if self.config.enable_dc_asgd == True: - assert self.sync_mode == False + if self.config.enable_dc_asgd is True: + assert self.sync_mode is False self.param_bak_list = [] # add param_bak for each trainer for p in self.param_grad_ep_mapping[endpoint]["params"]: @@ -1579,13 +1583,13 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler Examples: .. code-block:: python - import paddle.fluid as fluid + import paddle.distributed.transpiler as transpiler #this is an example, find available endpoints in your case pserver_endpoints = "192.168.0.1:6174,192.168.0.2:6174" current_endpoint = "192.168.0.1:6174" trainer_id = 0 trainers = 4 - t = fluid.DistributeTranspiler() + t = transpiler.DistributeTranspiler() t.transpile( trainer_id, pservers=pserver_endpoints, trainers=trainers) pserver_program, pserver_startup_program = t.get_pserver_programs(current_endpoint) @@ -1624,7 +1628,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler trainer_id = 0 trainers = 4 - t = fluid.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(trainer_id, pservers=pserver_endpoints, trainers=trainers) pserver_program = t.get_pserver_program(current_endpoint) pserver_startup_program = t.get_startup_program(current_endpoint, @@ -1851,7 +1855,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler param_grad_set = set() for p, g in self.params_grads: # skip parameter marked not trainable - if type(p) == Parameter and p.trainable == False: + if type(p) == Parameter and p.trainable is False: continue if p.name not in param_grad_set: param_list.append(p) @@ -2834,7 +2838,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler if role_id == int(LR_SCHED_OP_ROLE_ATTR_VALUE) or role_id == int( LR_SCHED_OP_ROLE_ATTR_VALUE ) | int(OPT_OP_ROLE_ATTR_VALUE): - if self.sync_mode == False and op.type == 'increment': + if self.sync_mode is False and op.type == 'increment': inputs = self._get_input_map_from_op( self.origin_program.global_block().vars, op ) @@ -2879,7 +2883,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler dtype=var.dtype, shape=var.shape, persistable=var.persistable, - initializer=paddle.nn.initializer.Constant(1), + initializer=Constant(1), ) op_role_attr_name = ( core.op_proto_and_checker_maker.kOpRoleAttrName() @@ -2978,7 +2982,7 @@ WIKI: https://github.com/PaddlePaddle/Fleet/blob/develop/markdown_doc/transpiler if op.attr(OP_ROLE_VAR_ATTR_NAME): param_name = op.attr(OP_ROLE_VAR_ATTR_NAME)[0] grad_name = op.attr(OP_ROLE_VAR_ATTR_NAME)[1] - if not param_name in optimize_params: + if param_name not in optimize_params: optimize_params.add(param_name) log("adding param_grad pair: ", param_name, grad_name) params_grads.append( diff --git a/python/paddle/fluid/transpiler/geo_sgd_transpiler.py b/python/paddle/distributed/transpiler/geo_sgd_transpiler.py similarity index 97% rename from python/paddle/fluid/transpiler/geo_sgd_transpiler.py rename to python/paddle/distributed/transpiler/geo_sgd_transpiler.py index 829217811455c5504ba6a36f6473ab574218b6f0..33f9b42add00fd70a77ae2da65e33f2b336728b9 100644 --- a/python/paddle/fluid/transpiler/geo_sgd_transpiler.py +++ b/python/paddle/distributed/transpiler/geo_sgd_transpiler.py @@ -24,36 +24,34 @@ Steps to transpile pserver: 4. append sum ops that should run on current server instance. 5. add listen_and_serv op """ -import sys import collections -import numpy as np -from .ps_dispatcher import RoundRobin, PSDispatcher -from .. import core, framework -from ..framework import ( - Program, - default_main_program, - default_startup_program, - Block, - Parameter, +from paddle import framework +from paddle.distributed.distribute_lookup_table import ( + find_distributed_lookup_table, ) from paddle.distributed.transpiler.details import ( - wait_server_ready, VarsDistributed, + wait_server_ready, ) -from paddle.distributed.transpiler.details import delete_ops -from .distribute_transpiler import ( - DistributeTranspiler, - DistributeTranspilerConfig, - slice_variable, - same_or_split_var, - ServerRuntimeConfig, +from paddle.framework import Program, core +from paddle.incubate.distributed.fleet.parameter_server.ir.ps_dispatcher import ( + PSDispatcher, + RoundRobin, ) from paddle.incubate.distributed.fleet.parameter_server.mode import ( DistributedMode, ) -from paddle.distributed.distribute_lookup_table import ( - find_distributed_lookup_table, +from paddle.static import ( + Parameter, + default_main_program, + default_startup_program, +) + +from .distribute_transpiler import ( + DistributeTranspiler, + DistributeTranspilerConfig, + slice_variable, ) RPC_OP_ROLE_ATTR_NAME = ( @@ -311,7 +309,7 @@ class GeoSgdTranspiler(DistributeTranspiler): param_grad_set = set() # step 1. create param_list for p, g in self.params_grads: - if type(p) == Parameter and p.trainable == False: + if type(p) == Parameter and p.trainable is False: continue if p.name not in param_grad_set: param_list.append(p) diff --git a/python/paddle/fluid/transpiler/memory_optimization_transpiler.py b/python/paddle/distributed/transpiler/memory_optimization_transpiler.py old mode 100755 new mode 100644 similarity index 92% rename from python/paddle/fluid/transpiler/memory_optimization_transpiler.py rename to python/paddle/distributed/transpiler/memory_optimization_transpiler.py index c71197fa0ad8160f60f7dfaffa6d15c75546ce45..fc9f5804d49505308a4fbfcc45d17defc6c1d9c4 --- a/python/paddle/fluid/transpiler/memory_optimization_transpiler.py +++ b/python/paddle/distributed/transpiler/memory_optimization_transpiler.py @@ -25,7 +25,7 @@ def memory_optimize( memory optimization strategies are enabled by default. """ logging.warn( - 'Caution! paddle.fluid.memory_optimize() is deprecated ' + 'Caution! paddle.distributed.transpiler.memory_optimize() is deprecated ' 'and not maintained any more, since it is not stable!\n' 'This API would not take any memory optimizations on your Program ' 'now, since we have provided default strategies for you.\n' @@ -48,6 +48,6 @@ def release_memory(input_program, skip_opt_set=None): memory optimization strategies are enabled by default. """ logging.warn( - 'paddle.fluid.release_memory() is deprecated, it would not' + 'paddle.distributed.transpiler.release_memory() is deprecated, it would not' ' take any memory release on your program' ) diff --git a/python/paddle/fluid/__init__.py b/python/paddle/fluid/__init__.py index 700df8c554165dfdec07b069e58e0594120f5904..10293a4178653f26c628084c7c7a2c0ff184432a 100644 --- a/python/paddle/fluid/__init__.py +++ b/python/paddle/fluid/__init__.py @@ -64,7 +64,6 @@ from .backward import gradients from . import regularizer from . import average from . import metrics -from . import transpiler from . import incubate from .param_attr import ParamAttr, WeightNormParamAttr from .data_feeder import DataFeeder @@ -80,12 +79,6 @@ from .core import ( MLUPlace, CustomPlace, ) -from .transpiler import ( - DistributeTranspiler, - memory_optimize, - release_memory, - DistributeTranspilerConfig, -) from .lod_tensor import create_lod_tensor, create_random_int_lodtensor from . import profiler from . import unique_name @@ -107,7 +100,6 @@ from .trainer_desc import ( MultiTrainer, HeterXpuTrainer, ) -from .transpiler import HashName, RoundRobin from .backward import append_backward Tensor = LoDTensor @@ -118,7 +110,6 @@ __all__ = ( framework.__all__ + executor.__all__ + trainer_desc.__all__ - + transpiler.__all__ + parallel_executor.__all__ + lod_tensor.__all__ + data_feed_desc.__all__ @@ -135,7 +126,6 @@ __all__ = ( 'disable_dygraph', 'enable_imperative', 'disable_imperative', - 'transpiler', 'nets', 'optimizer', 'backward', diff --git a/python/paddle/fluid/contrib/tests/test_image_classification_fp16.py b/python/paddle/fluid/contrib/tests/test_image_classification_fp16.py index 5ab54bc7161780859445e31bd3086654a9ff09c5..b147252ce221539f87e3b459de16d709b247851a 100644 --- a/python/paddle/fluid/contrib/tests/test_image_classification_fp16.py +++ b/python/paddle/fluid/contrib/tests/test_image_classification_fp16.py @@ -235,7 +235,7 @@ def train(net_type, use_cuda, save_dirname, is_local): current_endpoint = os.getenv("POD_IP") + ":" + port trainer_id = int(os.getenv("PADDLE_TRAINER_ID")) training_role = os.getenv("PADDLE_TRAINING_ROLE", "TRAINER") - t = fluid.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(trainer_id, pservers=pserver_endpoints, trainers=trainers) if training_role == "PSERVER": pserver_prog = t.get_pserver_program(current_endpoint) diff --git a/python/paddle/fluid/io.py b/python/paddle/fluid/io.py index 9faeacee886c46c277d0e3240eb5263af822dd54..ac9563fb9217e98365f0d3e7af0caac7487c5842 100644 --- a/python/paddle/fluid/io.py +++ b/python/paddle/fluid/io.py @@ -563,7 +563,7 @@ def _save_distributed_persistables(executor, dirname, main_program): paddle.enable_static() exe = fluid.Executor(fluid.CPUPlace()) param_path = "./my_paddle_model" - t = distribute_transpiler.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(...) train_program = t.get_trainer_program() _save_distributed_persistables(executor=exe, dirname=param_path, main_program=train_program) @@ -1179,7 +1179,7 @@ def _load_distributed_persistables(executor, dirname, main_program=None): paddle.enable_static() exe = fluid.Executor(fluid.CPUPlace()) param_path = "./my_paddle_model" - t = distribute_transpiler.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(...) pserver_prog = t.get_pserver_program(...) _load_distributed_persistables(executor=exe, dirname=param_path, main_program=pserver_prog) diff --git a/python/paddle/fluid/tests/book/notest_understand_sentiment.py b/python/paddle/fluid/tests/book/notest_understand_sentiment.py index 0eb09b210bd02962f75b48a891ac28a0c6610d72..0a1133db885e80f782b523c8676b24697e34252c 100644 --- a/python/paddle/fluid/tests/book/notest_understand_sentiment.py +++ b/python/paddle/fluid/tests/book/notest_understand_sentiment.py @@ -129,7 +129,7 @@ def train( current_endpoint = os.getenv("POD_IP") + ":" + port trainer_id = int(os.getenv("PADDLE_TRAINER_ID")) training_role = os.getenv("PADDLE_TRAINING_ROLE", "TRAINER") - t = fluid.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(trainer_id, pservers=pserver_endpoints, trainers=trainers) if training_role == "PSERVER": pserver_prog = t.get_pserver_program(current_endpoint) diff --git a/python/paddle/fluid/tests/book/test_fit_a_line.py b/python/paddle/fluid/tests/book/test_fit_a_line.py index c7c930fd53b5880eb5c83fff5777ac9d1e7db5d2..65ec225b05ee19330380ed02d578c2fab9da6854 100644 --- a/python/paddle/fluid/tests/book/test_fit_a_line.py +++ b/python/paddle/fluid/tests/book/test_fit_a_line.py @@ -144,7 +144,7 @@ def train(use_cuda, save_dirname, is_local, use_bf16, pure_bf16): current_endpoint = os.getenv("POD_IP") + ":" + port trainer_id = int(os.getenv("PADDLE_TRAINER_ID")) training_role = os.getenv("PADDLE_TRAINING_ROLE", "TRAINER") - t = fluid.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(trainer_id, pservers=pserver_endpoints, trainers=trainers) if training_role == "PSERVER": pserver_prog = t.get_pserver_program(current_endpoint) diff --git a/python/paddle/fluid/tests/book/test_image_classification.py b/python/paddle/fluid/tests/book/test_image_classification.py index 6ee33951583a1cf2be7acaac7fa49d71c71a5c49..417c01b4ca28655ede7f2f6689e0407c79640216 100644 --- a/python/paddle/fluid/tests/book/test_image_classification.py +++ b/python/paddle/fluid/tests/book/test_image_classification.py @@ -202,7 +202,7 @@ def train(net_type, use_cuda, save_dirname, is_local): current_endpoint = os.getenv("POD_IP") + ":" + port trainer_id = int(os.getenv("PADDLE_TRAINER_ID")) training_role = os.getenv("PADDLE_TRAINING_ROLE", "TRAINER") - t = fluid.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(trainer_id, pservers=pserver_endpoints, trainers=trainers) if training_role == "PSERVER": pserver_prog = t.get_pserver_program(current_endpoint) diff --git a/python/paddle/fluid/tests/book/test_recognize_digits.py b/python/paddle/fluid/tests/book/test_recognize_digits.py index 5d6939af8902fdca51b6b4486788269194524b6b..3c46168a27299879d2f1ee5ad9e2672b706cb5ae 100644 --- a/python/paddle/fluid/tests/book/test_recognize_digits.py +++ b/python/paddle/fluid/tests/book/test_recognize_digits.py @@ -178,7 +178,7 @@ def train( current_endpoint = os.getenv("POD_IP") + ":" + port trainer_id = int(os.getenv("PADDLE_TRAINER_ID")) training_role = os.getenv("PADDLE_TRAINING_ROLE", "TRAINER") - t = fluid.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(trainer_id, pservers=pserver_endpoints, trainers=trainers) if training_role == "PSERVER": pserver_prog = t.get_pserver_program(current_endpoint) diff --git a/python/paddle/fluid/tests/book/test_recommender_system.py b/python/paddle/fluid/tests/book/test_recommender_system.py index b4805e8f413985d163d9f261ca53a6f9749d63ca..c60e8d4fba3cc49242eaf76d7264ae8e858ac734 100644 --- a/python/paddle/fluid/tests/book/test_recommender_system.py +++ b/python/paddle/fluid/tests/book/test_recommender_system.py @@ -279,7 +279,7 @@ def train(use_cuda, save_dirname, is_local=True): current_endpoint = os.getenv("POD_IP") + ":" + port trainer_id = int(os.getenv("PADDLE_TRAINER_ID")) training_role = os.getenv("PADDLE_TRAINING_ROLE", "TRAINER") - t = fluid.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(trainer_id, pservers=pserver_endpoints, trainers=trainers) if training_role == "PSERVER": pserver_prog = t.get_pserver_program(current_endpoint) diff --git a/python/paddle/fluid/tests/book/test_word2vec_book.py b/python/paddle/fluid/tests/book/test_word2vec_book.py index d976e41dcc69710fc385e153001614512aa56b42..16fead30366ad122ab6c142ee98cede37f9528c1 100644 --- a/python/paddle/fluid/tests/book/test_word2vec_book.py +++ b/python/paddle/fluid/tests/book/test_word2vec_book.py @@ -184,7 +184,7 @@ def train( current_endpoint = os.getenv("POD_IP") + ":" + port trainer_id = int(os.getenv("PADDLE_TRAINER_ID")) training_role = os.getenv("PADDLE_TRAINING_ROLE", "TRAINER") - t = fluid.DistributeTranspiler() + t = paddle.distributed.transpiler.DistributeTranspiler() t.transpile(trainer_id, pservers=pserver_endpoints, trainers=trainers) if training_role == "PSERVER": pserver_prog = t.get_pserver_program(current_endpoint) diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/test_distributed_strategy.py b/python/paddle/fluid/tests/unittests/collective/fleet/test_distributed_strategy.py index f9148365ffc0e49be43582034a868b024157e768..920926f62ba91e9492ee60fc9c542051ed829d6d 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/test_distributed_strategy.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/test_distributed_strategy.py @@ -18,7 +18,7 @@ import unittest import paddle import paddle.fluid as fluid import paddle.incubate.distributed.fleet.role_maker as role_maker -from paddle.fluid.transpiler.distribute_transpiler import ( +from paddle.distributed.transpiler.distribute_transpiler import ( DistributeTranspilerConfig, ServerRuntimeConfig, ) diff --git a/python/paddle/fluid/tests/unittests/test_boxps.py b/python/paddle/fluid/tests/unittests/test_boxps.py index 636502eed9c6c9643727cd79b4c8360662ecd8d3..3b471e6209445ac694e3533a6ca6304727e78a66 100644 --- a/python/paddle/fluid/tests/unittests/test_boxps.py +++ b/python/paddle/fluid/tests/unittests/test_boxps.py @@ -25,10 +25,10 @@ class TestTranspile(unittest.TestCase): """TestCases for BoxPS Preload""" def get_transpile(self, mode, trainers="127.0.0.1:6174"): - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() config.mode = 'collective' config.collective_mode = mode - t = fluid.DistributeTranspiler(config=config) + t = paddle.distributed.transpiler.DistributeTranspiler(config=config) return t def test_transpile(self): diff --git a/python/paddle/fluid/tests/unittests/test_deprecated_memory_optimize_interfaces.py b/python/paddle/fluid/tests/unittests/test_deprecated_memory_optimize_interfaces.py index 536972332abfdc4f9508a6ffdb3a7288108fa768..58a15077de159fc9e4908bd6c3137b1923d14a71 100644 --- a/python/paddle/fluid/tests/unittests/test_deprecated_memory_optimize_interfaces.py +++ b/python/paddle/fluid/tests/unittests/test_deprecated_memory_optimize_interfaces.py @@ -16,12 +16,13 @@ import unittest from simple_nets import simple_fc_net +import paddle.distributed.transpiler as transpiler import paddle.fluid as fluid class DeprecatedMemoryOptimizationInterfaceTest(unittest.TestCase): def setUp(self): - self.method = fluid.memory_optimize + self.method = transpiler.memory_optimize def build_network(self, call_interface): startup_prog = fluid.Program() @@ -63,7 +64,7 @@ class DeprecatedMemoryOptimizationInterfaceTest(unittest.TestCase): class ReleaseMemoryTest(DeprecatedMemoryOptimizationInterfaceTest): def setUp(self): - self.method = fluid.release_memory + self.method = transpiler.release_memory if __name__ == '__main__': diff --git a/python/paddle/fluid/tests/unittests/test_dist_base.py b/python/paddle/fluid/tests/unittests/test_dist_base.py index ae769016bde05bb629574f9758de1d545fb6733a..16b8090fc6de493fc84cb795f8e46f2552783a86 100755 --- a/python/paddle/fluid/tests/unittests/test_dist_base.py +++ b/python/paddle/fluid/tests/unittests/test_dist_base.py @@ -80,7 +80,7 @@ class TestDistRunnerBase: hogwild_mode=False, ): # NOTE: import fluid until runtime, or else forking processes will cause error. - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() config.enable_dc_asgd = dc_asgd config.sync_mode = sync_mode config.runtime_split_send_recv = hogwild_mode @@ -88,7 +88,7 @@ class TestDistRunnerBase: if nccl_comm_num > 1: config.nccl_comm_num = nccl_comm_num # config.runtime_split_send_recv = True - t = fluid.DistributeTranspiler(config=config) + t = paddle.distributed.transpiler.DistributeTranspiler(config=config) t.transpile( trainer_id=trainer_id, program=main_program, @@ -454,7 +454,7 @@ class TestDistRunnerBase: or args.update_method == "nccl2_reduce_layer" ): # transpile for nccl2 - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() config.mode = "nccl2" config.nccl_comm_num = args.nccl_comm_num if args.use_hallreduce: @@ -466,7 +466,9 @@ class TestDistRunnerBase: type(self).__name__, "begin to run transpile on trainer with nccl2 mode", ) - nccl2_t = fluid.DistributeTranspiler(config=config) + nccl2_t = paddle.distributed.transpiler.DistributeTranspiler( + config=config + ) nccl2_t.transpile( args.trainer_id, program=fluid.default_main_program(), diff --git a/python/paddle/fluid/tests/unittests/test_dist_transpiler.py b/python/paddle/fluid/tests/unittests/test_dist_transpiler.py index cc8868c1065b3f7e3ed5328c1886583dd5147b1e..a9dd07783506a20f109eaf026f56779474bace2a 100644 --- a/python/paddle/fluid/tests/unittests/test_dist_transpiler.py +++ b/python/paddle/fluid/tests/unittests/test_dist_transpiler.py @@ -81,7 +81,11 @@ class TranspilerTest(unittest.TestCase): def _transpiler_instance(self, config=None, sync_mode=True): if not self.transpiler: main = self.get_main_program() - self.transpiler = fluid.DistributeTranspiler(config=config) + self.transpiler = ( + paddle.distributed.transpiler.DistributeTranspiler( + config=config + ) + ) self.transpiler.transpile( self.trainer_id, program=main, @@ -202,7 +206,7 @@ class TestBasicModel(TranspilerTest): class TestBasicModelWithLargeBlockSize(TranspilerTest): def transpiler_test_impl(self): - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() config.min_block_size = 1048576 pserver, startup = self.get_pserver(self.pserver1_ep, config) @@ -276,7 +280,7 @@ class TestNoSliceVar(TranspilerTest): super().setUp() def transpiler_test_impl(self): - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() config.slice_var_up = False _, startup = self.get_pserver(self.pserver1_ep, config) @@ -692,7 +696,7 @@ class TestEmptyPserverOptimizeBlocks(TranspilerTest): sgd_optimizer.minimize(avg_cost) def transpiler_test_impl(self): - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() config.slice_var_up = False pserver, startup = self.get_pserver(ep=self.pserver2_ep, config=config) @@ -924,7 +928,7 @@ class TestAsyncLocalLookupTable(TestDistLookupTableBase): self.network_with_table(is_sparse=True, is_distributed=False) def transpiler_test_impl(self): - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() pserver1, startup1 = self.get_pserver(self.pserver1_ep, config, False) self.assertEqual(len(pserver1.blocks), 4) @@ -991,7 +995,7 @@ class TestAsyncDistLookupTable(TestDistLookupTableBase): self.network_with_table(is_sparse=True, is_distributed=True) def transpiler_test_impl(self): - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() pserver1, startup1 = self.get_pserver(self.pserver1_ep, config, False) @@ -1089,7 +1093,7 @@ class TestDistLookupTableSliceSize(TestDistLookupTableBase): self.network_with_table(is_sparse=True, is_distributed=True) def transpiler_test_impl(self): - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() pserver1, _ = self.get_pserver(self.pserver1_ep, config) self.assertTrue(self.transpiler.has_distributed_lookup_table) @@ -1220,10 +1224,12 @@ class TestNCCL2Transpile(TranspilerTest): with fluid.program_guard(main, startup): self.net_conf() - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() config.mode = "nccl2" config.wait_port = False - t = fluid.DistributeTranspiler(config=config) + t = paddle.distributed.transpiler.DistributeTranspiler( + config=config + ) t.transpile( 0, trainers="127.0.0.1:6174,127.0.0.1:6175", diff --git a/python/paddle/fluid/tests/unittests/test_fleet_api_input.py b/python/paddle/fluid/tests/unittests/test_fleet_api_input.py index 596af335b6eb134aed824d7ae8fb1ffc1c67229c..316ddce6577f62a3a927925d41673b98e193c135 100644 --- a/python/paddle/fluid/tests/unittests/test_fleet_api_input.py +++ b/python/paddle/fluid/tests/unittests/test_fleet_api_input.py @@ -19,7 +19,7 @@ from dist_fleet_simnet_bow import train_network import paddle import paddle.fluid as fluid import paddle.incubate.distributed.fleet.role_maker as role_maker -from paddle.fluid.transpiler.distribute_transpiler import ( +from paddle.distributed.transpiler.distribute_transpiler import ( DistributeTranspilerConfig, ) from paddle.incubate.distributed.fleet.collective import CollectiveOptimizer diff --git a/python/paddle/fluid/tests/unittests/test_listen_and_serv_op.py b/python/paddle/fluid/tests/unittests/test_listen_and_serv_op.py index 0c1327c5af3a110a6e375c06c2758d1d42ac742d..793b4de78ed0190fe3e6a086bf561f8a87fee607 100644 --- a/python/paddle/fluid/tests/unittests/test_listen_and_serv_op.py +++ b/python/paddle/fluid/tests/unittests/test_listen_and_serv_op.py @@ -49,9 +49,9 @@ def run_pserver(use_cuda, sync_mode, ip, port, trainers, trainer_id): pserver_endpoints = ip + ":" + port current_endpoint = ip + ":" + port - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() config.sync_mode = sync_mode - t = fluid.DistributeTranspiler(config=config) + t = paddle.distributed.transpiler.DistributeTranspiler(config=config) t.transpile( trainer_id, pservers=pserver_endpoints, @@ -87,11 +87,11 @@ def run_pserver_with_empty_block( ps2 = ip + ":" + port pserver_endpoints = ps1 + "," + ps2 - config = fluid.DistributeTranspilerConfig() + config = paddle.distributed.transpiler.DistributeTranspilerConfig() config.sync_mode = sync_mode config.slice_var_up = False - t = fluid.DistributeTranspiler(config=config) + t = paddle.distributed.transpiler.DistributeTranspiler(config=config) t.transpile( trainer_id, pservers=pserver_endpoints, diff --git a/python/paddle/fluid/tests/unittests/test_slice_var.py b/python/paddle/fluid/tests/unittests/test_slice_var.py index 84c04c65424baaf5a150d9026f5e93bece000f1e..03881f83da7ce9fa47bb0253d2ab012b11b4af0d 100644 --- a/python/paddle/fluid/tests/unittests/test_slice_var.py +++ b/python/paddle/fluid/tests/unittests/test_slice_var.py @@ -16,7 +16,7 @@ import random import unittest import paddle.fluid as fluid -from paddle.fluid.transpiler.distribute_transpiler import slice_variable +from paddle.distributed.transpiler.distribute_transpiler import slice_variable class TestSliceVar(unittest.TestCase): diff --git a/python/paddle/fluid/transpiler/__init__.py b/python/paddle/fluid/transpiler/__init__.py deleted file mode 100644 index 8da4210dba2e760883b3bb122bb7aa687645e25c..0000000000000000000000000000000000000000 --- a/python/paddle/fluid/transpiler/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from .distribute_transpiler import ( - DistributeTranspiler, - DistributeTranspilerConfig, -) -from .memory_optimization_transpiler import memory_optimize, release_memory -from .ps_dispatcher import HashName, RoundRobin - -__all__ = [ - "DistributeTranspiler", - "memory_optimize", - "release_memory", - "HashName", - "RoundRobin", - "DistributeTranspilerConfig", -] diff --git a/python/paddle/fluid/transpiler/ps_dispatcher.py b/python/paddle/fluid/transpiler/ps_dispatcher.py deleted file mode 100644 index c42472f5a15c57957decff2d59ab67e7b36d7e12..0000000000000000000000000000000000000000 --- a/python/paddle/fluid/transpiler/ps_dispatcher.py +++ /dev/null @@ -1,127 +0,0 @@ -# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -class PSDispatcher: - """ - PSDispatcher is the base class for dispatching vars - into different pserver instance. - You need to implement the `dispatch` interface. - """ - - def __init__(self, pserver_endpoints): - self._eps = pserver_endpoints - self._step = 0 - - @property - def eps(self): - return self._eps - - def reset(self): - """ - reset the step counter, set it zero. - """ - self._step = 0 - - def dispatch(self, varlist): - """ - Args: - varlist(list): a list of Variables - Returns: - a map of pserver endpoint -> varname - """ - AssertionError("Interface has not been implemented.") - - -class HashName(PSDispatcher): - """ - :api_attr: Static Graph - - Hash variable names to several endpoints using python - "hash()" function. - - Args: - pserver_endpoints (list): list of endpoint(ip:port). - - Examples: - .. code-block:: python - - pserver_endpoints = ["127.0.0.1:6007", "127.0.0.1:6008"] - vars = ["var1","var2","var3","var4","var5"] - - rr = RoundRobin(pserver_endpoints) - rr.dispatch(vars) - - """ - - def __init__(self, pserver_endpoints): - super().__init__(pserver_endpoints) - - def _hash_block(self, block_str, total): - return hash(block_str) % total - - def dispatch(self, varlist): - """ - use `HashName` method to dispatch variables with each parameter server. - Args: - varlist (list): a list of Variables - - """ - eplist = [] - for var in varlist: - server_id = self._hash_block(var.name(), len(self._eps)) - server_for_param = self._eps[server_id] - eplist.append(server_for_param) - return eplist - - -class RoundRobin(PSDispatcher): - """ - :api_attr: Static Graph - - Distribute variables to several endpoints using - RondRobin method. - - Args: - pserver_endpoints (list): list of endpoint(ip:port). - - Examples: - .. code-block:: python - - pserver_endpoints = ["127.0.0.1:6007", "127.0.0.1:6008"] - vars = ["var1","var2","var3","var4","var5"] - - rr = RoundRobin(pserver_endpoints) - rr.dispatch(vars) - - """ - - def __init__(self, pserver_endpoints): - super().__init__(pserver_endpoints) - - def dispatch(self, varlist): - """ - use `RoundRobin` method to dispatch variables with each parameter server. - Args: - varlist (list): a list of Variables - - """ - eplist = [] - for var in varlist: - server_for_param = self._eps[self._step] - eplist.append(server_for_param) - self._step += 1 - if self._step >= len(self._eps): - self._step = 0 - return eplist diff --git a/python/paddle/incubate/distributed/fleet/collective.py b/python/paddle/incubate/distributed/fleet/collective.py index 5a41d90187e9f3dff113eabd8c02b4ea1f4d4804..5e135ced868303e3816ffbe96a381135181c37d7 100644 --- a/python/paddle/incubate/distributed/fleet/collective.py +++ b/python/paddle/incubate/distributed/fleet/collective.py @@ -15,9 +15,9 @@ import logging import os import paddle +import paddle.distributed.transpiler.distribute_transpiler as dist_transpiler import paddle.fluid as fluid import paddle.fluid.io as io -import paddle.fluid.transpiler.distribute_transpiler as dist_transpiler from paddle.fluid.compiler import CompiledProgram from paddle.fluid.executor import Executor from paddle.fluid.framework import Program diff --git a/python/paddle/incubate/distributed/fleet/parameter_server/distribute_transpiler/__init__.py b/python/paddle/incubate/distributed/fleet/parameter_server/distribute_transpiler/__init__.py index f60ef7fd54ff8da949345e67609f208bbd49936d..accddd6e1fe0454c10fa23828bb73027b70055e3 100644 --- a/python/paddle/incubate/distributed/fleet/parameter_server/distribute_transpiler/__init__.py +++ b/python/paddle/incubate/distributed/fleet/parameter_server/distribute_transpiler/__init__.py @@ -31,7 +31,7 @@ from paddle.fluid.compiler import CompiledProgram from paddle.fluid.parallel_executor import ParallelExecutor from paddle.fluid.optimizer import Optimizer -from paddle.fluid.transpiler.distribute_transpiler import ( +from paddle.distributed.transpiler.distribute_transpiler import ( DistributeTranspilerConfig, ) @@ -78,7 +78,7 @@ from paddle.incubate.distributed.fleet.parameter_server.ir import ( class FleetTranspiler(Fleet): """ - A subclass for compatibility with fluid.transpiler.DistributeTranspiler. + A subclass for compatibility with distributed.transpiler.DistributeTranspiler. """ def __init__(self): diff --git a/python/paddle/incubate/distributed/fleet/parameter_server/distribute_transpiler/distributed_strategy.py b/python/paddle/incubate/distributed/fleet/parameter_server/distribute_transpiler/distributed_strategy.py index 799755a29573508774c2e6148362a1bed7616af9..4e4b076d3b394389b71e81c0f7a428907a01cc85 100644 --- a/python/paddle/incubate/distributed/fleet/parameter_server/distribute_transpiler/distributed_strategy.py +++ b/python/paddle/incubate/distributed/fleet/parameter_server/distribute_transpiler/distributed_strategy.py @@ -25,7 +25,7 @@ __all__ = [ import os import paddle.fluid as fluid -from paddle.fluid.transpiler.distribute_transpiler import ( +from paddle.distributed.transpiler.distribute_transpiler import ( DistributeTranspilerConfig, ServerRuntimeConfig, ) diff --git a/python/setup.py.in b/python/setup.py.in index 7e1d6a7ad6a37650709655430bce8e64abfaed3d..198599cb01965fc311d2c09f4a0410af7a1f7af9 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -400,7 +400,6 @@ packages=['paddle', 'paddle.fluid.contrib', 'paddle.fluid.contrib.extend_optimizer', 'paddle.fluid.contrib.layers', - 'paddle.fluid.transpiler', 'paddle.fluid.incubate', 'paddle.incubate.distributed.fleet', 'paddle.fluid.incubate.checkpoint', diff --git a/setup.py b/setup.py index 9d2ee1c3e5d0beb720a0c3df68163900b93e2b28..429db65282ed1534a05b3c76abb7721a2bc5df3c 100644 --- a/setup.py +++ b/setup.py @@ -1300,7 +1300,6 @@ def get_setup_parameters(): 'paddle.fluid.contrib', 'paddle.fluid.contrib.extend_optimizer', 'paddle.fluid.contrib.layers', - 'paddle.fluid.transpiler', 'paddle.fluid.incubate', 'paddle.incubate.distributed.fleet', 'paddle.fluid.incubate.checkpoint',