From 5f6b8641e6c093cdba79e9508e7f6b3d77e08902 Mon Sep 17 00:00:00 2001 From: sunxing <346736790@qq.com> Date: Tue, 22 Mar 2022 13:53:40 +0800 Subject: [PATCH] =?UTF-8?q?c=E7=AE=97=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_network_ops/test_cdist.py | 2 +- test/test_network_ops/test_cdist_backward.py | 2 +- test/test_network_ops/test_ceil.py | 7 +++---- test/test_network_ops/test_celu.py | 2 +- test/test_network_ops/test_clamp.py | 2 +- test/test_network_ops/test_clamp_max.py | 2 +- test/test_network_ops/test_clamp_min.py | 2 +- test/test_network_ops/test_col2im_backward.py | 2 +- .../test_confusion_transpose.py | 2 +- .../test_confusion_transpose_backward.py | 2 +- test/test_network_ops/test_constant_pad_nd.py | 2 +- test/test_network_ops/test_conv2d.py | 17 +++++++++++------ test/test_network_ops/test_conv3d.py | 14 +++++++++----- .../test_conv_depthwise2d_backward.py | 9 +++------ test/test_network_ops/test_conv_tbc.py | 2 +- test/test_network_ops/test_conv_tbc_backward.py | 2 +- .../test_conv_transpose2d_backward.py | 8 +++----- test/test_network_ops/test_copy_.py | 2 +- test/test_network_ops/test_cos.py | 2 +- test/test_network_ops/test_cosh.py | 2 +- test/test_network_ops/test_cross.py | 2 +- test/test_network_ops/test_ctc_loss.py | 2 +- test/test_network_ops/test_ctc_loss_backward.py | 2 +- test/test_network_ops/test_cummax.py | 2 +- test/test_network_ops/test_cummin.py | 2 +- test/test_network_ops/test_cumprod.py | 2 +- test/test_network_ops/test_cumsum.py | 2 +- 27 files changed, 51 insertions(+), 48 deletions(-) diff --git a/test/test_network_ops/test_cdist.py b/test/test_network_ops/test_cdist.py index d300f19029..80cc5df5f6 100644 --- a/test/test_network_ops/test_cdist.py +++ b/test/test_network_ops/test_cdist.py @@ -12,8 +12,8 @@ # 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 diff --git a/test/test_network_ops/test_cdist_backward.py b/test/test_network_ops/test_cdist_backward.py index fb8e5c5d5d..f7c844ba29 100644 --- a/test/test_network_ops/test_cdist_backward.py +++ b/test/test_network_ops/test_cdist_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_ceil.py b/test/test_network_ops/test_ceil.py index 17f20c4fba..1e6cdf0c6e 100644 --- a/test/test_network_ops/test_ceil.py +++ b/test/test_network_ops/test_ceil.py @@ -14,17 +14,16 @@ # 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 class TestCeil(TestCase): - @Dtypes(torch.float) - def test_ceil(self, device, dtype): - cpu_input = torch.randn(10, 10, dtype=torch.float, device="cpu").to(dtype=dtype) + def test_ceil(self): + cpu_input = torch.randn(10, 10) npu_input = cpu_input.to("npu") cpu_output = torch.ceil_(cpu_input) npu_output = torch.ceil_(npu_input) diff --git a/test/test_network_ops/test_celu.py b/test/test_network_ops/test_celu.py index 631c16d1ca..90446f4b7e 100644 --- a/test/test_network_ops/test_celu.py +++ b/test/test_network_ops/test_celu.py @@ -12,8 +12,8 @@ # 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_clamp.py b/test/test_network_ops/test_clamp.py index fc32b89ec9..affd8be81b 100644 --- a/test/test_network_ops/test_clamp.py +++ b/test/test_network_ops/test_clamp.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_clamp_max.py b/test/test_network_ops/test_clamp_max.py index 12c78852bf..73dcfdcfa6 100644 --- a/test/test_network_ops/test_clamp_max.py +++ b/test/test_network_ops/test_clamp_max.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_clamp_min.py b/test/test_network_ops/test_clamp_min.py index 8abf146177..2687c9ecd7 100644 --- a/test/test_network_ops/test_clamp_min.py +++ b/test/test_network_ops/test_clamp_min.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_col2im_backward.py b/test/test_network_ops/test_col2im_backward.py index a1dfb59c4e..363992c7ce 100644 --- a/test/test_network_ops/test_col2im_backward.py +++ b/test/test_network_ops/test_col2im_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_confusion_transpose.py b/test/test_network_ops/test_confusion_transpose.py index 09699710d0..2e32c3ba82 100644 --- a/test/test_network_ops/test_confusion_transpose.py +++ b/test/test_network_ops/test_confusion_transpose.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 from torch_npu.testing.common_utils import create_common_tensor diff --git a/test/test_network_ops/test_confusion_transpose_backward.py b/test/test_network_ops/test_confusion_transpose_backward.py index 4921bcc4d4..f8dc8811f4 100644 --- a/test/test_network_ops/test_confusion_transpose_backward.py +++ b/test/test_network_ops/test_confusion_transpose_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_constant_pad_nd.py b/test/test_network_ops/test_constant_pad_nd.py index 591c51fac1..8737727cf1 100644 --- a/test/test_network_ops/test_constant_pad_nd.py +++ b/test/test_network_ops/test_constant_pad_nd.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_conv2d.py b/test/test_network_ops/test_conv2d.py index e00838b97b..8a8fe6a0e6 100644 --- a/test/test_network_ops/test_conv2d.py +++ b/test/test_network_ops/test_conv2d.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 @@ -75,12 +75,17 @@ class TestConv2d(TestCase): if weight_cpu.dtype == torch.float16: weight_cpu = weight_cpu.to(torch.float32) kernel_size = (item[1][2][2], item[1][2][3]) - assert item[0][2][1]/item[6] == item[1][2][1], "ilegal parameters: con2d in_channels//groups must equal to weight.size[1]." - cpu_output = self.op_exec_cpu(input_cpu, weight_cpu, item[0][2][1], item[1][2][0], kernel_size=kernel_size, - padding=item[2], stride=item[3], dilation=item[4], bias=item[5], groups=item[6]) + assert item[0][2][1]/item[6] == item[1][2][1], \ + "ilegal parameters: con2d in_channels//groups must equal to weight.size[1]." + cpu_output = self.op_exec_cpu(input_cpu, weight_cpu, item[0][2][1], + item[1][2][0], kernel_size=kernel_size, + padding=item[2], stride=item[3], + dilation=item[4], bias=item[5], groups=item[6]) weight_npu = weight_npu.to("cpu") - npu_output = self.op_exec_npu(input_npu, weight_npu, item[0][2][1], item[1][2][0], kernel_size=kernel_size, - padding=item[2], stride=item[3], dilation=item[4], bias=item[5], groups=item[6]) + npu_output = self.op_exec_npu(input_npu, weight_npu, item[0][2][1], + item[1][2][0], kernel_size=kernel_size, + padding=item[2], stride=item[3], + dilation=item[4], bias=item[5], groups=item[6]) npu_output = npu_output.to(torch.float16) cpu_output = cpu_output.to(torch.float16) diff --git a/test/test_network_ops/test_conv3d.py b/test/test_network_ops/test_conv3d.py index 168d8faaec..7affc60ccc 100644 --- a/test/test_network_ops/test_conv3d.py +++ b/test/test_network_ops/test_conv3d.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 @@ -73,12 +73,16 @@ class TestConv3d(TestCase): if weight_cpu.dtype == torch.float16: weight_cpu = weight_cpu.to(torch.float32) kernel_size = (item[1][2][2], item[1][2][3],item[1][2][4]) - cpu_output = self.op_exec_cpu(input_cpu, weight_cpu, item[0][2][1], item[1][2][0], kernel_size=kernel_size, - padding=item[2], stride=item[3], dilation=item[4], bias=item[5], groups=item[6]) + cpu_output = self.op_exec_cpu(input_cpu, weight_cpu, item[0][2][1], + item[1][2][0], kernel_size=kernel_size, + padding=item[2], stride=item[3], + dilation=item[4], bias=item[5], groups=item[6]) weight_npu = weight_npu.to("cpu") - npu_output = self.op_exec_npu(input_npu, weight_npu, item[0][2][1], item[1][2][0], kernel_size=kernel_size, - padding=item[2], stride=item[3], dilation=item[4], bias=item[5], groups=item[6]) + npu_output = self.op_exec_npu(input_npu, weight_npu, item[0][2][1], + item[1][2][0], kernel_size=kernel_size, + padding=item[2], stride=item[3], + dilation=item[4], bias=item[5], groups=item[6]) npu_output = npu_output.to(torch.float16) cpu_output = cpu_output.to(torch.float16) diff --git a/test/test_network_ops/test_conv_depthwise2d_backward.py b/test/test_network_ops/test_conv_depthwise2d_backward.py index addc77a2e0..d62e268e0d 100644 --- a/test/test_network_ops/test_conv_depthwise2d_backward.py +++ b/test/test_network_ops/test_conv_depthwise2d_backward.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 @@ -95,21 +95,18 @@ class TestConvDepthwise2d(TestCase): self.assertRtolEqual(self.weight_grad[0].numpy(), self.weight_grad[1].numpy()) def test_conv_depthwise2d_backward_shape_format_fp16(self, device="npu"): - shape_format = [ # input , weight, padding, stide, dilation, bias - # shuflenet + shape_format = [ [[np.float16, 0, [1024, 116, 28, 28]], [np.float16, 0, [116, 1, 3, 3]], 1, 2, 1, 0], [[np.float16, 3, [1024, 116, 14, 14]], [np.float16, 0, [116, 1, 3, 3]], 1, 1, 1, 0], ] self.conv_depthwise2d_backward_result(shape_format) def test_conv_depthwise2d_backward_shape_format_fp32(self, device="npu"): - shape_format = [ # input , weight, padding, stide, dilation, bias - # mobilenet + shape_format = [ [[np.float32, 3, [256, 32, 112, 112]], [np.float32, 0, [32, 1, 3, 3]], 1, 1, 1, None], [[np.float32, 3, [256, 96, 112, 112]], [np.float32, 0, [96, 1, 3, 3]], 1, 2, 1, None], ] #conv类算子不支持fp32数据的精度要求 - #self.conv_depthwise2d_backward_result(shape_format) if __name__ == "__main__": diff --git a/test/test_network_ops/test_conv_tbc.py b/test/test_network_ops/test_conv_tbc.py index 8a4224abd7..739a5a4003 100644 --- a/test/test_network_ops/test_conv_tbc.py +++ b/test/test_network_ops/test_conv_tbc.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_conv_tbc_backward.py b/test/test_network_ops/test_conv_tbc_backward.py index 5bcdc55e83..881e1320ad 100644 --- a/test/test_network_ops/test_conv_tbc_backward.py +++ b/test/test_network_ops/test_conv_tbc_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_conv_transpose2d_backward.py b/test/test_network_ops/test_conv_transpose2d_backward.py index 55f52b513d..81abf74840 100644 --- a/test/test_network_ops/test_conv_transpose2d_backward.py +++ b/test/test_network_ops/test_conv_transpose2d_backward.py @@ -14,11 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import torch -import torch_npu -import numpy as np import copy +import torch import torch.nn as nn +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 @@ -115,8 +115,6 @@ class TestConvTranspose2dBackward(TestCase): shape_format = [ [[np.float32, 0, [1, 4, 5, 5]], [np.float32, 0, [4, 4, 3, 3]]] ] - #conv类算子不支持fp32数据的精度要求 - #self.conv_transpose2d_backward_result(shape_format) if __name__ == "__main__": diff --git a/test/test_network_ops/test_copy_.py b/test/test_network_ops/test_copy_.py index d72ffa1aa5..d9b11213fb 100644 --- a/test/test_network_ops/test_copy_.py +++ b/test/test_network_ops/test_copy_.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_cos.py b/test/test_network_ops/test_cos.py index 49cd18f925..b5c629c671 100644 --- a/test/test_network_ops/test_cos.py +++ b/test/test_network_ops/test_cos.py @@ -14,8 +14,8 @@ 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_cosh.py b/test/test_network_ops/test_cosh.py index 9e465e8127..380a461ba4 100644 --- a/test/test_network_ops/test_cosh.py +++ b/test/test_network_ops/test_cosh.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_cross.py b/test/test_network_ops/test_cross.py index e7e3e08c21..85a69b4e62 100644 --- a/test/test_network_ops/test_cross.py +++ b/test/test_network_ops/test_cross.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_ctc_loss.py b/test/test_network_ops/test_ctc_loss.py index 33df1ec3f4..0b8f7d6fc0 100644 --- a/test/test_network_ops/test_ctc_loss.py +++ b/test/test_network_ops/test_ctc_loss.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_ctc_loss_backward.py b/test/test_network_ops/test_ctc_loss_backward.py index 9d0361901b..423a8a0bef 100644 --- a/test/test_network_ops/test_ctc_loss_backward.py +++ b/test/test_network_ops/test_ctc_loss_backward.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_cummax.py b/test/test_network_ops/test_cummax.py index 71339d6a70..42cb4697cf 100644 --- a/test/test_network_ops/test_cummax.py +++ b/test/test_network_ops/test_cummax.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_cummin.py b/test/test_network_ops/test_cummin.py index 1f7b585b53..a8cf3eb00c 100644 --- a/test/test_network_ops/test_cummin.py +++ b/test/test_network_ops/test_cummin.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_cumprod.py b/test/test_network_ops/test_cumprod.py index 46af72c89b..8eac75d598 100644 --- a/test/test_network_ops/test_cumprod.py +++ b/test/test_network_ops/test_cumprod.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_cumsum.py b/test/test_network_ops/test_cumsum.py index ae1a686e32..c79f2d57be 100644 --- a/test/test_network_ops/test_cumsum.py +++ b/test/test_network_ops/test_cumsum.py @@ -12,8 +12,8 @@ # 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 -- Gitee