已合并
test update ut #5125
huangyunlong创建于 6月6日
test update ut #5125
已合并
共 3 个文件变更+22-7
| @@ -22,7 +22,6 @@ not_support_in_910b = [ | |||
| 22 | "test_custom_ops/test_incre_flash_attention", | 22 | "test_custom_ops/test_incre_flash_attention", |
| 23 | "test_custom_ops/test_npu_ffn", | 23 | "test_custom_ops/test_npu_ffn", |
| 24 | "test_base_ops/test_adaptive_max_pool2d_backward", | 24 | "test_base_ops/test_adaptive_max_pool2d_backward", |
| 25 | - "test_base_ops/test_im2col_backward", | ||
| 26 | "test_base_ops/test_conv_transpose2d_backward", | 25 | "test_base_ops/test_conv_transpose2d_backward", |
| 27 | "test_base_ops/test_gru_true", | 26 | "test_base_ops/test_gru_true", |
| 28 | ] | 27 | ] |
| @@ -72,7 +72,6 @@ class TestForeachAddcmulScalarList(TestCase): | |||
| 72 | 72 | ||
| 73 | self.assertRtolEqual(cpu_output, npu_output) | 73 | self.assertRtolEqual(cpu_output, npu_output) |
| 74 | 74 | ||
| 75 | - | ||
| 76 | def test_foreach_addcmul_scalar_list_out_float16_shpae_tensor_num(self): | 75 | def test_foreach_addcmul_scalar_list_out_float16_shpae_tensor_num(self): |
| 77 | tensor_num_list = [20, 50] | 76 | tensor_num_list = [20, 50] |
| 78 | for tensor_num in tensor_num_list : | 77 | for tensor_num in tensor_num_list : |
| @@ -85,7 +84,7 @@ class TestForeachAddcmulScalarList(TestCase): | |||
| 85 | 84 | ||
| 86 | npu_output = torch._foreach_addcmul(npu_tensors[0], npu_tensors[1], npu_tensors[2], scalars) | 85 | npu_output = torch._foreach_addcmul(npu_tensors[0], npu_tensors[1], npu_tensors[2], scalars) |
| 87 | 86 | ||
| 88 | - self.assertRtolEqual(cpu_output, npu_output) | 87 | + self.assert_equal_bfloat16(cpu_output, npu_output) |
| 89 | 88 | ||
| 90 | 89 | ||
| 91 | def test_foreach_addcmul_scalar_list_out_bfloat16_shpae_tensor_num(self): | 90 | def test_foreach_addcmul_scalar_list_out_bfloat16_shpae_tensor_num(self): |
| @@ -108,7 +107,6 @@ class TestForeachAddcmulScalarList(TestCase): | |||
| 108 | 107 | ||
| 109 | self.assertRtolEqual(cpu_tensors[0], npu_tensors[0]) | 108 | self.assertRtolEqual(cpu_tensors[0], npu_tensors[0]) |
| 110 | 109 | ||
| 111 | - | ||
| 112 | def test_foreach_addcmul_scalar_list_inplace_float16_shpae_tensor_num(self): | 110 | def test_foreach_addcmul_scalar_list_inplace_float16_shpae_tensor_num(self): |
| 113 | tensor_num_list = [20, 50] | 111 | tensor_num_list = [20, 50] |
| 114 | for tensor_num in tensor_num_list : | 112 | for tensor_num in tensor_num_list : |
| @@ -121,7 +119,7 @@ class TestForeachAddcmulScalarList(TestCase): | |||
| 121 | 119 | ||
| 122 | torch._foreach_addcmul_(npu_tensors[0], npu_tensors[1], npu_tensors[2], scalars) | 120 | torch._foreach_addcmul_(npu_tensors[0], npu_tensors[1], npu_tensors[2], scalars) |
| 123 | 121 | ||
| 124 | - self.assertRtolEqual(cpu_output, npu_tensors[0]) | 122 | + self.assert_equal_bfloat16(cpu_output, npu_tensors[0]) |
| 125 | 123 | ||
| 126 | 124 | ||
| 127 | def test_foreach_addcmul_scalar_list_inplace_bfloat16_shpae_tensor_num(self): | 125 | def test_foreach_addcmul_scalar_list_inplace_bfloat16_shpae_tensor_num(self): |
| @@ -10,7 +10,16 @@ from torch_npu.testing.common_utils import create_common_tensor | |||
| 10 | 10 | ||
| 11 | class TestIm2colBackward(TestCase): | 11 | class TestIm2colBackward(TestCase): |
| 12 | 12 | ||
| 13 | - @unittest.skip("Temporarily skipping") | 13 | + def compute_re(self, output, golden): |
| 14 | + diff_value = torch.abs(torch.subtract(output.to(golden.dtype), golden)) | ||
| 15 | + diff_value_rel = diff_value / (torch.abs(golden) + 1e-7) | ||
| 16 | + max_re = torch.max(diff_value_rel).item() | ||
| 17 | + avg_re = torch.mean(diff_value_rel).item() | ||
| 18 | + | ||
| 19 | + diff = torch.subtract(output.to(golden.dtype), golden) | ||
| 20 | + rmse = torch.sqrt(torch.sum(diff*diff)/diff.numel()).item() | ||
| 21 | + return max_re, avg_re, rmse | ||
| 22 | + | ||
| 14 | def test_im2col_backward(self): | 23 | def test_im2col_backward(self): |
| 15 | dtype_list = [np.float16, np.float32] | 24 | dtype_list = [np.float16, np.float32] |
| 16 | shape_list = [[1, 144, 256], [144, 256]] | 25 | shape_list = [[1, 144, 256], [144, 256]] |
| @@ -20,7 +29,16 @@ class TestIm2colBackward(TestCase): | |||
| 20 | cpu_input, npu_input = create_common_tensor((dtype, 0, shape), -100, 100) | 29 | cpu_input, npu_input = create_common_tensor((dtype, 0, shape), -100, 100) |
| 21 | cpu_output = fold_cpu(cpu_input) | 30 | cpu_output = fold_cpu(cpu_input) |
| 22 | npu_output = fold_npu(npu_input) | 31 | npu_output = fold_npu(npu_input) |
| 23 | - self.assertRtolEqual(cpu_output, npu_output.cpu()) | 32 | + if dtype == np.float16: |
| 33 | + golden = fold_cpu(cpu_input.float()) | ||
| 34 | + cpu_max_re, cpu_avg_re, cpu_rmse = self.compute_re(cpu_output, golden) | ||
| 35 | + npu_max_re, npu_avg_re, npu_rmse = self.compute_re(npu_output.cpu(), golden) | ||
| 36 | + self.assertLessEqual(npu_max_re/cpu_max_re, 2) | ||
| 37 | + self.assertLessEqual(npu_avg_re/cpu_avg_re, 1.2) | ||
| 38 | + self.assertLessEqual(npu_rmse/cpu_rmse, 1.2) | ||
| 39 | + | ||
| 40 | + else: | ||
| 41 | + self.assertRtolEqual(cpu_output, npu_output.cpu()) | ||
| 24 | 42 | ||
| 25 | 43 | ||
| 26 | if __name__ == '__main__': | 44 | if __name__ == '__main__': |