Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions test/legacy_test/test_activation_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from contextlib import contextmanager

import numpy as np
from op_test import OpTest, convert_float_to_uint16
from op_test import OpTest, convert_float_to_uint16, get_places
from scipy.special import erf, expit
from utils import static_guard

Expand Down Expand Up @@ -328,15 +328,7 @@ def setUp(self):
self.x = np.random.uniform(0.1, 1, self.shape).astype(self.dtype)
self.out_ref = np.expm1(self.x)

self.place = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
self.place.append(paddle.CPUPlace())
if core.is_compiled_with_cuda():
self.place.append(paddle.CUDAPlace(0))
self.place = get_places()

def test_static_api(self):
def run(place):
Expand Down
24 changes: 3 additions & 21 deletions test/legacy_test/test_activation_sparse_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

import numpy as np
from op import Operator
from op_test import get_places

import paddle
from paddle.base import core
Expand Down Expand Up @@ -52,16 +52,7 @@ def check_with_place(self, place):
np.testing.assert_array_equal(result_array, np.square(np_array))

def test_sparse_acti(self):
places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
places.append(core.CPUPlace())
if core.is_compiled_with_cuda():
places.append(core.CUDAPlace(0))
for place in places:
for place in get_places():
self.check_with_place(place)


Expand Down Expand Up @@ -94,16 +85,7 @@ def check_with_place(self, place):
np.testing.assert_allclose(result_array, np.sqrt(np_array), rtol=1e-05)

def test_sparse_acti(self):
places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
places.append(core.CPUPlace())
if core.is_compiled_with_cuda():
places.append(core.CUDAPlace(0))
for place in places:
for place in get_places():
self.check_with_place(place)


Expand Down
13 changes: 2 additions & 11 deletions test/legacy_test/test_adagrad_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import numpy as np
from op import Operator
from op_test import OpTest
from op_test import OpTest, get_places

import paddle
from paddle.base import core
Expand Down Expand Up @@ -205,16 +205,7 @@ def get_out(param, lr, grad, m, epsilon):
)

def test_sparse_adagrad(self):
places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
places.append(core.CPUPlace())
if core.is_compiled_with_cuda():
places.append(core.CUDAPlace(0))
for place in places:
for place in get_places():
self.check_with_place(place)


Expand Down
13 changes: 2 additions & 11 deletions test/legacy_test/test_adam_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np
from op import Operator
from op_test import OpTest
from op_test import OpTest, get_places

import paddle
from paddle import base
Expand Down Expand Up @@ -577,16 +577,7 @@ def check_with_place(self, place, lazy_mode):
self.assertLess((actual[i] - np_array[i]), 0.00001)

def test_sparse_adam(self):
places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
places.append(core.CPUPlace())
if core.is_compiled_with_cuda():
places.append(core.CUDAPlace(0))
for place in places:
for place in get_places():
for lazy_mode in (True, False):
self.check_with_place(place, lazy_mode)

Expand Down
15 changes: 1 addition & 14 deletions test/legacy_test/test_adam_optimizer_fp32_fp64.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

from op_test import get_places
from utils import static_guard

import paddle
from paddle import base


def get_places():
places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not base.is_compiled_with_cuda()
):
places.append(base.CPUPlace())
if base.is_compiled_with_cuda():
places.append(base.CUDAPlace(0))
return places


def main_test_func(place, dtype):
with static_guard():
main = base.Program()
Expand Down
11 changes: 2 additions & 9 deletions test/legacy_test/test_adaptive_avg_pool1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import unittest

import numpy as np
from op_test import get_places

