test_dist_fleet_ctr.py 6.3 KB
Newer Older
T
tangwei12 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 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 __future__ import print_function

import os
import unittest
19
import tempfile
T
tangwei12 已提交
20 21 22
from test_dist_fleet_base import TestFleetBase


1
123malin 已提交
23
class TestDistMnistSync2x2(TestFleetBase):
T
tangwei12 已提交
24
    def _setup_config(self):
25
        self._mode = "sync"
1
123malin 已提交
26
        self._reader = "pyreader"
T
tangwei12 已提交
27
        self._need_test = 1
1
123malin 已提交
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    def check_with_place(self,
                         model_file,
                         delta=1e-3,
                         check_error_log=False,
                         need_envs={}):
        required_envs = {
            "PATH": os.getenv("PATH", ""),
            "PYTHONPATH": os.getenv("PYTHONPATH", ""),
            "LD_LIBRARY_PATH": os.getenv("LD_LIBRARY_PATH", ""),
            "FLAGS_rpc_deadline": "5000",  # 5sec to fail fast
            "http_proxy": "",
            "CPU_NUM": "2"
        }

        required_envs.update(need_envs)

        if check_error_log:
            required_envs["GLOG_v"] = "3"
            required_envs["GLOG_logtostderr"] = "1"

        tr0_losses, tr1_losses = self._run_cluster(model_file, required_envs)

    def test_dist_train(self):
        self.check_with_place(
            "dist_fleet_ctr.py", delta=1e-5, check_error_log=True)


T
tangwei12 已提交
56
@unittest.skip(reason="Skip unstable ut, open it when geo fixed")
57 58 59 60 61
class TestDistMnistAuto2x2(TestFleetBase):
    def _setup_config(self):
        self._mode = "auto"
        self._reader = "pyreader"

1
123malin 已提交
62 63 64 65 66 67 68 69 70 71
    def check_with_place(self,
                         model_file,
                         delta=1e-3,
                         check_error_log=False,
                         need_envs={}):
        required_envs = {
            "PATH": os.getenv("PATH", ""),
            "PYTHONPATH": os.getenv("PYTHONPATH", ""),
            "LD_LIBRARY_PATH": os.getenv("LD_LIBRARY_PATH", ""),
            "FLAGS_rpc_deadline": "5000",  # 5sec to fail fast
72 73
            "http_proxy": "",
            "CPU_NUM": "2"
1
123malin 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
        }

        required_envs.update(need_envs)

        if check_error_log:
            required_envs["GLOG_v"] = "3"
            required_envs["GLOG_logtostderr"] = "1"

        tr0_losses, tr1_losses = self._run_cluster(model_file, required_envs)

    def test_dist_train(self):
        self.check_with_place(
            "dist_fleet_ctr.py", delta=1e-5, check_error_log=True)


89
class TestDistMnistAsync2x2(TestFleetBase):
1
123malin 已提交
90
    def _setup_config(self):
91
        self._mode = "async"
1
123malin 已提交
92 93 94 95 96 97 98 99 100 101 102 103
        self._reader = "pyreader"

    def check_with_place(self,
                         model_file,
                         delta=1e-3,
                         check_error_log=False,
                         need_envs={}):
        required_envs = {
            "PATH": os.getenv("PATH", ""),
            "PYTHONPATH": os.getenv("PYTHONPATH", ""),
            "LD_LIBRARY_PATH": os.getenv("LD_LIBRARY_PATH", ""),
            "FLAGS_rpc_deadline": "5000",  # 5sec to fail fast
104 105
            "http_proxy": "",
            "CPU_NUM": "2"
1
123malin 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
        }

        required_envs.update(need_envs)

        if check_error_log:
            required_envs["GLOG_v"] = "3"
            required_envs["GLOG_logtostderr"] = "1"

        tr0_losses, tr1_losses = self._run_cluster(model_file, required_envs)

    def test_dist_train(self):
        self.check_with_place(
            "dist_fleet_ctr.py", delta=1e-5, check_error_log=True)


T
tangwei12 已提交
121
# @unittest.skip(reason="Skip unstable ut, reader need to be rewrite")
122
class TestDistMnistAsyncDataset2x2(TestFleetBase):
1
123malin 已提交
123 124
    def _setup_config(self):
        self._mode = "async"
125
        self._reader = "dataset"
1
123malin 已提交
126 127 128 129 130 131 132 133 134 135 136

    def check_with_place(self,
                         model_file,
                         delta=1e-3,
                         check_error_log=False,
                         need_envs={}):
        required_envs = {
            "PATH": os.getenv("PATH", ""),
            "PYTHONPATH": os.getenv("PYTHONPATH", ""),
            "LD_LIBRARY_PATH": os.getenv("LD_LIBRARY_PATH", ""),
            "FLAGS_rpc_deadline": "5000",  # 5sec to fail fast
137
            "http_proxy": "",
138 139 140 141 142
            "SAVE_MODEL": "1",
            "dump_param": "concat_0.tmp_0",
            "dump_fields": "dnn-fc-3.tmp_0,dnn-fc-3.tmp_0@GRAD",
            "dump_fields_path": tempfile.mkdtemp(),
            "Debug": "1"
1
123malin 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
        }

        required_envs.update(need_envs)

        if check_error_log:
            required_envs["GLOG_v"] = "3"
            required_envs["GLOG_logtostderr"] = "1"

        tr0_losses, tr1_losses = self._run_cluster(model_file, required_envs)

    def test_dist_train(self):
        self.check_with_place(
            "dist_fleet_ctr.py", delta=1e-5, check_error_log=True)


158
class TestDistCtrHalfAsync2x2(TestFleetBase):
1
123malin 已提交
159
    def _setup_config(self):
160
        self._mode = "async"
161
        self._reader = "pyreader"
T
tangwei12 已提交
162 163 164 165 166 167 168 169 170 171

    def check_with_place(self,
                         model_file,
                         delta=1e-3,
                         check_error_log=False,
                         need_envs={}):
        required_envs = {
            "PATH": os.getenv("PATH", ""),
            "PYTHONPATH": os.getenv("PYTHONPATH", ""),
            "LD_LIBRARY_PATH": os.getenv("LD_LIBRARY_PATH", ""),
172 173
            "FLAGS_rpc_deadline": "30000",  # 5sec to fail fast
            "http_proxy": "",
174 175 176
            "FLAGS_communicator_send_queue_size": "2",
            "FLAGS_communicator_max_merge_var_num": "2",
            "CPU_NUM": "2",
177
            "SAVE_MODEL": "0"
T
tangwei12 已提交
178 179 180 181 182 183 184 185 186 187 188 189
        }

        required_envs.update(need_envs)

        if check_error_log:
            required_envs["GLOG_v"] = "3"
            required_envs["GLOG_logtostderr"] = "1"

        tr0_losses, tr1_losses = self._run_cluster(model_file, required_envs)

    def test_dist_train(self):
        self.check_with_place(
190
            "dist_fleet_ctr.py", delta=1e-5, check_error_log=True)
T
tangwei12 已提交
191 192 193 194


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