diff --git a/test/deprecated/legacy_test/CMakeLists.txt b/test/deprecated/legacy_test/CMakeLists.txt index 7e68ae538002d..a98e9387f3c1e 100644 --- a/test/deprecated/legacy_test/CMakeLists.txt +++ b/test/deprecated/legacy_test/CMakeLists.txt @@ -38,8 +38,6 @@ list(APPEND MIXED_DIST_TEST_OPS test_ascend_group) list(APPEND MIXED_DIST_TEST_OPS test_fleet_api_input) list(APPEND MIXED_DIST_TEST_OPS test_fleet_base) -list(APPEND MIXED_DIST_TEST_OPS test_fleet_base_2_deprecated) -list(APPEND MIXED_DIST_TEST_OPS test_fleet_base_3_deprecated) list(APPEND MIXED_DIST_TEST_OPS test_fleet_auto) list(APPEND MIXED_DIST_TEST_OPS test_auto_parallel_partitioner_deprecated) list(APPEND MIXED_DIST_TEST_OPS test_auto_parallel_partitioner_gpt_deprecated) @@ -499,10 +497,6 @@ if(WITH_DISTRIBUTE) if(NOT APPLE) py_test_modules(test_fleet_base MODULES test_fleet_base ENVS ${dist_ENVS} FLAGS_enable_pir_api=0) - py_test_modules(test_fleet_base_2_deprecated MODULES - test_fleet_base_2_deprecated ENVS ${dist_ENVS}) - py_test_modules(test_fleet_base_3_deprecated MODULES - test_fleet_base_3_deprecated ENVS ${dist_ENVS}) if(NOT WIN32) py_test_modules( test_auto_parallel_partitioner_deprecated MODULES diff --git a/test/deprecated/legacy_test/test_fleet_base_2_deprecated.py b/test/deprecated/legacy_test/test_fleet_base_2_deprecated.py deleted file mode 100644 index 836f9486f8667..0000000000000 --- a/test/deprecated/legacy_test/test_fleet_base_2_deprecated.py +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright (c) 2020 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. - -import tempfile -import unittest - -import paddle - -paddle.enable_static() - -import os - -from paddle import base - - -class TestFleetBase(unittest.TestCase): - def setUp(self): - os.environ["POD_IP"] = "127.0.0.1" - os.environ["PADDLE_PORT"] = "36000" - os.environ["PADDLE_TRAINERS_NUM"] = "1" - # os.environ["PADDLE_PSERVERS_IP_PORT_LIST"] = \ - # "127.0.0.1:36001,127.0.0.2:36001" - - def test_ps_minimize(self): - import paddle - from paddle.distributed import fleet - - os.environ["TRAINING_ROLE"] = "TRAINER" - os.environ["PADDLE_TRAINER_ID"] = "1" - - input_x = paddle.static.data(name="x", shape=[-1, 32], dtype='float32') - input_slot = paddle.static.data( - name="slot", shape=[-1, 1], dtype='int64' - ) - input_y = paddle.static.data(name="y", shape=[-1, 1], dtype='int64') - - emb = paddle.static.nn.sparse_embedding(input=input_slot, size=[10, 9]) - input_x = paddle.concat(x=[input_x, emb], axis=1) - fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh') - fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh') - prediction = paddle.static.nn.fc(x=[fc_2], size=2, activation='softmax') - cost = paddle.nn.functional.cross_entropy( - input=prediction, label=input_y, reduction='none', use_softmax=False - ) - avg_cost = paddle.mean(x=cost) - - role = fleet.PaddleCloudRoleMaker(is_collective=False) - fleet.init(role) - - strategy = paddle.distributed.fleet.DistributedStrategy() - strategy.a_sync = False - strategy.a_sync_configs = {"launch_barrier": False} - - optimizer = paddle.optimizer.SGD(learning_rate=0.001) - optimizer = fleet.distributed_optimizer(optimizer, strategy=strategy) - optimizer.minimize(avg_cost) - - place = base.CPUPlace() - exe = base.Executor(place) - exe.run(paddle.static.default_startup_program()) - compiled_prog = base.compiler.CompiledProgram( - base.default_main_program() - ) - - temp_dir = tempfile.TemporaryDirectory() - fleet.init_worker() - fleet.fleet.save( - dirname=temp_dir.name, feed=['x', 'y'], fetch=[avg_cost] - ) - fleet.fleet.save( - dirname=temp_dir.name, feed=[input_x, input_y], fetch=[avg_cost] - ) - fleet.fleet.save(dirname=temp_dir.name) - - fleet.load_model(path=temp_dir.name, mode=0) - fleet.load_model(path=temp_dir.name, mode=1) - temp_dir.cleanup() - - -if __name__ == "__main__": - unittest.main() diff --git a/test/deprecated/legacy_test/test_fleet_base_3_deprecated.py b/test/deprecated/legacy_test/test_fleet_base_3_deprecated.py deleted file mode 100644 index b72a79be8dde3..0000000000000 --- a/test/deprecated/legacy_test/test_fleet_base_3_deprecated.py +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright (c) 2020 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. - -import os -import unittest - -import paddle -from paddle.distributed import fleet -from paddle.distributed.fleet.base import role_maker - -paddle.enable_static() - - -class TestFleetBase_1(unittest.TestCase): - def setUp(self): - os.environ["POD_IP"] = "127.0.0.1" - os.environ["PADDLE_TRAINER_ENDPOINTS"] = "127.0.0.1:36001" - os.environ["PADDLE_TRAINERS_NUM"] = "2" - os.environ["PADDLE_PSERVERS_IP_PORT_LIST"] = ( - "127.0.0.1:36001,127.0.0.2:36001" - ) - - def test_collective_minimize(self): - input_x = paddle.static.data(name="x", shape=[-1, 32], dtype='float32') - input_y = paddle.static.data(name="y", shape=[-1, 1], dtype='int64') - - fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh') - fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh') - prediction = paddle.static.nn.fc(x=[fc_2], size=2, activation='softmax') - cost = paddle.nn.functional.cross_entropy( - input=prediction, label=input_y, reduction='none', use_softmax=False - ) - avg_cost = paddle.mean(x=cost) - - role = role_maker.PaddleCloudRoleMaker(is_collective=True) - fleet.init(role) - strategy = fleet.DistributedStrategy() - optimizer = paddle.optimizer.SGD(learning_rate=0.001) - optimizer = fleet.distributed_optimizer(optimizer, strategy=strategy) - optimizer.minimize(avg_cost) - - -class TestFleetBase(unittest.TestCase): - def setUp(self): - os.environ["POD_IP"] = "127.0.0.1" - os.environ["PADDLE_TRAINER_ENDPOINTS"] = "127.0.0.1:36001" - os.environ["PADDLE_TRAINERS_NUM"] = "2" - os.environ["PADDLE_PSERVERS_IP_PORT_LIST"] = ( - "127.0.0.1:36001,127.0.0.2:36001" - ) - - def test_fleet_get_applied_optimizer(self): - input_x = paddle.static.data(name="x", shape=[-1, 32], dtype='float32') - input_y = paddle.static.data(name="y", shape=[-1, 1], dtype='int64') - - fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh') - fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh') - prediction = paddle.static.nn.fc(x=[fc_2], size=2, activation='softmax') - cost = paddle.nn.functional.cross_entropy( - input=prediction, label=input_y, reduction='none', use_softmax=False - ) - avg_cost = paddle.mean(x=cost) - - fleet.init(is_collective=True) - - meta_list = fleet._get_applied_meta_list() - graph_list = fleet._get_applied_graph_list() - # not called minimize function - self.assertEqual(len(meta_list), 0) - self.assertEqual(len(graph_list), 0) - - strategy = fleet.DistributedStrategy() - optimizer = paddle.optimizer.SGD(learning_rate=0.001) - optimizer = fleet.distributed_optimizer(optimizer, strategy=strategy) - optimizer.minimize(avg_cost) - - meta_list = fleet._get_applied_meta_list() - graph_list = fleet._get_applied_graph_list() - self.assertEqual(len(meta_list), 1) - self.assertEqual(len(graph_list), 0) - - -if __name__ == "__main__": - unittest.main() diff --git a/test/legacy_test/test_fleet_base_4.py b/test/legacy_test/test_fleet_base_4.py deleted file mode 100644 index 30f837965a311..0000000000000 --- a/test/legacy_test/test_fleet_base_4.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2020 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. - -import os -import unittest - -import paddle -from paddle.distributed import fleet - -paddle.enable_static() - - -class TestFleetBase(unittest.TestCase): - def setUp(self): - os.environ["POD_IP"] = "127.0.0.1" - os.environ["PADDLE_TRAINER_ENDPOINTS"] = "127.0.0.1:36001" - os.environ["PADDLE_TRAINERS_NUM"] = "2" - os.environ["PADDLE_PSERVERS_IP_PORT_LIST"] = ( - "127.0.0.1:36001,127.0.0.2:36001" - ) - - def test_fleet_init(self): - os.environ["TRAINING_ROLE"] = "PSERVER" - os.environ["POD_IP"] = "127.0.0.1" - os.environ["PADDLE_PORT"] = "36001" - - role = fleet.PaddleCloudRoleMaker(is_collective=False) - fleet.init(role) - fleet.init() - fleet.init(is_collective=False) - self.assertRaises(Exception, fleet.init, is_collective="F") - self.assertRaises(Exception, fleet.init, role_maker="F") - - -if __name__ == "__main__": - unittest.main()