test_parallel_dygraph_sharding_parallel.py 1.6 KB
Newer Older
J
JZ-LIANG 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2021 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.

zhenhailiu's avatar
zhenhailiu 已提交
15
import os
J
JZ-LIANG 已提交
16 17
import unittest

T
tianshuo78520a 已提交
18
from legacy_test.test_parallel_dygraph_dataparallel import TestMultipleGpus
J
JZ-LIANG 已提交
19 20 21 22 23


class TestHybridParallel(TestMultipleGpus):
    # check sharding logic as well as the accuracy with single mode
    def test_hybrid_parallel_sharding_logic(self):
zhenhailiu's avatar
zhenhailiu 已提交
24 25 26 27 28 29 30
        # test shard grad reduce
        os.environ["FLAGS_shard_use_reduce"] = "1"
        os.environ["FLAGS_shard_norm_align_dp"] = "0"
        self.run_mnist_2gpu('hybrid_parallel_sharding_model.py')
        # test shard grad allreduce
        os.environ["FLAGS_shard_use_reduce"] = "0"
        os.environ["FLAGS_shard_norm_align_dp"] = "1"
31
        self.run_mnist_2gpu('hybrid_parallel_sharding_model.py')
J
JZ-LIANG 已提交
32

33 34 35
    def test_hybrid_parallel_sharding_tensor_fusion(self):
        self.run_mnist_2gpu('hybrid_parallel_sharding_model_with_fusion.py')

36 37 38
    def test_hybrid_parallel_sharding_state_dict(self):
        self.run_mnist_2gpu('hybrid_parallel_sharding_state_dict.py')

J
JZ-LIANG 已提交
39 40 41

if __name__ == "__main__":
    unittest.main()