test_dist_simnet_bow.py 4.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#   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

from test_dist_base import TestDistBase

21 22 23
import os
flag_name = os.path.splitext(__file__)[0]

24 25 26 27

class TestDistSimnetBowDense2x2(TestDistBase):
    def _setup_config(self):
        self._sync_mode = True
28
        self._enforce_place = "CPU"
29 30

    def test_simnet_bow(self):
31 32 33 34 35
        need_envs = {
            "IS_DISTRIBUTED": '0',
            "IS_SPARSE": '0',
            'IS_SELF_CONTAINED_LR': '1'
        }
36 37 38
        self.check_with_place(
            "dist_simnet_bow.py",
            delta=1e-5,
T
tangwei12 已提交
39
            check_error_log=True,
40 41
            need_envs=need_envs,
            log_name=flag_name)
42 43 44 45 46


class TestDistSimnetBow2x2DenseAsync(TestDistBase):
    def _setup_config(self):
        self._sync_mode = False
47
        self._enforce_place = "CPU"
48

Y
Yu Yang 已提交
49 50
    #FIXME(typhoonzero): fix async tests later
    def notest_simnet_bow(self):
51 52 53
        need_envs = {
            "IS_DISTRIBUTED": '0',
            "IS_SPARSE": '0',
Y
Yu Yang 已提交
54
            'IS_SELF_CONTAINED_LR': '1',
55
        }
56 57 58
        self.check_with_place(
            "dist_simnet_bow.py",
            delta=100,
59 60 61
            check_error_log=True,
            need_envs=need_envs,
            log_name=flag_name)
62 63 64 65 66


class TestDistSimnetBowSparse2x2(TestDistBase):
    def _setup_config(self):
        self._sync_mode = True
67
        self._enforce_place = "CPU"
68 69

    def test_simnet_bow(self):
70 71 72 73 74
        need_envs = {
            "IS_DISTRIBUTED": '0',
            "IS_SPARSE": '1',
            'IS_SELF_CONTAINED_LR': '1'
        }
75 76 77
        self.check_with_place(
            "dist_simnet_bow.py",
            delta=1e-5,
78 79 80
            check_error_log=True,
            need_envs=need_envs,
            log_name=flag_name)
81 82 83 84 85


class TestDistSimnetBow2x2SparseAsync(TestDistBase):
    def _setup_config(self):
        self._sync_mode = False
86
        self._enforce_place = "CPU"
87 88

    def test_simnet_bow(self):
89 90 91 92 93
        need_envs = {
            "IS_DISTRIBUTED": '0',
            "IS_SPARSE": '1',
            'IS_SELF_CONTAINED_LR': '1'
        }
94 95 96
        self.check_with_place(
            "dist_simnet_bow.py",
            delta=100,
97 98 99
            check_error_log=True,
            need_envs=need_envs,
            log_name=flag_name)
100 101


G
gongweibao 已提交
102
# FIXME(tangwei): Learningrate variable is not created on pserver.
103 104 105 106 107 108 109 110 111 112 113 114 115 116
class TestDistSimnetBow2x2LookupTableSync(TestDistBase):
    def _setup_config(self):
        self._sync_mode = True
        self._enforce_place = "CPU"

    def test_simnet_bow(self):
        need_envs = {
            "IS_DISTRIBUTED": '1',
            "IS_SPARSE": '1',
            'IS_SELF_CONTAINED_LR': '1'
        }
        self.check_with_place(
            "dist_simnet_bow.py",
            delta=1e-5,
G
gongweibao 已提交
117
            check_error_log=True,
118 119
            need_envs=need_envs,
            log_name=flag_name)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135


class TestDistSimnetBow2x2LookupTableAsync(TestDistBase):
    def _setup_config(self):
        self._sync_mode = False
        self._enforce_place = "CPU"

    def test_simnet_bow(self):
        need_envs = {
            "IS_DISTRIBUTED": '1',
            "IS_SPARSE": '1',
            'IS_SELF_CONTAINED_LR': '1'
        }
        self.check_with_place(
            "dist_simnet_bow.py",
            delta=100,
136 137 138
            check_error_log=True,
            need_envs=need_envs,
            log_name=flag_name)
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154


class TestDistSimnetBow2x2LookupTableNotContainLRSync(TestDistBase):
    def _setup_config(self):
        self._sync_mode = True
        self._enforce_place = "CPU"

    def test_simnet_bow(self):
        need_envs = {
            "IS_DISTRIBUTED": '1',
            "IS_SPARSE": '1',
            'IS_SELF_CONTAINED_LR': '0'
        }
        self.check_with_place(
            "dist_simnet_bow.py",
            delta=1e-5,
155 156 157
            check_error_log=True,
            need_envs=need_envs,
            log_name=flag_name)
158 159


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