diff --git a/tests/st/ops/gpu/test_argmax_op.py b/tests/st/ops/gpu/test_argmax_op.py index 96f94c54f3..7b90bc4eaa 100644 --- a/tests/st/ops/gpu/test_argmax_op.py +++ b/tests/st/ops/gpu/test_argmax_op.py @@ -48,15 +48,15 @@ def test_argmax(): expect2 = np.array([1, 0, 0, 0]).astype(np.int32) context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") - Argmax = NetArgmax() - output = Argmax(x) + argmax = NetArgmax() + output = argmax(x) assert (output[0].asnumpy() == expect1).all() assert (output[1].asnumpy() == expect2).all() assert (output[2].asnumpy() == expect2).all() context.set_context(mode=context.GRAPH_MODE, device_target="GPU") - Argmax1 = NetArgmax() - output1 = Argmax(x) + argmax1 = NetArgmax() + output1 = argmax1(x) assert (output1[0].asnumpy() == expect1).all() assert (output1[1].asnumpy() == expect2).all() assert (output1[2].asnumpy() == expect2).all() diff --git a/tests/st/ops/gpu/test_assign_op.py b/tests/st/ops/gpu/test_assign_op.py index 74c2ebafbf..5beccde8fd 100644 --- a/tests/st/ops/gpu/test_assign_op.py +++ b/tests/st/ops/gpu/test_assign_op.py @@ -23,13 +23,13 @@ from mindspore.ops import operations as P class Net(nn.Cell): - def __init__(self, value): + def __init__(self, param): super(Net, self).__init__() - self.var = Parameter(value, name="var") + self.var = Parameter(param, name="var") self.assign = P.Assign() - def construct(self, value): - return self.assign(self.var, value) + def construct(self, param): + return self.assign(self.var, param) x = np.array([[1.2, 1], [1, 0]]).astype(np.float32) diff --git a/tests/st/ops/gpu/test_batch_matmul.py b/tests/st/ops/gpu/test_batch_matmul.py index ee7ab24995..361280dd9b 100644 --- a/tests/st/ops/gpu/test_batch_matmul.py +++ b/tests/st/ops/gpu/test_batch_matmul.py @@ -20,9 +20,6 @@ import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor from mindspore.common import dtype as mstype -from mindspore.common.api import ms_function -from mindspore.common.initializer import initializer -from mindspore.common.parameter import Parameter from mindspore.ops import operations as P @@ -38,7 +35,7 @@ class BatchMatMulNet(nn.Cell): return self.batch_matmul(x, y) -def test_4D(): +def test_4d(): input_x = Tensor(np.arange(2 * 4 * 1 * 3).reshape(2, 4, 1, 3), mstype.float32) input_y = Tensor(np.arange(2 * 4 * 3 * 4).reshape(2, 4, 3, 4), mstype.float32) @@ -60,7 +57,7 @@ def test_4D(): @pytest.mark.level0 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard -def test_4D_transpose_a(): +def test_4d_transpose_a(): input_x = Tensor(np.arange(2 * 4 * 3 * 1).reshape(2, 4, 3, 1), mstype.float32) input_y = Tensor(np.arange(2 * 4 * 3 * 4).reshape(2, 4, 3, 4), mstype.float32) @@ -82,7 +79,7 @@ def test_4D_transpose_a(): @pytest.mark.level0 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard -def test_4D_transpose_b(): +def test_4d_transpose_b(): input_x = Tensor(np.arange(2 * 4 * 1 * 3).reshape(2, 4, 1, 3), mstype.float32) input_y = Tensor(np.arange(2 * 4 * 4 * 3).reshape(2, 4, 4, 3), mstype.float32) @@ -104,7 +101,7 @@ def test_4D_transpose_b(): @pytest.mark.level0 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard -def test_4D_transpose_ab(): +def test_4d_transpose_ab(): input_x = Tensor(np.arange(2 * 4 * 3 * 1).reshape(2, 4, 3, 1), mstype.float32) input_y = Tensor(np.arange(2 * 4 * 4 * 3).reshape(2, 4, 4, 3), mstype.float32) @@ -122,17 +119,7 @@ def test_4D_transpose_ab(): [[5612, 5810, 6008, 6206]]]] assert (output.asnumpy() == expect).all() - -class BatchMatMulNet(nn.Cell): - def __init__(self, transpose_a=False, transpose_b=False): - super(BatchMatMulNet, self).__init__() - self.batch_matmul = P.BatchMatMul(transpose_a, transpose_b) - - def construct(self, x, y): - return self.batch_matmul(x, y) - - -def test_4D_fp16(): +def test_4d_fp16(): input_x = Tensor(np.arange(2 * 4 * 1 * 3).reshape(2, 4, 1, 3), mstype.float16) input_y = Tensor(np.arange(2 * 4 * 3 * 4).reshape(2, 4, 3, 4), mstype.float16) diff --git a/tests/st/ops/gpu/test_batchnorm_fold2_op.py b/tests/st/ops/gpu/test_batchnorm_fold2_op.py index eaaf10ef07..47b11b7b7a 100644 --- a/tests/st/ops/gpu/test_batchnorm_fold2_op.py +++ b/tests/st/ops/gpu/test_batchnorm_fold2_op.py @@ -68,10 +68,10 @@ def test_batchnrom_fold2(): current_step = np.array([0]).astype('int32') output = net(Tensor(x), Tensor(beta), Tensor(gamma), Tensor(batch_std), Tensor(batch_mean), Tensor(running_std), Tensor(running_mean), Tensor(current_step)) - expect = (x + beta.reshape(-1, 1, 1) - (gamma * running_mean / running_std).reshape(-1, 1, - 1) if current_step >= freeze_bn else - x * (running_std / batch_std).reshape(-1, 1, 1) + (beta - gamma * batch_mean / batch_std).reshape(-1, 1, - 1)) + expect = ((x + beta.reshape(-1, 1, 1) - + (gamma * running_mean / running_std).reshape(-1, 1, 1) if current_step >= freeze_bn else + x * (running_std / batch_std).reshape(-1, 1, 1) + + (beta - gamma * batch_mean / batch_std).reshape(-1, 1, 1))) error = np.ones(shape=expect.shape) * 1.0e-6 diff = output.asnumpy() - expect assert np.all(diff < error) @@ -80,10 +80,9 @@ def test_batchnrom_fold2(): current_step = np.array([100000]).astype('int32') output = net(Tensor(x), Tensor(beta), Tensor(gamma), Tensor(batch_std), Tensor(batch_mean), Tensor(running_std), Tensor(running_mean), Tensor(current_step)) - expect = (x + beta.reshape(-1, 1, 1) - (gamma * running_mean / running_std).reshape(-1, 1, - 1) if current_step >= freeze_bn else - x * (batch_std / running_std).reshape(-1, 1, 1) + (beta - gamma * batch_mean / batch_std).reshape(-1, 1, - 1)) + expect = ((x + beta.reshape(-1, 1, 1) - (gamma * running_mean / running_std).reshape(-1, 1, 1) + if current_step >= freeze_bn else x * (batch_std / running_std).reshape(-1, 1, 1) + + (beta - gamma * batch_mean / batch_std).reshape(-1, 1, 1))) error = np.ones(shape=expect.shape) * 1.0e-6 diff = output.asnumpy() - expect assert np.all(diff < error) diff --git a/tests/st/ops/gpu/test_batchnorm_fold_grad_op.py b/tests/st/ops/gpu/test_batchnorm_fold_grad_op.py index 8bf623371d..5d20a95ac0 100644 --- a/tests/st/ops/gpu/test_batchnorm_fold_grad_op.py +++ b/tests/st/ops/gpu/test_batchnorm_fold_grad_op.py @@ -38,8 +38,8 @@ class Net(nn.Cell): def np_result(d_batch_mean, d_batch_std, x, batch_mean, batch_std): n = x.shape[0] * x.shape[2] * x.shape[3] - dx = d_batch_mean.reshape(1, -1, 1, 1) / n + d_batch_std.reshape(1, -1, 1, 1) * ( - x - batch_mean.reshape(1, -1, 1, 1)) / batch_std.reshape(1, -1, 1, 1) / n + dx = (d_batch_mean.reshape(1, -1, 1, 1) / n + d_batch_std.reshape(1, -1, 1, 1) * + (x - batch_mean.reshape(1, -1, 1, 1)) / batch_std.reshape(1, -1, 1, 1) / n) return dx diff --git a/tests/st/ops/gpu/test_batchnorm_fold_op.py b/tests/st/ops/gpu/test_batchnorm_fold_op.py index f7e1a2deb8..0572a3b901 100644 --- a/tests/st/ops/gpu/test_batchnorm_fold_op.py +++ b/tests/st/ops/gpu/test_batchnorm_fold_op.py @@ -86,7 +86,7 @@ def test_batchnorm_fold2(): ms_var = Tensor(variance) batch_mean, batch_var, delay_mean, delay_std = net(Tensor(x), ms_mean, ms_var, Tensor(current_step)) - expect1, expect2, expect3, expect4, expect5, expect6 = np_result(x, mean, variance, 0.9, 1e-12) + expect1, expect2, expect3, _, expect5, expect6 = np_result(x, mean, variance, 0.9, 1e-12) assert np.allclose(batch_mean.asnumpy(), expect1, rtol=1.e-7, atol=1.e-5) assert np.allclose(batch_var.asnumpy(), expect2, rtol=1.e-7, atol=1.e-5) assert np.allclose(ms_mean.asnumpy(), expect3, rtol=1.e-7, atol=1.e-5) @@ -108,7 +108,7 @@ def test_batchnorm_fold_freeze(): ms_var = Tensor(variance) batch_mean, batch_var, delay_mean, delay_std = net(Tensor(x), ms_mean, ms_var, Tensor(current_step)) - expect1, expect2, expect3, expect4, expect5, expect6 = np_result(x, mean, variance, 0.9, 1e-12) + _, _, _, _, expect5, expect6 = np_result(x, mean, variance, 0.9, 1e-12) assert np.allclose(batch_mean.asnumpy(), np.zeros_like(mean), rtol=1.e-7, atol=1.e-5) assert np.allclose(batch_var.asnumpy(), np.ones_like(mean), rtol=1.e-7, atol=1.e-5) assert np.allclose(ms_mean.asnumpy(), mean, rtol=1.e-7, atol=1.e-5) diff --git a/tests/st/ops/gpu/test_batchnorm_op.py b/tests/st/ops/gpu/test_batchnorm_op.py index 28689bfe0e..0aeac6dfcc 100644 --- a/tests/st/ops/gpu/test_batchnorm_op.py +++ b/tests/st/ops/gpu/test_batchnorm_op.py @@ -61,9 +61,6 @@ def test_train_forward(): [-0.0281, 0.9119, 1.3819, 1.8518], [2.7918, 0.4419, -0.4981, 0.9119], [1.8518, 0.9119, 2.3218, -0.9680]]]]).astype(np.float32) - grad = np.array([[ - [[1, 2, 7, 1], [4, 2, 1, 3], [1, 6, 5, 2], [2, 4, 3, 2]], - [[9, 4, 3, 5], [1, 3, 7, 6], [5, 7, 9, 9], [1, 4, 6, 8]]]]).astype(np.float32) weight = np.ones(2).astype(np.float32) bias = np.ones(2).astype(np.float32) diff --git a/tests/st/ops/gpu/test_broadcast_op.py b/tests/st/ops/gpu/test_broadcast_op.py index e102d17ff3..3f97a229e8 100644 --- a/tests/st/ops/gpu/test_broadcast_op.py +++ b/tests/st/ops/gpu/test_broadcast_op.py @@ -16,10 +16,8 @@ import numpy as np import pytest -import mindspore.common.dtype as mstype import mindspore.context as context from mindspore.common.tensor import Tensor -from mindspore.nn import Cell from mindspore.ops import operations as P diff --git a/tests/st/ops/gpu/test_cast_op.py b/tests/st/ops/gpu/test_cast_op.py index e7a0563b15..4e1d32d9da 100644 --- a/tests/st/ops/gpu/test_cast_op.py +++ b/tests/st/ops/gpu/test_cast_op.py @@ -47,9 +47,9 @@ def test_cast(): net = Net() output = net(x0, t0, x1, t1) type0 = output[0].asnumpy().dtype - assert (type0 == 'float16') + assert type0 == 'float16' type1 = output[1].asnumpy().dtype - assert (type1 == 'float32') + assert type1 == 'float32' @pytest.mark.level0 @@ -65,6 +65,6 @@ def test_cast1(): net = Net() output = net(x0, t0, x1, t1) type0 = output[0].asnumpy().dtype - assert (type0 == 'float32') + assert type0 == 'float32' type1 = output[1].asnumpy().dtype - assert (type1 == 'float32') + assert type1 == 'float32' diff --git a/tests/st/ops/gpu/test_conv2d_backprop_filter_op.py b/tests/st/ops/gpu/test_conv2d_backprop_filter_op.py index a545bd841a..3d95c47a97 100644 --- a/tests/st/ops/gpu/test_conv2d_backprop_filter_op.py +++ b/tests/st/ops/gpu/test_conv2d_backprop_filter_op.py @@ -66,13 +66,6 @@ def test_conv2d_backprop_filter(): [-3, -2, -3, -16]]]]).astype(np.float32)) conv2d_filter = Conv2dFilter() output = conv2d_filter(out, x, w) - print("================================") - """ - expect output: - [[[[ -60, -142, -265] - [-104, -211, -322] - [-102, -144, -248]]]] - """ expect = np.array([[[[-60, -142, -265], [-104, -211, -322], [-102, -144, -248]]]]).astype(np.float32) diff --git a/tests/st/ops/gpu/test_conv2d_backprop_input_op.py b/tests/st/ops/gpu/test_conv2d_backprop_input_op.py index bbe672a079..1b66fb4795 100644 --- a/tests/st/ops/gpu/test_conv2d_backprop_input_op.py +++ b/tests/st/ops/gpu/test_conv2d_backprop_input_op.py @@ -20,8 +20,6 @@ import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor from mindspore.common.api import ms_function -from mindspore.common.initializer import initializer -from mindspore.common.parameter import Parameter from mindspore.ops import operations as P context.set_context(device_target='GPU') diff --git a/tests/st/ops/gpu/test_conv2d_op.py b/tests/st/ops/gpu/test_conv2d_op.py index 850c8968a2..a42114a106 100644 --- a/tests/st/ops/gpu/test_conv2d_op.py +++ b/tests/st/ops/gpu/test_conv2d_op.py @@ -57,16 +57,6 @@ def test_conv2d(): conv2d = NetConv2d() output = conv2d(x, w) assert (output.asnumpy() == expect).all() - """ - expect output: - [[[[ 45. 48. 51.] - [ 54. 57. 60.] - [ 63. 66. 69.]] - - [[126. 138. 150.] - [162. 174. 186.] - [198. 210. 222.]]]] - """ context.set_context(mode=context.GRAPH_MODE, device_target="GPU") conv2d = NetConv2d() output = conv2d(x, w) diff --git a/tests/st/ops/gpu/test_correction_mul_grad_op.py b/tests/st/ops/gpu/test_correction_mul_grad_op.py index 531e51ed2e..0bb825a3b4 100644 --- a/tests/st/ops/gpu/test_correction_mul_grad_op.py +++ b/tests/st/ops/gpu/test_correction_mul_grad_op.py @@ -14,7 +14,6 @@ # ============================================================================ import numpy as np -import os import pytest import mindspore.context as context @@ -51,5 +50,5 @@ def test_correction_mul_grad(): expect = [0, 0] expect[0] = (dout * np.reshape(batch_std / running_std, (co, 1, 1, 1))) expect[1] = (np.sum(dout * x, (1, 2, 3)) / running_std) - for i, v in enumerate(output): - assert (np.allclose(output[i].asnumpy(), expect[i], rtol=1.e-5, atol=1.e-5)) + for i, _ in enumerate(output): + assert np.allclose(output[i].asnumpy(), expect[i], rtol=1.e-5, atol=1.e-5) diff --git a/tests/st/ops/gpu/test_correction_mul_op.py b/tests/st/ops/gpu/test_correction_mul_op.py index 9a5ab6728b..f505c62650 100644 --- a/tests/st/ops/gpu/test_correction_mul_op.py +++ b/tests/st/ops/gpu/test_correction_mul_op.py @@ -50,4 +50,4 @@ def test_correction_mul(): diff = output.asnumpy() - expect assert np.all(diff < error) assert np.all(diff > error * -1) - assert (output.shape() == expect.shape) + assert output.shape() == expect.shape diff --git a/tests/st/ops/gpu/test_dense_op.py b/tests/st/ops/gpu/test_dense_op.py index 700f41ea32..125b273a82 100644 --- a/tests/st/ops/gpu/test_dense_op.py +++ b/tests/st/ops/gpu/test_dense_op.py @@ -68,8 +68,8 @@ class GradData(nn.Cell): self.grad = GradOperation(name="get_all", get_all=True, sens_param=True) self.network = network - def construct(self, input, output_grad): - return self.grad(self.network)(input, output_grad) + def construct(self, inputs, output_grad): + return self.grad(self.network)(inputs, output_grad) class GradWeight(nn.Cell): @@ -172,8 +172,8 @@ class Grad(nn.Cell): self.grad = GradOperation(name="get_all", get_all=True, sens_param=True) self.network = network - def construct(self, input, bias, dy): - return self.grad(self.network)(input, bias, dy) + def construct(self, inputs, bias, dy): + return self.grad(self.network)(inputs, bias, dy) @pytest.mark.level0 diff --git a/tests/st/ops/gpu/test_equal_op.py b/tests/st/ops/gpu/test_equal_op.py index 62dfeee1eb..ad627c666d 100644 --- a/tests/st/ops/gpu/test_equal_op.py +++ b/tests/st/ops/gpu/test_equal_op.py @@ -50,16 +50,16 @@ def test_equal(): equal = NetEqual() output0 = equal(x0, y0) assert np.all(output0.asnumpy() == expect0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = equal(x1, y1) assert np.all(output1.asnumpy() == expect1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape context.set_context(mode=context.GRAPH_MODE, device_target="GPU") equal = NetEqual() output0 = equal(x0, y0) assert np.all(output0.asnumpy() == expect0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = equal(x1, y1) assert np.all(output1.asnumpy() == expect1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape diff --git a/tests/st/ops/gpu/test_exp_op.py b/tests/st/ops/gpu/test_exp_op.py index d87ea47c6c..ea205c707a 100644 --- a/tests/st/ops/gpu/test_exp_op.py +++ b/tests/st/ops/gpu/test_exp_op.py @@ -49,19 +49,19 @@ def test_exp(): output0 = exp(x0) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = exp(x1) diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") exp = NetExp() output0 = exp(x0) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = exp(x1) diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape diff --git a/tests/st/ops/gpu/test_flatten_grad_op.py b/tests/st/ops/gpu/test_flatten_grad_op.py index d55c59c384..0ee6c40318 100644 --- a/tests/st/ops/gpu/test_flatten_grad_op.py +++ b/tests/st/ops/gpu/test_flatten_grad_op.py @@ -19,7 +19,6 @@ import pytest import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor -from mindspore.ops import operations as P from mindspore.ops.operations import _grad_ops as G @@ -38,11 +37,6 @@ class NetFlattenGrad(nn.Cell): @pytest.mark.env_onecard def test_flatten_grad(): x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]).astype(np.float32)) - """ - expect output: - [ [-0.1 0.3 3.6] - [ 0.4 0.5 -3.2] ] - """ expect = np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]).astype(np.float32) diff --git a/tests/st/ops/gpu/test_flatten_op.py b/tests/st/ops/gpu/test_flatten_op.py index 1c033a471a..3d8ba96b7f 100644 --- a/tests/st/ops/gpu/test_flatten_op.py +++ b/tests/st/ops/gpu/test_flatten_op.py @@ -37,11 +37,6 @@ class NetFlatten(nn.Cell): def test_flatten(): x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]).astype(np.float32)) expect = np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]).astype(np.float32) - """ - expect output: - [[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]] - """ - context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") flatten = NetFlatten() output = flatten(x) diff --git a/tests/st/ops/gpu/test_float_status_op.py b/tests/st/ops/gpu/test_float_status_op.py index 5ba2013058..65689577c4 100644 --- a/tests/st/ops/gpu/test_float_status_op.py +++ b/tests/st/ops/gpu/test_float_status_op.py @@ -68,7 +68,7 @@ x3 = np.array([[1, 2], [3, 4], [5.0, 88.0]]).astype(np.float32) @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard def test_status(): - ms_status = Net(); + ms_status = Net() output1 = ms_status(Tensor(x1)) output2 = ms_status(Tensor(x2)) output3 = ms_status(Tensor(x3)) @@ -84,7 +84,7 @@ def test_status(): @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard def test_nan(): - ms_isnan = Netnan(); + ms_isnan = Netnan() output1 = ms_isnan(Tensor(x1)) output2 = ms_isnan(Tensor(x2)) output3 = ms_isnan(Tensor(x3)) @@ -100,7 +100,7 @@ def test_nan(): @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard def test_inf(): - ms_isinf = Netinf(); + ms_isinf = Netinf() output1 = ms_isinf(Tensor(x1)) output2 = ms_isinf(Tensor(x2)) output3 = ms_isinf(Tensor(x3)) @@ -116,7 +116,7 @@ def test_inf(): @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard def test_finite(): - ms_isfinite = Netfinite(); + ms_isfinite = Netfinite() output1 = ms_isfinite(Tensor(x1)) output2 = ms_isfinite(Tensor(x2)) output3 = ms_isfinite(Tensor(x3)) diff --git a/tests/st/ops/gpu/test_gather_op.py b/tests/st/ops/gpu/test_gather_op.py index 8d11cb32c6..5c882a6567 100644 --- a/tests/st/ops/gpu/test_gather_op.py +++ b/tests/st/ops/gpu/test_gather_op.py @@ -913,16 +913,16 @@ class GatherNet2(nn.Cell): @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard def test_gather2(): - x = Tensor(np.array([[4., 5., 4., 1., 5., ], - [4., 9., 5., 6., 4., ], - [9., 8., 4., 3., 6., ], - [0., 4., 2., 2., 8., ], - [1., 8., 6., 2., 8., ], - [8., 1., 9., 7., 3., ], - [7., 9., 2., 5., 7., ], - [9., 8., 6., 8., 5., ], - [3., 7., 2., 7., 4., ], - [4., 2., 8., 2., 9., ]] + x = Tensor(np.array([[4., 5., 4., 1., 5.,], + [4., 9., 5., 6., 4.,], + [9., 8., 4., 3., 6.,], + [0., 4., 2., 2., 8.,], + [1., 8., 6., 2., 8.,], + [8., 1., 9., 7., 3.,], + [7., 9., 2., 5., 7.,], + [9., 8., 6., 8., 5.,], + [3., 7., 2., 7., 4.,], + [4., 2., 8., 2., 9.,]] ).astype(np.float32)) indices = Tensor(np.array([[4000, 1, 300000]]).astype(np.int32)) diff --git a/tests/st/ops/gpu/test_layer_norm_grad_op.py b/tests/st/ops/gpu/test_layer_norm_grad_op.py index 91397a2fd2..032dee50ac 100644 --- a/tests/st/ops/gpu/test_layer_norm_grad_op.py +++ b/tests/st/ops/gpu/test_layer_norm_grad_op.py @@ -19,8 +19,6 @@ import pytest import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor -from mindspore.ops import composite as C -from mindspore.ops import operations as P from mindspore.ops.operations import _grad_ops as G context.set_context(mode=context.GRAPH_MODE, device_target="GPU") diff --git a/tests/st/ops/gpu/test_log_op.py b/tests/st/ops/gpu/test_log_op.py index 33ab09af9d..00007b4330 100644 --- a/tests/st/ops/gpu/test_log_op.py +++ b/tests/st/ops/gpu/test_log_op.py @@ -50,10 +50,10 @@ def test_log(): output1 = log(x1) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape context.set_context(mode=context.GRAPH_MODE, device_target="GPU") log = NetLog() @@ -61,7 +61,7 @@ def test_log(): output1 = log(x1) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape diff --git a/tests/st/ops/gpu/test_logical_op.py b/tests/st/ops/gpu/test_logical_op.py index 015238783e..1de7a7f870 100644 --- a/tests/st/ops/gpu/test_logical_op.py +++ b/tests/st/ops/gpu/test_logical_op.py @@ -27,8 +27,8 @@ class NetAnd(Cell): super(NetAnd, self).__init__() self.logicaland = P.LogicalAnd() - def construct(self, x, y): - return self.logicaland(x, y) + def construct(self, input_x, input_y): + return self.logicaland(input_x, input_y) class NetOr(Cell): @@ -36,8 +36,8 @@ class NetOr(Cell): super(NetOr, self).__init__() self.logicalor = P.LogicalOr() - def construct(self, x, y): - return self.logicalor(x, y) + def construct(self, input_x, input_y): + return self.logicalor(input_x, input_y) class NetNot(Cell): @@ -45,8 +45,8 @@ class NetNot(Cell): super(NetNot, self).__init__() self.logicalnot = P.LogicalNot() - def construct(self, x): - return self.logicalnot(x) + def construct(self, input_x): + return self.logicalnot(input_x) x = np.array([True, False, False]).astype(np.bool) diff --git a/tests/st/ops/gpu/test_logsoftmax_op.py b/tests/st/ops/gpu/test_logsoftmax_op.py index 83e59beb63..5834f90a10 100644 --- a/tests/st/ops/gpu/test_logsoftmax_op.py +++ b/tests/st/ops/gpu/test_logsoftmax_op.py @@ -35,8 +35,8 @@ def test_logsoftmax(): [-3.452001, -1.2546989, -1.4618242, -0.79552734]]).astype(np.float32) context.set_context(mode=context.GRAPH_MODE, device_target="GPU") - LogSoftmax = P.LogSoftmax() - output = LogSoftmax(Tensor(x)) + logSoftmax = P.LogSoftmax() + output = logSoftmax(Tensor(x)) assert np.allclose(output.asnumpy(), expect) @@ -134,7 +134,7 @@ def test_logsoftmaxgrad1(): [-0.01768187, 0.26872346, -0.5037259, -0.3376058, -0.3291146, 1.4752979, -0.25972134, 0.8869053, 0.25325722, -0.13946185], [-0.5247209, 0.70192003, -1.0808672, 1.4858199, -1.1273282, 0.20728993, 0.38918605, 0.08162117, - 0.10445589, 0.3220427]], ).astype(np.float32) + 0.10445589, 0.3220427]],).astype(np.float32) context.set_context(mode=context.GRAPH_MODE, device_target="GPU") net = LogSoftmax(0) diff --git a/tests/st/ops/gpu/test_lstm_op.py b/tests/st/ops/gpu/test_lstm_op.py index e796a526d3..d73850668e 100644 --- a/tests/st/ops/gpu/test_lstm_op.py +++ b/tests/st/ops/gpu/test_lstm_op.py @@ -23,7 +23,6 @@ from mindspore.common.initializer import initializer from mindspore.common.parameter import ParameterTuple, Parameter from mindspore.common.tensor import Tensor from mindspore.ops import composite as C -from mindspore.ops import functional as F from mindspore.ops import operations as P context.set_context(device_target='GPU') @@ -81,7 +80,7 @@ class LstmNet(nn.Cell): -2.9055e-01, -2.8129e-01, 6.0219e-01, 4.9193e-01, 3.3115e-01], [-5.6894e-01, -5.0359e-01, 4.7491e-01, 5.8110e-01, -5.4921e-01, -6.1343e-01, -5.8236e-02, -3.7682e-01, 4.8338e-01, -2.1551e-01]]).astype(np.float32).reshape( - [1, -1]) + [1, -1]) whh = np.array([[-0.4820, -0.2350], [-0.1195, 0.0519], @@ -205,7 +204,7 @@ class BiLstmNet(nn.Cell): [0.0299, -0.6071, -0.4683, -0.3363, -0.0044, -0.0007, 0.2700, 0.0202, -0.2880, -0.6869], [0.3025, -0.2461, -0.5128, 0.6327, -0.1438, -0.5100, 0.1924, 0.2023, 0.3129, 0.2271], [0.3777, 0.0546, 0.4790, -0.1895, 0.3588, 0.4490, 0.6850, 0.6240, -0.2739, -0.4474]]).astype( - np.float32).reshape([1, -1]) + np.float32).reshape([1, -1]) whh = np.array([[0.6346, -0.6366], [-0.0248, -0.6156], @@ -394,7 +393,7 @@ class MultiLayerBiLstmNet(nn.Cell): 5.5428e-01, 1.0429e-01, 5.1322e-01, 1.9406e-01], [3.9698e-01, -5.2101e-01, 5.1372e-01, -3.9866e-01, 1.0115e-01, -4.1290e-02, -3.0980e-01, 2.1607e-01, 4.8420e-01, -1.9267e-01]]).astype(np.float32).reshape( - [1, -1]) + [1, -1]) whh_reverse_l0 = np.array([[-0.3231, -0.3960], [-0.1625, -0.3032], @@ -460,7 +459,7 @@ class MultiLayerBiLstmNet(nn.Cell): weight layer0 forward - wih + wih whh reverse wih @@ -662,7 +661,7 @@ class Net(nn.Cell): [-0.4520, 0.4201, -0.2374, -0.1556, -0.4175, -0.6834, 0.3096, -0.1581, 0.0127, 0.6872], [0.1788, -0.5442, -0.3675, -0.2887, -0.3004, 0.5813, 0.1618, 0.6875, -0.4678, 0.0071], [-0.6453, -0.2528, 0.5675, -0.5154, -0.4129, -0.0214, 0.5539, 0.0343, 0.1712, 0.5644]]).astype( - np.float32).reshape([1, -1]) + np.float32).reshape([1, -1]) whh_reverse_l0 = np.array([[-0.6657, 0.6330], [-0.2290, 0.6556], @@ -728,7 +727,7 @@ class Net(nn.Cell): weight layer0 forward - wih + wih whh reverse wih @@ -927,7 +926,7 @@ class LstmNetWithDropout(nn.Cell): [0.5142, 0.0790, -0.1123, -0.2351, 0.3982, -0.6351, 0.5906, 0.3917, -0.0850, -0.5397], [-0.4795, -0.6576, 0.5693, 0.0047, -0.6626, 0.1013, -0.4015, -0.4040, -0.2817, 0.4430], [0.0251, -0.3035, -0.6026, 0.2693, -0.2749, 0.1501, -0.5778, 0.5570, -0.7065, -0.6196]]).astype( - np.float32).reshape([1, -1]) + np.float32).reshape([1, -1]) whh = np.array([[-0.4344, -0.2529], [0.0377, 0.7046], diff --git a/tests/st/ops/gpu/test_maximum_op.py b/tests/st/ops/gpu/test_maximum_op.py index 6b869d981e..eafd9e5136 100644 --- a/tests/st/ops/gpu/test_maximum_op.py +++ b/tests/st/ops/gpu/test_maximum_op.py @@ -53,15 +53,15 @@ def test_maximum(): error = np.ones(shape=[1, 3]) * 1.0e-5 context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") - max = Net() - output = max(x, y) + max_op = Net() + output = max_op(x, y) diff = output.asnumpy() - expect assert np.all(diff < error) assert np.all(-diff < error) context.set_context(mode=context.GRAPH_MODE, device_target="GPU") - max = Net() - output = max(x, y) + max_op_2 = Net() + output = max_op_2(x, y) diff = output.asnumpy() - expect assert np.all(diff < error) assert np.all(-diff < error) diff --git a/tests/st/ops/gpu/test_maxpool_grad_gpu_op.py b/tests/st/ops/gpu/test_maxpool_grad_gpu_op.py index 6a99591f04..5b65f60964 100644 --- a/tests/st/ops/gpu/test_maxpool_grad_gpu_op.py +++ b/tests/st/ops/gpu/test_maxpool_grad_gpu_op.py @@ -19,7 +19,6 @@ import pytest import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor -from mindspore.ops import operations as P from mindspore.ops.operations import _grad_ops as G diff --git a/tests/st/ops/gpu/test_minimum_op.py b/tests/st/ops/gpu/test_minimum_op.py index b071b1759d..9ba8cc5309 100644 --- a/tests/st/ops/gpu/test_minimum_op.py +++ b/tests/st/ops/gpu/test_minimum_op.py @@ -16,7 +16,6 @@ import numpy as np import pytest -import mindspore.common.dtype as mstype import mindspore.context as context from mindspore.common.tensor import Tensor from mindspore.nn import Cell diff --git a/tests/st/ops/gpu/test_momentum_op.py b/tests/st/ops/gpu/test_momentum_op.py index 2ce6f9ee6e..d81e39a48c 100644 --- a/tests/st/ops/gpu/test_momentum_op.py +++ b/tests/st/ops/gpu/test_momentum_op.py @@ -57,17 +57,12 @@ def test_momentum(): train_network = TrainOneStepCell(net_with_criterion, optimizer) # optimizer train_network.set_train() losses = [] - for i in range(epoch): + for _ in range(epoch): data = Tensor(np.arange(0, 16).reshape(1, 1, 4, 4).astype(np.float32) * 0.01) label = Tensor(np.array([0]).astype(np.int32)) loss = train_network(data, label) losses.append(loss) - """ - expect output: - [[0.04132498 0.00874167 0.00874167 0.00874167 0.00874167 - 0.00874167 0.00874167 0.00874167 0.00874167 0.00874167]] - """ - error = np.ones(shape=[1, 10]) * 1.0e-6 + _ = np.ones(shape=[1, 10]) * 1.0e-6 return losses diff --git a/tests/st/ops/gpu/test_mul_op.py b/tests/st/ops/gpu/test_mul_op.py index d5929e5b3a..2fbd744d24 100644 --- a/tests/st/ops/gpu/test_mul_op.py +++ b/tests/st/ops/gpu/test_mul_op.py @@ -64,35 +64,35 @@ def test_mul(): diff0 = output0.asnumpy() - expect0 error0 = np.ones(shape=expect0.shape) * 1.0e-5 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = mul(x1, y1) expect1 = np.multiply(x1_np, y1_np) diff1 = output1.asnumpy() - expect1 error1 = np.ones(shape=expect1.shape) * 1.0e-5 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape output2 = mul(x2, y2) expect2 = np.multiply(x2_np, y2_np) diff2 = output2.asnumpy() - expect2 error2 = np.ones(shape=expect2.shape) * 1.0e-5 assert np.all(diff2 < error2) - assert (output2.shape() == expect2.shape) + assert output2.shape() == expect2.shape output3 = mul(x3, y3) expect3 = np.multiply(x3_np, y3_np) diff3 = output3.asnumpy() - expect3 error3 = np.ones(shape=expect3.shape) * 1.0e-5 assert np.all(diff3 < error3) - assert (output3.shape() == expect3.shape) + assert output3.shape() == expect3.shape output4 = mul(x4, y4) expect4 = np.multiply(x4_np, y4_np) diff4 = output4.asnumpy() - expect4 error4 = np.ones(shape=expect4.shape) * 1.0e-5 assert np.all(diff4 < error4) - assert (output4.shape() == expect4.shape) + assert output4.shape() == expect4.shape context.set_context(mode=context.GRAPH_MODE, device_target="GPU") mul = NetMul() @@ -101,32 +101,32 @@ def test_mul(): diff0 = output0.asnumpy() - expect0 error0 = np.ones(shape=expect0.shape) * 1.0e-5 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = mul(x1, y1) expect1 = np.multiply(x1_np, y1_np) diff1 = output1.asnumpy() - expect1 error1 = np.ones(shape=expect1.shape) * 1.0e-5 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape output2 = mul(x2, y2) expect2 = np.multiply(x2_np, y2_np) diff2 = output2.asnumpy() - expect2 error2 = np.ones(shape=expect2.shape) * 1.0e-5 assert np.all(diff2 < error2) - assert (output2.shape() == expect2.shape) + assert output2.shape() == expect2.shape output3 = mul(x3, y3) expect3 = np.multiply(x3_np, y3_np) diff3 = output3.asnumpy() - expect3 error3 = np.ones(shape=expect3.shape) * 1.0e-5 assert np.all(diff3 < error3) - assert (output3.shape() == expect3.shape) + assert output3.shape() == expect3.shape output4 = mul(x4, y4) expect4 = np.multiply(x4_np, y4_np) diff4 = output4.asnumpy() - expect4 error4 = np.ones(shape=expect4.shape) * 1.0e-5 assert np.all(diff4 < error4) - assert (output4.shape() == expect4.shape) + assert output4.shape() == expect4.shape diff --git a/tests/st/ops/gpu/test_neg_op.py b/tests/st/ops/gpu/test_neg_op.py index 6e34de4453..8d93c2d5f0 100644 --- a/tests/st/ops/gpu/test_neg_op.py +++ b/tests/st/ops/gpu/test_neg_op.py @@ -49,19 +49,19 @@ def test_neg(): output0 = neg(x0) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = neg(x1) diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape context.set_context(mode=context.GRAPH_MODE, device_target="GPU") neg = NetNeg() output0 = neg(x0) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = neg(x1) diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape diff --git a/tests/st/ops/gpu/test_one_hot_op.py b/tests/st/ops/gpu/test_one_hot_op.py index 052e6ea34b..59acb35875 100644 --- a/tests/st/ops/gpu/test_one_hot_op.py +++ b/tests/st/ops/gpu/test_one_hot_op.py @@ -20,7 +20,6 @@ import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor from mindspore.common.api import ms_function -from mindspore.ops import operations as P context.set_context(device_target='GPU') diff --git a/tests/st/ops/gpu/test_realdiv_op.py b/tests/st/ops/gpu/test_realdiv_op.py index f911d78489..9268660260 100644 --- a/tests/st/ops/gpu/test_realdiv_op.py +++ b/tests/st/ops/gpu/test_realdiv_op.py @@ -19,9 +19,6 @@ import pytest import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor -from mindspore.common.api import ms_function -from mindspore.common.initializer import initializer -from mindspore.common.parameter import Parameter from mindspore.ops import operations as P @@ -67,35 +64,35 @@ def test_real_div(): diff0 = output0.asnumpy() - expect0 error0 = np.ones(shape=expect0.shape) * 1.0e-5 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = real_div(x1, y1) expect1 = np.divide(x1_np, y1_np) diff1 = output1.asnumpy() - expect1 error1 = np.ones(shape=expect1.shape) * 1.0e-5 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape output2 = real_div(x2, y2) expect2 = np.divide(x2_np, y2_np) diff2 = output2.asnumpy() - expect2 error2 = np.ones(shape=expect2.shape) * 1.0e-5 assert np.all(diff2 < error2) - assert (output2.shape() == expect2.shape) + assert output2.shape() == expect2.shape output3 = real_div(x3, y3) expect3 = np.divide(x3_np, y3_np) diff3 = output3.asnumpy() - expect3 error3 = np.ones(shape=expect3.shape) * 1.0e-5 assert np.all(diff3 < error3) - assert (output3.shape() == expect3.shape) + assert output3.shape() == expect3.shape output4 = real_div(x4, y4) expect4 = np.divide(x4_np, y4_np) diff4 = output4.asnumpy() - expect4 error4 = np.ones(shape=expect4.shape) * 1.0e-5 assert np.all(diff4 < error4) - assert (output4.shape() == expect4.shape) + assert output4.shape() == expect4.shape context.set_context(mode=context.PYNATIVE_MODE, device_target='GPU') real_div = NetRealDiv() @@ -104,32 +101,32 @@ def test_real_div(): diff0 = output0.asnumpy() - expect0 error0 = np.ones(shape=expect0.shape) * 1.0e-5 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = real_div(x1, y1) expect1 = np.divide(x1_np, y1_np) diff1 = output1.asnumpy() - expect1 error1 = np.ones(shape=expect1.shape) * 1.0e-5 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape output2 = real_div(x2, y2) expect2 = np.divide(x2_np, y2_np) diff2 = output2.asnumpy() - expect2 error2 = np.ones(shape=expect2.shape) * 1.0e-5 assert np.all(diff2 < error2) - assert (output2.shape() == expect2.shape) + assert output2.shape() == expect2.shape output3 = real_div(x3, y3) expect3 = np.divide(x3_np, y3_np) diff3 = output3.asnumpy() - expect3 error3 = np.ones(shape=expect3.shape) * 1.0e-5 assert np.all(diff3 < error3) - assert (output3.shape() == expect3.shape) + assert output3.shape() == expect3.shape output4 = real_div(x4, y4) expect4 = np.divide(x4_np, y4_np) diff4 = output4.asnumpy() - expect4 error4 = np.ones(shape=expect4.shape) * 1.0e-5 assert np.all(diff4 < error4) - assert (output4.shape() == expect4.shape) + assert output4.shape() == expect4.shape diff --git a/tests/st/ops/gpu/test_reciprocal_op.py b/tests/st/ops/gpu/test_reciprocal_op.py index 83d9b52ece..b03558cf4e 100644 --- a/tests/st/ops/gpu/test_reciprocal_op.py +++ b/tests/st/ops/gpu/test_reciprocal_op.py @@ -49,19 +49,19 @@ def test_Reciprocal(): output0 = reciprocal(x0) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = reciprocal(x1) diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape context.set_context(mode=context.GRAPH_MODE, device_target="GPU") reciprocal = NetReciprocal() output0 = reciprocal(x0) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = reciprocal(x1) diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape diff --git a/tests/st/ops/gpu/test_reduce_max_op.py b/tests/st/ops/gpu/test_reduce_max_op.py index 600e872b5d..b2ab808c79 100644 --- a/tests/st/ops/gpu/test_reduce_max_op.py +++ b/tests/st/ops/gpu/test_reduce_max_op.py @@ -128,43 +128,43 @@ def test_ReduceMax(): diff0 = abs(output[0].asnumpy() - expect0) error0 = np.ones(shape=expect0.shape) * 1.0e-5 assert np.all(diff0 < error0) - assert (output[0].shape() == expect0.shape) + assert output[0].shape() == expect0.shape expect1 = np.max(x1, axis=axis1, keepdims=keep_dims1) diff1 = abs(output[1].asnumpy() - expect1) error1 = np.ones(shape=expect1.shape) * 1.0e-5 assert np.all(diff1 < error1) - assert (output[1].shape() == expect1.shape) + assert output[1].shape() == expect1.shape expect2 = np.max(x2, axis=axis2, keepdims=keep_dims2) diff2 = abs(output[2].asnumpy() - expect2) error2 = np.ones(shape=expect2.shape) * 1.0e-5 assert np.all(diff2 < error2) - assert (output[2].shape() == expect2.shape) + assert output[2].shape() == expect2.shape expect3 = np.max(x3, axis=axis3, keepdims=keep_dims3) diff3 = abs(output[3].asnumpy() - expect3) error3 = np.ones(shape=expect3.shape) * 1.0e-5 assert np.all(diff3 < error3) - assert (output[3].shape() == expect3.shape) + assert output[3].shape() == expect3.shape expect4 = np.max(x4, axis=np_axis4, keepdims=keep_dims4) diff4 = abs(output[4].asnumpy() - expect4) error4 = np.ones(shape=expect4.shape) * 1.0e-5 assert np.all(diff4 < error4) - assert (output[4].shape() == expect4.shape) + assert output[4].shape() == expect4.shape expect5 = np.max(x5, axis=np_axis5, keepdims=keep_dims5) diff5 = abs(output[5].asnumpy() - expect5) error5 = np.ones(shape=expect5.shape) * 1.0e-5 assert np.all(diff5 < error5) - assert (output[5].shape() == expect5.shape) + assert output[5].shape() == expect5.shape expect6 = np.max(x6, axis=axis6, keepdims=keep_dims6) diff6 = abs(output[6].asnumpy() - expect6) error6 = np.ones(shape=expect6.shape) * 1.0e-5 assert np.all(diff6 < error6) - assert (output[6].shape() == expect6.shape) + assert output[6].shape() == expect6.shape expect7 = np.max(x7, axis=axis7, keepdims=keep_dims7) diff7 = abs(output[7].asnumpy() - expect7) diff --git a/tests/st/ops/gpu/test_reduce_mean_op.py b/tests/st/ops/gpu/test_reduce_mean_op.py index ca4b3ea027..d6a10c631f 100644 --- a/tests/st/ops/gpu/test_reduce_mean_op.py +++ b/tests/st/ops/gpu/test_reduce_mean_op.py @@ -180,88 +180,88 @@ def test_ReduceMean(): diff0 = abs(output[0].asnumpy() - expect0) error0 = np.ones(shape=expect0.shape) * 1.0e-5 assert np.all(diff0 < error0) - assert (output[0].shape() == expect0.shape) + assert output[0].shape() == expect0.shape expect1 = np.mean(x1, axis=axis1, keepdims=keep_dims1) diff1 = abs(output[1].asnumpy() - expect1) error1 = np.ones(shape=expect1.shape) * 1.0e-5 assert np.all(diff1 < error1) - assert (output[1].shape() == expect1.shape) + assert output[1].shape() == expect1.shape expect2 = np.mean(x2, axis=axis2, keepdims=keep_dims2) diff2 = abs(output[2].asnumpy() - expect2) error2 = np.ones(shape=expect2.shape) * 1.0e-5 assert np.all(diff2 < error2) - assert (output[2].shape() == expect2.shape) + assert output[2].shape() == expect2.shape expect3 = np.mean(x3, axis=axis3, keepdims=keep_dims3) diff3 = abs(output[3].asnumpy() - expect3) error3 = np.ones(shape=expect3.shape) * 1.0e-5 assert np.all(diff3 < error3) - assert (output[3].shape() == expect3.shape) + assert output[3].shape() == expect3.shape expect4 = np.mean(x4, axis=axis4, keepdims=keep_dims4) diff4 = abs(output[4].asnumpy() - expect4) error4 = np.ones(shape=expect4.shape) * 1.0e-5 assert np.all(diff4 < error4) - assert (output[4].shape() == expect4.shape) + assert output[4].shape() == expect4.shape expect5 = np.mean(x5, axis=axis5, keepdims=keep_dims5) diff5 = abs(output[5].asnumpy() - expect5) error5 = np.ones(shape=expect5.shape) * 1.0e-5 assert np.all(diff5 < error5) - assert (output[5].shape() == expect5.shape) + assert output[5].shape() == expect5.shape expect6 = np.mean(x6, axis=axis6, keepdims=keep_dims6) diff6 = abs(output[6].asnumpy() - expect6) error6 = np.ones(shape=expect6.shape) * 1.0e-5 assert np.all(diff6 < error6) - assert (output[6].shape() == expect6.shape) + assert output[6].shape() == expect6.shape expect7 = np.mean(x7, axis=axis7, keepdims=keep_dims7) diff7 = abs(output[7].asnumpy() - expect7) error7 = np.ones(shape=expect7.shape) * 1.0e-5 assert np.all(diff7 < error7) - assert (output[7].shape() == expect7.shape) + assert output[7].shape() == expect7.shape expect8 = np.mean(x8, axis=axis8, keepdims=keep_dims8) diff8 = abs(output[8].asnumpy() - expect8) error8 = np.ones(shape=expect8.shape) * 1.0e-5 assert np.all(diff8 < error8) - assert (output[8].shape() == expect8.shape) + assert output[8].shape() == expect8.shape expect9 = np.mean(x9, axis=axis9, keepdims=keep_dims9) diff9 = abs(output[9].asnumpy() - expect9) error9 = np.ones(shape=expect9.shape) * 1.0e-5 assert np.all(diff9 < error9) - assert (output[9].shape() == expect9.shape) + assert output[9].shape() == expect9.shape expect10 = np.mean(x10, axis=axis10, keepdims=keep_dims10) diff10 = abs(output[10].asnumpy() - expect10) error10 = np.ones(shape=expect10.shape) * 1.0e-5 assert np.all(diff10 < error10) - assert (output[10].shape() == expect10.shape) + assert output[10].shape() == expect10.shape expect11 = np.mean(x11, axis=axis11, keepdims=keep_dims11) diff11 = abs(output[11].asnumpy() - expect11) error11 = np.ones(shape=expect11.shape) * 1.0e-5 assert np.all(diff11 < error11) - assert (output[11].shape() == expect11.shape) + assert output[11].shape() == expect11.shape expect12 = np.mean(x12, axis=axis12, keepdims=keep_dims12) diff12 = abs(output[12].asnumpy() - expect12) error12 = np.ones(shape=expect12.shape) * 1.0e-5 assert np.all(diff12 < error12) - assert (output[12].shape() == expect12.shape) + assert output[12].shape() == expect12.shape expect13 = np.mean(x13, axis=axis13, keepdims=keep_dims13) diff13 = abs(output[13].asnumpy() - expect13) error13 = np.ones(shape=expect13.shape) * 1.0e-5 assert np.all(diff13 < error13) - assert (output[13].shape() == expect13.shape) + assert output[13].shape() == expect13.shape expect14 = np.mean(x14, axis=np_axis14, keepdims=keep_dims14) diff14 = abs(output[14].asnumpy() - expect14) error14 = np.ones(shape=expect14.shape) * 1.0e-5 assert np.all(diff14 < error14) - assert (output[14].shape() == expect14.shape) + assert output[14].shape() == expect14.shape diff --git a/tests/st/ops/gpu/test_relu6_grad_op.py b/tests/st/ops/gpu/test_relu6_grad_op.py index dba788c271..9be8ee6567 100644 --- a/tests/st/ops/gpu/test_relu6_grad_op.py +++ b/tests/st/ops/gpu/test_relu6_grad_op.py @@ -19,7 +19,6 @@ import pytest import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor -from mindspore.ops import operations as P from mindspore.ops.operations import _grad_ops as G @@ -42,9 +41,9 @@ def test_relu6_grad(): dy = Tensor(np.array([[[[1, 1, 1], [1, 1, 1], [1, 1, 1]]]]).astype(np.float32)) - expect = np.array([[[[0, 1, 0, ], - [1, 0, 0, ], - [0, 1, 0, ]]]]).astype(np.float32) + expect = np.array([[[[0, 1, 0,], + [1, 0, 0,], + [0, 1, 0,]]]]).astype(np.float32) error = np.ones(shape=[3, 3]) * 1.0e-6 context.set_context(mode=context.GRAPH_MODE, device_target="GPU") diff --git a/tests/st/ops/gpu/test_relu6_op.py b/tests/st/ops/gpu/test_relu6_op.py index f491fe985f..9a336e9e55 100644 --- a/tests/st/ops/gpu/test_relu6_op.py +++ b/tests/st/ops/gpu/test_relu6_op.py @@ -38,8 +38,8 @@ def test_relu6(): x = Tensor(np.array([[[[-1, 1, 10], [5.9, 6.1, 6], [10, 1, -1]]]]).astype(np.float32)) - expect = np.array([[[[0, 1, 6, ], - [5.9, 6, 6, ], + expect = np.array([[[[0, 1, 6,], + [5.9, 6, 6,], [6, 1, 0.]]]]).astype(np.float32) context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") diff --git a/tests/st/ops/gpu/test_relu_op.py b/tests/st/ops/gpu/test_relu_op.py index ddd0fa6574..3cec34ef5d 100644 --- a/tests/st/ops/gpu/test_relu_op.py +++ b/tests/st/ops/gpu/test_relu_op.py @@ -38,8 +38,8 @@ def test_relu(): x = Tensor(np.array([[[[-1, 1, 10], [1, -1, 1], [10, 1, -1]]]]).astype(np.float32)) - expect = np.array([[[[0, 1, 10, ], - [1, 0, 1, ], + expect = np.array([[[[0, 1, 10,], + [1, 0, 1,], [10, 1, 0.]]]]).astype(np.float32) context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") diff --git a/tests/st/ops/gpu/test_select_op.py b/tests/st/ops/gpu/test_select_op.py index 610b03e198..03c100cab9 100644 --- a/tests/st/ops/gpu/test_select_op.py +++ b/tests/st/ops/gpu/test_select_op.py @@ -27,8 +27,8 @@ class Net(nn.Cell): super(Net, self).__init__() self.select = P.Select() - def construct(self, cond, x, y): - return self.select(cond, x, y) + def construct(self, cond, input_x, input_y): + return self.select(cond, input_x, input_y) cond = np.array([[True, False], [True, False]]).astype(np.bool) diff --git a/tests/st/ops/gpu/test_slice.py b/tests/st/ops/gpu/test_slice.py index 490898ce4b..4f63bb83a6 100644 --- a/tests/st/ops/gpu/test_slice.py +++ b/tests/st/ops/gpu/test_slice.py @@ -41,8 +41,8 @@ def test_slice(): [[4., -4., 4.]]] context.set_context(mode=context.GRAPH_MODE, device_target="GPU") - slice = Slice() - output = slice(x) + slice_op = Slice() + output = slice_op(x) assert (output.asnumpy() == expect).all() diff --git a/tests/st/ops/gpu/test_slice_grad.py b/tests/st/ops/gpu/test_slice_grad.py index 7a0c73ce1b..d6cc84d6ef 100644 --- a/tests/st/ops/gpu/test_slice_grad.py +++ b/tests/st/ops/gpu/test_slice_grad.py @@ -20,7 +20,6 @@ import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor from mindspore.common.api import ms_function -from mindspore.ops import operations as P from mindspore.ops.operations import _grad_ops as G context.set_context(device_target='GPU') diff --git a/tests/st/ops/gpu/test_softmax_cross_entropy_with_logits_op.py b/tests/st/ops/gpu/test_softmax_cross_entropy_with_logits_op.py index 3e9714faad..8fd70b8172 100644 --- a/tests/st/ops/gpu/test_softmax_cross_entropy_with_logits_op.py +++ b/tests/st/ops/gpu/test_softmax_cross_entropy_with_logits_op.py @@ -19,10 +19,6 @@ import pytest import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor -from mindspore.common.api import ms_function -from mindspore.common.initializer import initializer -from mindspore.common.parameter import Parameter - class NetSoftmaxCrossEntropyWithLogits(nn.Cell): def __init__(self): diff --git a/tests/st/ops/gpu/test_softmax_op.py b/tests/st/ops/gpu/test_softmax_op.py index c1803b4719..73925d8c3b 100644 --- a/tests/st/ops/gpu/test_softmax_op.py +++ b/tests/st/ops/gpu/test_softmax_op.py @@ -116,7 +116,7 @@ def test_softmax_4d(): [-1.5992336e-01, -5.9647644e-01, 1.2957820e+00, -1.0650631e-01, 7.0879894e-01], [4.1372257e-01, 3.6408889e-01, -6.3091749e-01, 1.0573713e+00, 1.0981073e+00], [-1.9162457e-01, 3.6392561e-05, -1.8338780e-01, 1.7549801e+00, -9.3534666e-01]]]]).astype( - np.float32) + np.float32) dy = np.array([[[[2.98213929e-01, 3.10518718e+00, -1.64306939e-01, -7.33681679e-01, 5.23136854e-02], [-3.47142726e-01, -1.52662742e+00, 5.26977003e-01, 5.29672280e-02, -4.34386432e-01], @@ -142,7 +142,7 @@ def test_softmax_4d(): [4.14457440e-01, -8.74118507e-01, -4.21902031e-01, 7.87168801e-01, -1.48280108e+00], [1.42688036e+00, -2.02695489e+00, 9.26816165e-01, 9.37691629e-01, 7.85577714e-01], [-6.59893751e-01, 1.14681525e-02, -5.79456389e-01, -1.65206456e+00, 4.37116653e-01]]]]).astype( - np.float32) + np.float32) expect_x = np.array([[[[0.21919312, 0.3903627, 0.12594244, 0.07031325, 0.19418849], [0.19778392, 0.36304963, 0.16719443, 0.1646197, 0.10735231], diff --git a/tests/st/ops/gpu/test_sparse_softmax_cross_entropy_with_logits_op.py b/tests/st/ops/gpu/test_sparse_softmax_cross_entropy_with_logits_op.py index 7daa9e38df..df4b692410 100644 --- a/tests/st/ops/gpu/test_sparse_softmax_cross_entropy_with_logits_op.py +++ b/tests/st/ops/gpu/test_sparse_softmax_cross_entropy_with_logits_op.py @@ -19,8 +19,6 @@ import pytest import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor -from mindspore.common.api import ms_function - class NetSparseSoftmaxCrossEntropyWithLogits(nn.Cell): def __init__(self): diff --git a/tests/st/ops/gpu/test_sqrt_op.py b/tests/st/ops/gpu/test_sqrt_op.py index b6f2f42335..35c06d4c30 100644 --- a/tests/st/ops/gpu/test_sqrt_op.py +++ b/tests/st/ops/gpu/test_sqrt_op.py @@ -17,7 +17,6 @@ import numpy as np import pytest import mindspore.context as context -import mindspore.nn as nn from mindspore import Tensor from mindspore.ops import operations as P diff --git a/tests/st/ops/gpu/test_sub_op.py b/tests/st/ops/gpu/test_sub_op.py index a65d02d9b3..c28e745a7b 100644 --- a/tests/st/ops/gpu/test_sub_op.py +++ b/tests/st/ops/gpu/test_sub_op.py @@ -76,19 +76,19 @@ def test_Sub(): output4 = sub(x4, y4) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape diff2 = output2.asnumpy() - expect2 assert np.all(diff2 < error2) - assert (output2.shape() == expect2.shape) + assert output2.shape() == expect2.shape diff3 = output3.asnumpy() - expect3 assert np.all(diff3 < error3) - assert (output3.shape() == expect3.shape) + assert output3.shape() == expect3.shape diff4 = output4.asnumpy() - expect4 assert np.all(diff4 < error4) - assert (output4.shape() == expect4.shape) + assert output4.shape() == expect4.shape context.set_context(mode=context.GRAPH_MODE, device_target="GPU") sub = Net() @@ -99,16 +99,16 @@ def test_Sub(): output4 = sub(x4, y4) diff0 = output0.asnumpy() - expect0 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape diff1 = output1.asnumpy() - expect1 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape diff2 = output2.asnumpy() - expect2 assert np.all(diff2 < error2) - assert (output2.shape() == expect2.shape) + assert output2.shape() == expect2.shape diff3 = output3.asnumpy() - expect3 assert np.all(diff3 < error3) - assert (output3.shape() == expect3.shape) + assert output3.shape() == expect3.shape diff4 = output4.asnumpy() - expect4 assert np.all(diff4 < error4) - assert (output4.shape() == expect4.shape) + assert output4.shape() == expect4.shape diff --git a/tests/st/ops/gpu/test_tile_op.py b/tests/st/ops/gpu/test_tile_op.py index cc2145b8f1..6e1b07fe17 100644 --- a/tests/st/ops/gpu/test_tile_op.py +++ b/tests/st/ops/gpu/test_tile_op.py @@ -65,16 +65,16 @@ def test_tile(): diff0 = output[0].asnumpy() - expect0 error0 = np.ones(shape=expect0.shape) * 1.0e-5 assert np.all(diff0 < error0) - assert (output[0].shape() == expect0.shape) + assert output[0].shape() == expect0.shape expect1 = np.tile(input_x1, mul1) diff1 = output[1].asnumpy() - expect1 error1 = np.ones(shape=expect1.shape) * 1.0e-5 assert np.all(diff1 < error1) - assert (output[1].shape() == expect1.shape) + assert output[1].shape() == expect1.shape expect2 = np.tile(input_x2, mul2) diff2 = output[2].asnumpy() - expect2 error2 = np.ones(shape=expect2.shape) * 1.0e-5 assert np.all(diff2 < error2) - assert (output[2].shape() == expect2.shape) + assert output[2].shape() == expect2.shape diff --git a/tests/st/ops/gpu/test_unsorted_segment_sum.py b/tests/st/ops/gpu/test_unsorted_segment_sum.py index 62267d0383..fc5662ebc0 100644 --- a/tests/st/ops/gpu/test_unsorted_segment_sum.py +++ b/tests/st/ops/gpu/test_unsorted_segment_sum.py @@ -20,9 +20,6 @@ import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor from mindspore.common import dtype as mstype -from mindspore.common.api import ms_function -from mindspore.common.initializer import initializer -from mindspore.common.parameter import Parameter from mindspore.ops import operations as P context.set_context(device_target='GPU') diff --git a/tests/st/ops/gpu/test_zeroslike_op.py b/tests/st/ops/gpu/test_zeroslike_op.py index 3532776876..d8aa8ebdf1 100644 --- a/tests/st/ops/gpu/test_zeroslike_op.py +++ b/tests/st/ops/gpu/test_zeroslike_op.py @@ -19,9 +19,6 @@ import pytest import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor -from mindspore.common.api import ms_function -from mindspore.common.initializer import initializer -from mindspore.common.parameter import Parameter from mindspore.ops import operations as P context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") @@ -53,14 +50,14 @@ def test_ZerosLike(): diff0 = output0.asnumpy() - expect0 error0 = np.ones(shape=expect0.shape) * 1.0e-5 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = zeros_like(x1) expect1 = np.zeros_like(x1_np) diff1 = output1.asnumpy() - expect1 error1 = np.ones(shape=expect1.shape) * 1.0e-5 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape context.set_context(mode=context.GRAPH_MODE, device_target="GPU") zeros_like = NetZerosLike() @@ -69,11 +66,11 @@ def test_ZerosLike(): diff0 = output0.asnumpy() - expect0 error0 = np.ones(shape=expect0.shape) * 1.0e-5 assert np.all(diff0 < error0) - assert (output0.shape() == expect0.shape) + assert output0.shape() == expect0.shape output1 = zeros_like(x1) expect1 = np.zeros_like(x1_np) diff1 = output1.asnumpy() - expect1 error1 = np.ones(shape=expect1.shape) * 1.0e-5 assert np.all(diff1 < error1) - assert (output1.shape() == expect1.shape) + assert output1.shape() == expect1.shape