diff --git a/test/test_network_ops/test_cdist.py b/test/test_network_ops/test_cdist.py index d300f190295c077a8903acd936c2ac8cf84ec423..80cc5df5f6e94b568bee7536fdf6eed273dec1b0 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 fb8e5c5d5ddc33a8f9297bda591e8d5e30728911..f7c844ba292c51b3ea3ce662b35c6ca382391fc8 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 17f20c4fba5b663abeeb92381f6e0b4bfe18820b..1e6cdf0c6e133d6b1d4878f03c15761fc42d3023 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 631c16d1caac6e90b967a62226529abac7bb1901..90446f4b7e0e2fc20f7a13601f7779d03d6a24a8 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 fc32b89ec955cd707a1271bbc13e059abc9fc073..affd8be81b331e94731422c40096f553007a796a 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 12c78852bf3987622d7b2589ca5c23dcbdfc471d..73dcfdcfa671121398b1daed237e43892e09a98c 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 8abf146177827e8bf6f34e375078f03e1ef667ba..2687c9ecd776e4592760b9b44eb7eeb550539671 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 a1dfb59c4eb750f5edcc169ef7c58947fcd41257..363992c7ce2f23e14ffc89ffd51d8221520f6ca8 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 09699710d0113ef2ae129a661970607b44727e81..2e32c3ba824a73a69e96a94f0443a3c98a1d4d05 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 4921bcc4d4a4380b4ea3f3f45a09c813ab473374..f8dc8811f4098fd452c7b75cddc93f76c725b719 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 591c51fac1d49339500c51f044fbef6d4a3fc839..8737727cf1dfc8917ce6058fcb93f77b2e469136 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 e00838b97b4192eae99cca60bb2514c2aee0f620..8a8fe6a0e6f159d8651c91bb09e67d41314da7ca 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 168d8faaec78ed4d96aae23c88fd958b757a4ee7..7affc60ccce7ea0f0262927ceff2320e2c6e92ff 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 addc77a2e01a3478cf118fe309bae9ddb8cd4dab..d62e268e0d347f70466c6130b36deb6463c5a4a1 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 8a4224abd74cd79681f30b90c1f7de2f384f64d6..739a5a40038a2c0407473846846420eafafe0f00 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 5bcdc55e838e9662bc0f79d5829c41ceaf9cd025..881e1320ad461d4c210474c561274cc0c3be7df3 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 55f52b513db50007a4b3b7a8296dc2e49aef4470..81abf7484021252bf95f674169fa997f211c2f3a 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 d72ffa1aa596cdad969dc418b9e379f0d86c00cd..d9b11213fb63a3c80bda415070b4de39cdc1fdba 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 49cd18f9253f4fa9ff318f6dc51e4e38d60946d8..b5c629c67191f557c553ef5e0faea9a89bf93b6e 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 9e465e8127017a54840ed12041c963742e2992d7..380a461ba4b0f66988c16f4b169da1017dad4289 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 e7e3e08c2183801d88ac380cd12ef3a97c26e885..85a69b4e62e0eacdc6b87fe5efb2d9a245567342 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 33df1ec3f480b30ba5c7822950cc1ed891927625..0b8f7d6fc084e776a2fdc859013b7cf38bc4910c 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 9d0361901b23b190e561e1a4189f000c12283ab9..423a8a0bef4fad45be280f961c19d2a6eb3751ba 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 71339d6a70aefcef8526030250471d93c4b1cf9e..42cb4697cf47c8869c67c33cd3b37aeb6cb75678 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 1f7b585b53c6f40d7795e310f933e727b24e0e01..a8cf3eb00cfea77f715c0cdd6597a962d19e577f 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 46af72c89b290d7bf7cff0e6296d73f32be641c9..8eac75d598bb049d7bc98f3d72df76c62b0084cb 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 ae1a686e324e894ac17f51b2f2db9d74585aed87..c79f2d57be3d55d201c281ce3da0ed9e576da4ca 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