import paddle
import paddle.nn.functional as F
Expand Down Expand Up @@ -83,15 +84,7 @@ def avg_pool1D_forward_naive(
class TestPool1D_API(unittest.TestCase):
def setUp(self):
np.random.seed(123)
self.places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
self.places.append(base.CPUPlace())
if core.is_compiled_with_cuda():
self.places.append(base.CUDAPlace(0))
self.places = get_places()

def check_adaptive_avg_dygraph_results(self, place):
with base.dygraph.guard(place):
Expand Down
24 changes: 3 additions & 21 deletions test/legacy_test/test_adaptive_max_pool1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

import numpy as np
from op_test import check_out_dtype, paddle_static_guard
from op_test import check_out_dtype, get_places, paddle_static_guard

import paddle
import paddle.nn.functional as F
from paddle import base
from paddle.base import core


def adaptive_start_index(index, input_size, output_size):
Expand Down Expand Up @@ -74,15 +72,7 @@ def max_pool1D_forward_naive(
class TestPool1D_API(unittest.TestCase):
def setUp(self):
np.random.seed(123)
self.places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
self.places.append(base.CPUPlace())
if core.is_compiled_with_cuda():
self.places.append(base.CUDAPlace(0))
self.places = get_places()

def check_adaptive_max_dygraph_results(self, place):
with base.dygraph.guard(place):
Expand Down Expand Up @@ -149,15 +139,7 @@ def test_max_pool(self):
class TestPool1D_API_ZeroSize(unittest.TestCase):
def setUp(self):
np.random.seed(123)
self.places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
self.places.append(base.CPUPlace())
if core.is_compiled_with_cuda():
self.places.append(base.CUDAPlace(0))
self.places = get_places()

def check_adaptive_max_dygraph_results(self, place):
with base.dygraph.guard(place):
Expand Down
14 changes: 2 additions & 12 deletions test/legacy_test/test_arg_min_max_v2_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

import numpy as np
from op_test import OpTest
from op_test import OpTest, get_places

import paddle
from paddle import base
from paddle.base import Program, core, program_guard


Expand Down Expand Up @@ -166,15 +164,7 @@ class ArgMaxMinTestCase(unittest.TestCase):
def setUp(self):
np.random.seed(123)
self.input_data = np.random.rand(10, 10).astype("float32")
self.places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not paddle.is_compiled_with_cuda()
):
self.places.append(base.CPUPlace())
if core.is_compiled_with_cuda():
self.places.append(paddle.CUDAPlace(0))
self.places = get_places()
self.op = eval(f"paddle.{op_type}")
self.numpy_op = eval(f"np.{op_type}")

Expand Down
27 changes: 4 additions & 23 deletions test/legacy_test/test_assign_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

import gradient_checker
import numpy as np
import op_test
from decorator_helper import prog_scope
from op_test import convert_float_to_uint16, convert_uint16_to_float
from op_test import convert_float_to_uint16, convert_uint16_to_float, get_places

import paddle
from paddle import base
from paddle.base import Program, core, program_guard
from paddle.base import Program, program_guard
from paddle.base.backward import append_backward


Expand Down Expand Up @@ -327,16 +326,7 @@ def func(self, place):

def test_grad(self):
paddle.enable_static()
places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
places.append(base.CPUPlace())
if core.is_compiled_with_cuda():
places.append(base.CUDAPlace(0))
for p in places:
for p in get_places():
self.func(p)
paddle.disable_static()

Expand Down Expand Up @@ -365,16 +355,7 @@ def func(self, place):

def test_grad(self):
paddle.enable_static()
places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not core.is_compiled_with_cuda()
):
places.append(base.CPUPlace())
if core.is_compiled_with_cuda():
places.append(base.CUDAPlace(0))
for p in places:
for p in get_places():
self.func(p)
paddle.disable_static()

Expand Down
12 changes: 2 additions & 10 deletions test/legacy_test/test_bce_with_logits_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

import numpy as np
from op_test import get_places

import paddle
from paddle import base
Expand Down Expand Up @@ -143,15 +143,7 @@ class TestBCEWithLogitsLoss(unittest.TestCase):
def test_BCEWithLogitsLoss(self):
logit_np = np.random.uniform(0.1, 0.8, size=(20, 30)).astype(np.float64)
label_np = np.random.randint(0, 2, size=(20, 30)).astype(np.float64)
places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not base.core.is_compiled_with_cuda()
):
places.append(base.CPUPlace())
if base.core.is_compiled_with_cuda():
places.append(base.CUDAPlace(0))
places = get_places()
reductions = ['sum', 'mean', 'none']
for place in places:
for reduction in reductions:
Expand Down
13 changes: 2 additions & 11 deletions test/legacy_test/test_box_coder_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

import numpy as np
from op_test import OpTest
from op_test import OpTest, get_places

import paddle

Expand Down Expand Up @@ -340,15 +339,7 @@ def setUp(self):
self.box_normalized,
self.axis,
)
self.place = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not paddle.is_compiled_with_cuda()
):
self.place.append(paddle.CPUPlace())
if paddle.is_compiled_with_cuda():
self.place.append(paddle.CUDAPlace(0))
self.place = get_places()

def test_dygraph_api(self):
def run(place):
Expand Down
Loading
Loading