From f3fee0ebd7fc706235804ef0edc8fe1067acacbc Mon Sep 17 00:00:00 2001 From: zhoufan37 Date: Tue, 22 Mar 2022 14:26:47 +0800 Subject: [PATCH] modified codechecks-z Operator --- test/test_network_ops/test_scatter.py | 2 +- test/test_network_ops/test_scatter_add.py | 16 ++++++++-------- test/test_network_ops/test_selu.py | 2 +- test/test_network_ops/test_sigmoid.py | 3 ++- test/test_network_ops/test_sigmoid_backward.py | 3 ++- test/test_network_ops/test_sign.py | 3 ++- test/test_network_ops/test_silu.py | 2 +- test/test_network_ops/test_silu_backward.py | 2 +- test/test_network_ops/test_sin.py | 2 +- test/test_network_ops/test_sinh.py | 2 +- test/test_network_ops/test_slogdet.py | 2 +- .../test_network_ops/test_slow_conv_dilated2d.py | 2 +- .../test_slow_conv_dilated2d_backward.py | 2 +- .../test_slow_conv_transpose2d.py | 2 +- .../test_slow_conv_transpose2d_backward.py | 2 +- .../test_smooth_l1_loss_backward.py | 2 +- test/test_network_ops/test_smoothl1loss.py | 2 +- test/test_network_ops/test_soft_margin_loss.py | 2 +- .../test_soft_margin_loss_backward.py | 2 +- test/test_network_ops/test_softplus.py | 2 +- test/test_network_ops/test_softplus_backward.py | 2 +- test/test_network_ops/test_softshrink.py | 2 +- .../test_network_ops/test_softshrink_backward.py | 2 +- test/test_network_ops/test_sort.py | 3 ++- .../test_sort_without_indices.py | 2 +- test/test_network_ops/test_stack.py | 3 ++- test/test_network_ops/test_std.py | 2 +- test/test_network_ops/test_std_mean.py | 2 +- test/test_network_ops/test_sub_sample.py | 2 +- test/test_network_ops/test_sum.py | 2 +- test/test_network_ops/test_take.py | 2 +- test/test_network_ops/test_tan.py | 2 +- test/test_network_ops/test_tanh.py | 6 ++++-- test/test_network_ops/test_tanh_backward.py | 3 ++- .../test_thnn_conv_depthwise2d_backward.py | 6 +++--- .../test_thnn_conv_depthwise2d_forward.py | 14 ++++++++------ test/test_network_ops/test_threshold.py | 2 +- test/test_network_ops/test_threshold_backward.py | 2 +- test/test_network_ops/test_to.py | 3 ++- test/test_network_ops/test_topk.py | 2 +- test/test_network_ops/test_transpose.py | 2 +- .../test_triangular_solve_helper.py | 2 +- test/test_network_ops/test_tril.py | 2 +- test/test_network_ops/test_triu.py | 2 +- test/test_network_ops/test_true_divide.py | 2 +- test/test_network_ops/test_trunc.py | 3 ++- test/test_network_ops/test_unique2.py | 2 +- test/test_network_ops/test_upsample_bicubic2d.py | 3 ++- .../test_upsample_bicubic2d_backward.py | 3 ++- .../test_network_ops/test_upsample_bilinear2d.py | 3 ++- .../test_upsample_bilinear2d_backward.py | 3 ++- test/test_network_ops/test_upsample_linear1d.py | 2 +- .../test_upsample_linear1d_backward.py | 2 +- test/test_network_ops/test_upsample_nearest1d.py | 2 +- .../test_upsample_nearest1d_backward.py | 2 +- test/test_network_ops/test_upsample_nearest2d.py | 5 +++-- .../test_upsample_nearest2d_backward.py | 5 +++-- test/test_network_ops/test_upsample_nearest3d.py | 2 +- .../test_upsample_nearest3d_backward.py | 2 +- .../test_upsample_trilinear3d.py | 2 +- .../test_upsample_trilinear3d_backward.py | 2 +- test/test_network_ops/test_var.py | 2 +- test/test_network_ops/test_where.py | 5 ++++- test/test_network_ops/test_xor.py | 2 +- test/test_network_ops/test_zero.py | 3 ++- test/test_network_ops/test_zeros.py | 3 ++- test/test_network_ops/test_zeroslike.py | 2 +- 67 files changed, 107 insertions(+), 84 deletions(-) diff --git a/test/test_network_ops/test_scatter.py b/test/test_network_ops/test_scatter.py index 1936d3761b2..87caae98a20 100644 --- a/test/test_network_ops/test_scatter.py +++ b/test/test_network_ops/test_scatter.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_scatter_add.py b/test/test_network_ops/test_scatter_add.py index 9443d71b754..398a4765e30 100644 --- a/test/test_network_ops/test_scatter_add.py +++ b/test/test_network_ops/test_scatter_add.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor @@ -45,13 +45,13 @@ class TestScatterAdd(TestCase): def test_scatter_add_common_shape_format(self, device="npu"): shape_format = [ - [0, [np.int64, 0, [10, 20]], [np.float32, 0, [10, 20]], [np.float32, 0, [10, 20]]], - [1, [np.int64, 0, [10, 20]], [np.float32, 0, [10, 20]], [np.float32, 0, [10, 20]]], - [0, [np.int64, 0, [2, 6]], [np.float32, 0, [2, 6]], [np.float32, 0, [2, 6]]], - [1, [np.int64, 0, [2, 6]], [np.float32, 0, [2, 6]], [np.float32, 0, [2, 6]]], - [0, [np.int64, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]]], - [1, [np.int64, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]]], - [2, [np.int64, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]]], + [0, [np.int64, 0, [10, 20]], [np.float32, 0, [10, 20]], [np.float32, 0, [10, 20]]], + [1, [np.int64, 0, [10, 20]], [np.float32, 0, [10, 20]], [np.float32, 0, [10, 20]]], + [0, [np.int64, 0, [2, 6]], [np.float32, 0, [2, 6]], [np.float32, 0, [2, 6]]], + [1, [np.int64, 0, [2, 6]], [np.float32, 0, [2, 6]], [np.float32, 0, [2, 6]]], + [0, [np.int64, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]]], + [1, [np.int64, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]]], + [2, [np.int64, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]], [np.float32, 0, [10, 20, 30]]], ] for item in shape_format: diff --git a/test/test_network_ops/test_selu.py b/test/test_network_ops/test_selu.py index c3c3dbe8e72..c785ca21e4a 100644 --- a/test/test_network_ops/test_selu.py +++ b/test/test_network_ops/test_selu.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests diff --git a/test/test_network_ops/test_sigmoid.py b/test/test_network_ops/test_sigmoid.py index c47ab416562..c615642a74b 100644 --- a/test/test_network_ops/test_sigmoid.py +++ b/test/test_network_ops/test_sigmoid.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_sigmoid_backward.py b/test/test_network_ops/test_sigmoid_backward.py index a78d172d4d6..b2e4614f8c1 100644 --- a/test/test_network_ops/test_sigmoid_backward.py +++ b/test/test_network_ops/test_sigmoid_backward.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_sign.py b/test/test_network_ops/test_sign.py index 67a61ff8699..87f951ec178 100644 --- a/test/test_network_ops/test_sign.py +++ b/test/test_network_ops/test_sign.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_silu.py b/test/test_network_ops/test_silu.py index 0da283cafc8..60153d4ff07 100644 --- a/test/test_network_ops/test_silu.py +++ b/test/test_network_ops/test_silu.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_silu_backward.py b/test/test_network_ops/test_silu_backward.py index 9e4e319e81a..08d08bfb79e 100644 --- a/test/test_network_ops/test_silu_backward.py +++ b/test/test_network_ops/test_silu_backward.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_sin.py b/test/test_network_ops/test_sin.py index 4252cafb90e..07fa0ac08da 100644 --- a/test/test_network_ops/test_sin.py +++ b/test/test_network_ops/test_sin.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_sinh.py b/test/test_network_ops/test_sinh.py index 5915b0c48aa..c00b9ccab3d 100644 --- a/test/test_network_ops/test_sinh.py +++ b/test/test_network_ops/test_sinh.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests diff --git a/test/test_network_ops/test_slogdet.py b/test/test_network_ops/test_slogdet.py index 2ea343f4fd6..c68abcb45d9 100644 --- a/test/test_network_ops/test_slogdet.py +++ b/test/test_network_ops/test_slogdet.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_slow_conv_dilated2d.py b/test/test_network_ops/test_slow_conv_dilated2d.py index 253019389e0..5b73a9ccd41 100644 --- a/test/test_network_ops/test_slow_conv_dilated2d.py +++ b/test/test_network_ops/test_slow_conv_dilated2d.py @@ -13,9 +13,9 @@ # limitations under the License. import torch -import torch_npu import numpy as np import torch.nn as nn +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_slow_conv_dilated2d_backward.py b/test/test_network_ops/test_slow_conv_dilated2d_backward.py index 4b7981d506e..68b300104f3 100644 --- a/test/test_network_ops/test_slow_conv_dilated2d_backward.py +++ b/test/test_network_ops/test_slow_conv_dilated2d_backward.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_slow_conv_transpose2d.py b/test/test_network_ops/test_slow_conv_transpose2d.py index 006312f4735..f53cd2c9f15 100644 --- a/test/test_network_ops/test_slow_conv_transpose2d.py +++ b/test/test_network_ops/test_slow_conv_transpose2d.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_slow_conv_transpose2d_backward.py b/test/test_network_ops/test_slow_conv_transpose2d_backward.py index ec0ce0a1f60..d5e02b90be1 100644 --- a/test/test_network_ops/test_slow_conv_transpose2d_backward.py +++ b/test/test_network_ops/test_slow_conv_transpose2d_backward.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_smooth_l1_loss_backward.py b/test/test_network_ops/test_smooth_l1_loss_backward.py index 0d37d9f84c1..f97b64000ee 100644 --- a/test/test_network_ops/test_smooth_l1_loss_backward.py +++ b/test/test_network_ops/test_smooth_l1_loss_backward.py @@ -13,9 +13,9 @@ # limitations under the License. import torch -import torch_npu import numpy as np import torch.nn.functional as F +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_smoothl1loss.py b/test/test_network_ops/test_smoothl1loss.py index 7dafcf0d21f..945ad772343 100644 --- a/test/test_network_ops/test_smoothl1loss.py +++ b/test/test_network_ops/test_smoothl1loss.py @@ -14,8 +14,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_soft_margin_loss.py b/test/test_network_ops/test_soft_margin_loss.py index 599f3bacbee..f4d22616b54 100644 --- a/test/test_network_ops/test_soft_margin_loss.py +++ b/test/test_network_ops/test_soft_margin_loss.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_soft_margin_loss_backward.py b/test/test_network_ops/test_soft_margin_loss_backward.py index 0b690d9ff83..52f693532c5 100644 --- a/test/test_network_ops/test_soft_margin_loss_backward.py +++ b/test/test_network_ops/test_soft_margin_loss_backward.py @@ -13,9 +13,9 @@ # limitations under the License. import torch -import torch_npu import numpy as np import torch.nn.functional as F +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_softplus.py b/test/test_network_ops/test_softplus.py index 9b881b23df8..d0103c94385 100644 --- a/test/test_network_ops/test_softplus.py +++ b/test/test_network_ops/test_softplus.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_softplus_backward.py b/test/test_network_ops/test_softplus_backward.py index 08b8cbdc75d..5eff4633bb2 100644 --- a/test/test_network_ops/test_softplus_backward.py +++ b/test/test_network_ops/test_softplus_backward.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_softshrink.py b/test/test_network_ops/test_softshrink.py index cee5d9709b8..1dab3ba6a22 100644 --- a/test/test_network_ops/test_softshrink.py +++ b/test/test_network_ops/test_softshrink.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests diff --git a/test/test_network_ops/test_softshrink_backward.py b/test/test_network_ops/test_softshrink_backward.py index 1b3e86df0ee..0cc0383d62a 100644 --- a/test/test_network_ops/test_softshrink_backward.py +++ b/test/test_network_ops/test_softshrink_backward.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests diff --git a/test/test_network_ops/test_sort.py b/test/test_network_ops/test_sort.py index 27cc84ef1b4..2e154fbf876 100644 --- a/test/test_network_ops/test_sort.py +++ b/test/test_network_ops/test_sort.py @@ -13,9 +13,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_sort_without_indices.py b/test/test_network_ops/test_sort_without_indices.py index e53e1842ef8..7057aee7d17 100644 --- a/test/test_network_ops/test_sort_without_indices.py +++ b/test/test_network_ops/test_sort_without_indices.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_stack.py b/test/test_network_ops/test_stack.py index b209bb3f653..e4ca4e21da2 100644 --- a/test/test_network_ops/test_stack.py +++ b/test/test_network_ops/test_stack.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_std.py b/test/test_network_ops/test_std.py index bfe8b8a95d4..0237995f79a 100644 --- a/test/test_network_ops/test_std.py +++ b/test/test_network_ops/test_std.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_std_mean.py b/test/test_network_ops/test_std_mean.py index d49444561cb..a3b37534c8e 100644 --- a/test/test_network_ops/test_std_mean.py +++ b/test/test_network_ops/test_std_mean.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_sub_sample.py b/test/test_network_ops/test_sub_sample.py index a6ae808ccbc..06b38ba7865 100644 --- a/test/test_network_ops/test_sub_sample.py +++ b/test/test_network_ops/test_sub_sample.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests diff --git a/test/test_network_ops/test_sum.py b/test/test_network_ops/test_sum.py index 94bb384110d..f14f6dc8842 100644 --- a/test/test_network_ops/test_sum.py +++ b/test/test_network_ops/test_sum.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_take.py b/test/test_network_ops/test_take.py index 7cbe07bd589..58a1168a37b 100644 --- a/test/test_network_ops/test_take.py +++ b/test/test_network_ops/test_take.py @@ -15,8 +15,8 @@ # coding: utf-8 import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_tan.py b/test/test_network_ops/test_tan.py index 4f5002e0e5f..d7865bf5c0a 100644 --- a/test/test_network_ops/test_tan.py +++ b/test/test_network_ops/test_tan.py @@ -16,8 +16,8 @@ import copy import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests diff --git a/test/test_network_ops/test_tanh.py b/test/test_network_ops/test_tanh.py index a1bcfb09c6a..9e722a26275 100644 --- a/test/test_network_ops/test_tanh.py +++ b/test/test_network_ops/test_tanh.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor @@ -83,7 +84,8 @@ class TestTanh(TestCase): [[np.float16, -1, (4, 44, 44)], 3450,34020], [[np.float16, -1, (65500, 3, 3)], -214748,-214746], [[np.float16, -1, (64, 4, 4)], -9.313225746154785e-10,9.313225746154785e-10], - [[np.float16, -1, (128, 3, 5)], -0.000000000000000000000000000000000000011754943508,0.000000000000000000000000000000000000011754943508], + [[np.float16, -1, (128, 3, 5)], + -0.000000000000000000000000000000000000011754943508,0.000000000000000000000000000000000000011754943508], [[np.float16, -1, (1, 1, 1)], 0.9283381566708346 , 16], [[np.float16, -1, (6, 3, 10)], 0.03133650248813469 , 37], [[np.float16, -1, (65500, 1, 1)], 95, 100 ], diff --git a/test/test_network_ops/test_tanh_backward.py b/test/test_network_ops/test_tanh_backward.py index 35f4642acae..fcff6f30c1f 100644 --- a/test/test_network_ops/test_tanh_backward.py +++ b/test/test_network_ops/test_tanh_backward.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_thnn_conv_depthwise2d_backward.py b/test/test_network_ops/test_thnn_conv_depthwise2d_backward.py index b267e1e59ef..e07c36db8a2 100644 --- a/test/test_network_ops/test_thnn_conv_depthwise2d_backward.py +++ b/test/test_network_ops/test_thnn_conv_depthwise2d_backward.py @@ -15,9 +15,9 @@ # limitations under the License. import torch -import torch_npu import numpy as np import torch.nn as nn +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor @@ -41,7 +41,7 @@ class TestThnnConvDepthwise2d(TestCase): input1.register_hook(lambda grad: self.get_input_grad(grad)) bias1 = False - if bias != None: + if bias is not None: bias1 = True m1 = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, bias=bias1, @@ -61,7 +61,7 @@ class TestThnnConvDepthwise2d(TestCase): input1.register_hook(lambda grad: self.get_input_grad(grad)) bias1 = False - if bias != None: + if bias is not None: bias1 = True m1 = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, bias=bias1, diff --git a/test/test_network_ops/test_thnn_conv_depthwise2d_forward.py b/test/test_network_ops/test_thnn_conv_depthwise2d_forward.py index 10f1083a4ff..f5fe8f25c23 100644 --- a/test/test_network_ops/test_thnn_conv_depthwise2d_forward.py +++ b/test/test_network_ops/test_thnn_conv_depthwise2d_forward.py @@ -13,9 +13,9 @@ # limitations under the License. import torch -import torch_npu import numpy as np import torch.nn as nn +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor @@ -31,13 +31,14 @@ class TestThnnConvDepthwise2d(TestCase): def get_input_grad(self, grad): self.input_grad.append(grad.to("cpu")) - def op_exec_cpu(self, input1, weight, in_channels, out_channels, kernel_size, padding=0, stride=1, dilation=1, bias=True, group=2): + def op_exec_cpu(self, input1, weight, in_channels, + out_channels, kernel_size, padding=0, stride=1, dilation=1, bias=True, group=2): weight1 = weight input1.requires_grad = True input1.register_hook(lambda grad: self.get_input_grad(grad)) bias1 = False - if bias != None: + if bias is not None: bias1 = True m1 = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, bias=bias1, groups=group) @@ -50,13 +51,14 @@ class TestThnnConvDepthwise2d(TestCase): return cpuOutput - def op_exec_npu(self, input1, weight, in_channels, out_channels, kernel_size, padding=0, stride=1, dilation=1, bias=True, group=2): + def op_exec_npu(self, input1, weight, in_channels, + out_channels, kernel_size, padding=0, stride=1, dilation=1, bias=True, group=2): weight1 = weight input1.requires_grad = True input1.register_hook(lambda grad: self.get_input_grad(grad)) bias1 = False - if bias != None: + if bias is not None: bias1 = True m1 = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, bias=bias1, groups=group) @@ -98,7 +100,7 @@ class TestThnnConvDepthwise2d(TestCase): padding=item[2], stride=item[3], dilation=item[4], bias=item[5], group=group) cpu_output = cpu_output.to(npu_output.dtype) - if item[5] == True: + if item[5] is True: self.assertRtolEqual(cpu_output.detach().numpy(), npu_output.detach().numpy(), 0.005 ) else: self.assertRtolEqual(cpu_output.detach().numpy(), npu_output.detach().numpy() ) diff --git a/test/test_network_ops/test_threshold.py b/test/test_network_ops/test_threshold.py index febb6cf36d0..ec93408d7ba 100644 --- a/test/test_network_ops/test_threshold.py +++ b/test/test_network_ops/test_threshold.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_threshold_backward.py b/test/test_network_ops/test_threshold_backward.py index 1307e10ed30..c999b751e81 100644 --- a/test/test_network_ops/test_threshold_backward.py +++ b/test/test_network_ops/test_threshold_backward.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_to.py b/test/test_network_ops/test_to.py index 3f8c7076be1..9d70e624346 100644 --- a/test/test_network_ops/test_to.py +++ b/test/test_network_ops/test_to.py @@ -15,12 +15,13 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor + class TestTo(TestCase): def cpu_op_exec(self, input1, target): output = input1.to(target) diff --git a/test/test_network_ops/test_topk.py b/test/test_network_ops/test_topk.py index 0d6975f6693..89914e1ddfa 100644 --- a/test/test_network_ops/test_topk.py +++ b/test/test_network_ops/test_topk.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_transpose.py b/test/test_network_ops/test_transpose.py index 798d7d5e326..681445ab915 100644 --- a/test/test_network_ops/test_transpose.py +++ b/test/test_network_ops/test_transpose.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_triangular_solve_helper.py b/test/test_network_ops/test_triangular_solve_helper.py index c2d028e92b0..18c7e07b0ae 100644 --- a/test/test_network_ops/test_triangular_solve_helper.py +++ b/test/test_network_ops/test_triangular_solve_helper.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_tril.py b/test/test_network_ops/test_tril.py index 31195afcc4c..05b6733bc32 100644 --- a/test/test_network_ops/test_tril.py +++ b/test/test_network_ops/test_tril.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_triu.py b/test/test_network_ops/test_triu.py index 6daa9ebe17e..f07101fa825 100644 --- a/test/test_network_ops/test_triu.py +++ b/test/test_network_ops/test_triu.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_true_divide.py b/test/test_network_ops/test_true_divide.py index e89e5096319..3f0cdd5231f 100644 --- a/test/test_network_ops/test_true_divide.py +++ b/test/test_network_ops/test_true_divide.py @@ -12,8 +12,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests diff --git a/test/test_network_ops/test_trunc.py b/test/test_network_ops/test_trunc.py index 3d180f3433b..313abb78136 100644 --- a/test/test_network_ops/test_trunc.py +++ b/test/test_network_ops/test_trunc.py @@ -13,12 +13,13 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor + class TestTrunc(TestCase): def generate_single_data(self, min_d, max_d, shape, dtype): input1 = np.random.uniform(min_d, max_d, shape).astype(dtype) diff --git a/test/test_network_ops/test_unique2.py b/test/test_network_ops/test_unique2.py index 4f3c07d218d..003ae72d2f0 100644 --- a/test/test_network_ops/test_unique2.py +++ b/test/test_network_ops/test_unique2.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests diff --git a/test/test_network_ops/test_upsample_bicubic2d.py b/test/test_network_ops/test_upsample_bicubic2d.py index 38e16e92284..cc2c268e3c8 100644 --- a/test/test_network_ops/test_upsample_bicubic2d.py +++ b/test/test_network_ops/test_upsample_bicubic2d.py @@ -15,12 +15,13 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor + class TestUpsampleBicubic2d(TestCase): def cpu_op_exec(self, input1, output_size, align_corners, scale_h, scale_w): diff --git a/test/test_network_ops/test_upsample_bicubic2d_backward.py b/test/test_network_ops/test_upsample_bicubic2d_backward.py index ea37ece37d6..7adfc577f11 100644 --- a/test/test_network_ops/test_upsample_bicubic2d_backward.py +++ b/test/test_network_ops/test_upsample_bicubic2d_backward.py @@ -15,12 +15,13 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor + class TestUpsampleBicubic2dBackward(TestCase): def cpu_op_exec(self, input1, output_size, align_corners, scale_h, scale_w): diff --git a/test/test_network_ops/test_upsample_bilinear2d.py b/test/test_network_ops/test_upsample_bilinear2d.py index d610e9dcbe7..0caf8692ab7 100644 --- a/test/test_network_ops/test_upsample_bilinear2d.py +++ b/test/test_network_ops/test_upsample_bilinear2d.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_bilinear2d_backward.py b/test/test_network_ops/test_upsample_bilinear2d_backward.py index 92688d3ae7a..c3b01fa5450 100644 --- a/test/test_network_ops/test_upsample_bilinear2d_backward.py +++ b/test/test_network_ops/test_upsample_bilinear2d_backward.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_linear1d.py b/test/test_network_ops/test_upsample_linear1d.py index 0232218341a..89257947aca 100644 --- a/test/test_network_ops/test_upsample_linear1d.py +++ b/test/test_network_ops/test_upsample_linear1d.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_linear1d_backward.py b/test/test_network_ops/test_upsample_linear1d_backward.py index ff7531669ab..c6970982d76 100644 --- a/test/test_network_ops/test_upsample_linear1d_backward.py +++ b/test/test_network_ops/test_upsample_linear1d_backward.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_nearest1d.py b/test/test_network_ops/test_upsample_nearest1d.py index bad0c52ebc8..60ca2095a1c 100644 --- a/test/test_network_ops/test_upsample_nearest1d.py +++ b/test/test_network_ops/test_upsample_nearest1d.py @@ -13,9 +13,9 @@ # limitations under the License. import torch -import torch_npu import numpy as np import torch.nn.functional as F +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_nearest1d_backward.py b/test/test_network_ops/test_upsample_nearest1d_backward.py index c27181d33e9..82f8eb678c2 100644 --- a/test/test_network_ops/test_upsample_nearest1d_backward.py +++ b/test/test_network_ops/test_upsample_nearest1d_backward.py @@ -14,9 +14,9 @@ import math import torch -import torch_npu import numpy as np import torch.nn.functional as F +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_nearest2d.py b/test/test_network_ops/test_upsample_nearest2d.py index a73cbc8bb82..3bebc640f76 100644 --- a/test/test_network_ops/test_upsample_nearest2d.py +++ b/test/test_network_ops/test_upsample_nearest2d.py @@ -11,10 +11,11 @@ # 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 torch -import torch_npu -import torch.nn.functional as F import numpy as np +import torch.nn.functional as F +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_nearest2d_backward.py b/test/test_network_ops/test_upsample_nearest2d_backward.py index 6e74d03d577..0522c4e3af0 100644 --- a/test/test_network_ops/test_upsample_nearest2d_backward.py +++ b/test/test_network_ops/test_upsample_nearest2d_backward.py @@ -11,10 +11,11 @@ # 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 torch -import torch_npu -import torch.nn.functional as F import numpy as np +import torch.nn.functional as F +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_nearest3d.py b/test/test_network_ops/test_upsample_nearest3d.py index 0d3c7ea4e04..b174ec7193e 100644 --- a/test/test_network_ops/test_upsample_nearest3d.py +++ b/test/test_network_ops/test_upsample_nearest3d.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_nearest3d_backward.py b/test/test_network_ops/test_upsample_nearest3d_backward.py index d99b44e849e..db84e51219c 100644 --- a/test/test_network_ops/test_upsample_nearest3d_backward.py +++ b/test/test_network_ops/test_upsample_nearest3d_backward.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_trilinear3d.py b/test/test_network_ops/test_upsample_trilinear3d.py index 4f6d98c13dc..ffc1aafdfef 100644 --- a/test/test_network_ops/test_upsample_trilinear3d.py +++ b/test/test_network_ops/test_upsample_trilinear3d.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_upsample_trilinear3d_backward.py b/test/test_network_ops/test_upsample_trilinear3d_backward.py index c319622fcb3..9fc0d32604d 100644 --- a/test/test_network_ops/test_upsample_trilinear3d_backward.py +++ b/test/test_network_ops/test_upsample_trilinear3d_backward.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_var.py b/test/test_network_ops/test_var.py index 12482c7dc92..092a6095bd4 100644 --- a/test/test_network_ops/test_var.py +++ b/test/test_network_ops/test_var.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_where.py b/test/test_network_ops/test_where.py index 4db59af042f..88519347f45 100644 --- a/test/test_network_ops/test_where.py +++ b/test/test_network_ops/test_where.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor @@ -23,6 +24,7 @@ class TestWhere(TestCase): def cpu_op_exec(self, input1): output = torch.where(input1) output = list(output) + for i in range(len(output)): output[i] = output[i].numpy().astype(np.int32) return output @@ -30,6 +32,7 @@ class TestWhere(TestCase): def npu_op_exec(self, input1): output = torch.where(input1) output = list(output) + for i in range(len(output)): output[i] = output[i].to("cpu").numpy().astype(np.int32) return output diff --git a/test/test_network_ops/test_xor.py b/test/test_network_ops/test_xor.py index f0e254befee..d5dcf2f7332 100644 --- a/test/test_network_ops/test_xor.py +++ b/test/test_network_ops/test_xor.py @@ -13,8 +13,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests diff --git a/test/test_network_ops/test_zero.py b/test/test_network_ops/test_zero.py index cdce485d46d..7122cfdd014 100644 --- a/test/test_network_ops/test_zero.py +++ b/test/test_network_ops/test_zero.py @@ -11,9 +11,10 @@ # 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 torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_zeros.py b/test/test_network_ops/test_zeros.py index 390994d7cc1..248eaeca4f8 100644 --- a/test/test_network_ops/test_zeros.py +++ b/test/test_network_ops/test_zeros.py @@ -11,10 +11,11 @@ # 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 copy import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_zeroslike.py b/test/test_network_ops/test_zeroslike.py index a014707ab2f..86b58704f7e 100644 --- a/test/test_network_ops/test_zeroslike.py +++ b/test/test_network_ops/test_zeroslike.py @@ -15,8 +15,8 @@ # limitations under the License. import torch -import torch_npu import numpy as np +import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor -- Gitee