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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions test/legacy_test/test_adamax_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 @@ -276,18 +275,7 @@ def _test_adamax_op_dygraph_place_amp(self, place, use_amp=False):
paddle.enable_static()

def _get_places(self):
import paddle

places = []
if (
os.environ.get('FLAGS_CI_both_cpu_and_gpu', 'False').lower()
in ['1', 'true', 'on']
or not paddle.is_compiled_with_cuda()
):
places.append('cpu')
if paddle.is_compiled_with_cuda():
places.append('gpu')
return places
return get_places(string_format=True)

def test_main(self):
for place in self._get_places():
Expand Down
12 changes: 2 additions & 10 deletions test/legacy_test/test_adamw_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from functools import partial

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

import paddle
from paddle import base, nn
Expand Down Expand Up @@ -758,15 +758,7 @@ def _test_adamw_op_dygraph_place_amp(self, place, use_amp=False):
optimizer.clear_grad()

def _get_places(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()
):
places.append('cpu')
if paddle.is_compiled_with_cuda():
places.append('gpu')
places = get_places(string_format=True)
if paddle.is_compiled_with_xpu():
places.append('xpu')
return places
Expand Down
12 changes: 2 additions & 10 deletions test/legacy_test/test_adaptive_log_softmax_with_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
import paddle.optimizer as optim
Expand Down Expand Up @@ -58,15 +58,7 @@ def predict(self, input):
class TestNNAdaptiveLogSoftmaxWithLossAPI(unittest.TestCase):
def setUp(self):
paddle.seed(2024)
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('cpu')
if paddle.is_compiled_with_cuda():
self.place.append('gpu')
self.place = get_places(string_format=True)
self.log_np = np.random.randn(4, 8).astype('float32')
self.predict_np = np.abs(np.random.randn(64, 8).astype('float32'))

Expand Down
13 changes: 2 additions & 11 deletions test/legacy_test/test_bce_loss.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
from paddle import base
Expand Down Expand Up @@ -161,15 +160,7 @@ class TestBCELoss(unittest.TestCase):
def test_BCELoss(self):
input_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
22 changes: 3 additions & 19 deletions test/legacy_test/test_cartesian_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
# 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 random
import unittest
from itertools import product

import numpy as np
from op_test import get_places

import paddle
from paddle.base import core
Expand All @@ -36,15 +36,7 @@ def setUp(self):
self.c_np = np.random.random(self.c_shape).astype(self.dtype_np)
self.d_np = np.empty(0, self.dtype_np)

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('cpu')
if paddle.is_compiled_with_cuda():
self.place.append('gpu')
self.place = get_places(string_format=True)

def init_setting(self):
self.dtype_np = 'float32'
Expand Down Expand Up @@ -127,15 +119,7 @@ def setUp(self):
self.a_np = np.random.random(self.a_shape).astype(self.dtype_np)
self.b_np = np.empty(0, self.dtype_np)

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('cpu')
if paddle.is_compiled_with_cuda():
self.place.append('gpu')
self.place = get_places(string_format=True)

def init_setting(self):
self.dtype_np = 'float32'
Expand Down
36 changes: 4 additions & 32 deletions test/legacy_test/test_cauchy_inplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +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 get_places

import paddle
from paddle import base


class TestCauchyInplaceDtype(unittest.TestCase):
Expand All @@ -36,16 +35,7 @@ def test_fp64():
tensor_fp64.cauchy_()
self.assertEqual(tensor_fp64.dtype, paddle.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('cpu')
if base.core.is_compiled_with_cuda():
places.append('gpu')
for place in places:
for place in get_places(string_format=True):
paddle.set_device(place)
test_fp32()
test_fp64()
Expand Down Expand Up @@ -101,17 +91,8 @@ def test_cauchy_inplace_distribution(self):

class TestCauchyInplaceEmptyTensor(unittest.TestCase):
def test_cauchy_inplace_op_empty_tensor(self):
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('cpu')
if base.core.is_compiled_with_cuda():
places.append('gpu')
test_shapes = [(200, 1), (1, 200)]
for place in places:
for place in get_places(string_format=True):
paddle.set_device(place)
for test_shape in test_shapes:
tensor = paddle.empty(shape=test_shape)
Expand All @@ -137,16 +118,7 @@ def test_grad():
cauchy_grad = tensor_b.grad.numpy()
self.assertTrue((cauchy_grad == 0).all())

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('cpu')
if base.core.is_compiled_with_cuda():
places.append('gpu')
for place in places:
for place in get_places(string_format=True):
paddle.set_device(place)
test_grad()

Expand Down
22 changes: 3 additions & 19 deletions test/legacy_test/test_combinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
# 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 random
import unittest
from itertools import combinations, combinations_with_replacement

import numpy as np
from op_test import get_places

import paddle
from paddle.base import Program
Expand Down Expand Up @@ -47,15 +47,7 @@ def setUp(self):
self.modify_setting()
self.x_np = np.random.random(self.x_shape).astype(self.dtype_np)

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('cpu')
if paddle.is_compiled_with_cuda():
self.place.append('gpu')
self.place = get_places(string_format=True)

def init_setting(self):
self.dtype_np = 'float64'
Expand Down Expand Up @@ -128,15 +120,7 @@ def modify_setting(self):

class TestCombinationsEmpty(unittest.TestCase):
def setUp(self):
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('cpu')
if paddle.is_compiled_with_cuda():
self.place.append('gpu')
self.place = get_places(string_format=True)

def test_dygraph(self):
paddle.disable_static()
Expand Down
13 changes: 2 additions & 11 deletions test/legacy_test/test_complex_matmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,19 @@
# 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
import paddle.base.dygraph as dg
from paddle import base


class TestComplexMatMulLayer(unittest.TestCase):
def setUp(self):
self._dtypes = ["float32", "float64"]
self._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()
):
self._places.append(base.CPUPlace())
if base.core.is_compiled_with_cuda():
self._places.append(base.CUDAPlace(0))
self._places = get_places()

def compare_by_basic_api(self, x, y, np_result):
for place in self._places:
Expand Down
19 changes: 3 additions & 16 deletions test/legacy_test/test_complex_view_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +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 OpTest
from op_test import OpTest, get_places

import paddle
from paddle import static
from paddle.base import core, dygraph
from paddle.base import dygraph

paddle.enable_static()

Expand Down Expand Up @@ -123,24 +122,12 @@ def test_static(self):


class TestViewAsRealAPI_ZeroSize(unittest.TestCase):
def get_places(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))
return places

def setUp(self):
self.x = np.random.randn(10, 0) + 1j * np.random.randn(10, 0)
self.out = ref_view_as_real(self.x)

def test_dygraph(self):
for place in self.get_places():
for place in get_places():
with dygraph.guard(place):
x_tensor = paddle.to_tensor(self.x)
x_tensor.stop_gradient = False
Expand Down
Loading
Loading