已合并
在A5环境上输入数据类型是int类型时调用tensor.div_加rounding_mode=trunc;在A5环境跳过ND->NC1HWC0格式的转换。 #41486
在A5环境上输入数据类型是int类型时调用tensor.div_加rounding_mode=trunc;在A5环境跳过ND->NC1HWC0格式的转换。 #41486
已合并
xiaoqi-zhou创建于 7月13日
6 个文件变更+47-31
@@ -1,16 +1,15 @@
1-import unittest
2import os1import os
3from random import randint2from random import randint
4- 
5import numpy as np3import numpy as np
4+ 
6import torch5import torch
7import torch.distributed as dist6import torch.distributed as dist
8import torch.multiprocessing as mp7import torch.multiprocessing as mp
9-import torch_npu
10 8 
9+import torch_npu
11import torch_npu.distributed10import torch_npu.distributed
12from torch_npu.testing.testcase import TestCase, run_tests11from torch_npu.testing.testcase import TestCase, run_tests
13-from torch_npu.testing.common_utils import create_common_tensor12+from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices
14from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU13from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU
15 14 
16 15 
@@ -155,6 +154,7 @@ class HcclAllGatherTest(HcclAllGatherTestBase):
155 pg.barrier()154 pg.barrier()
156 p2c.get()155 p2c.get()
157 156 
157+ @SupportedDevices(['Ascend910A', 'Ascend910B', 'Ascend910_93'])
158 @skipIfUnsupportMultiNPU(2)158 @skipIfUnsupportMultiNPU(2)
159 def test_all_gather_dist(self):159 def test_all_gather_dist(self):
160 ranks = [2]160 ranks = [2]
@@ -174,6 +174,7 @@ class HcclAllGatherTest(HcclAllGatherTestBase):
174 self._test_multiprocess(HcclAllGatherTest._test_all_gather,174 self._test_multiprocess(HcclAllGatherTest._test_all_gather,
175 HcclAllGatherTest._init_dist_hccl, expected, input1, world_size)175 HcclAllGatherTest._init_dist_hccl, expected, input1, world_size)
176 176 
177+ @SupportedDevices(['Ascend910A', 'Ascend910B', 'Ascend910_93'])
177 @skipIfUnsupportMultiNPU(2)178 @skipIfUnsupportMultiNPU(2)
178 def test_all_gather_dist_different_shape(self):179 def test_all_gather_dist_different_shape(self):
179 ranks = [2]180 ranks = [2]
@@ -1,15 +1,10 @@
1-import unittest
2-import os
3-from random import randint
4- 
5import numpy as np1import numpy as np
2+ 
6import torch3import torch
7import torch.distributed as dist4import torch.distributed as dist
8-import torch.multiprocessing as mp
9-import torch_npu
10 5 
11-from torch_npu.testing.testcase import TestCase, run_tests6+from torch_npu.testing.testcase import run_tests
12-from torch_npu.testing.common_utils import create_common_tensor7+from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices
13from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU8from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU
14 9 
15from test_allgather import HcclAllGatherTestBase10from test_allgather import HcclAllGatherTestBase
@@ -29,6 +24,7 @@ class HcclAllGatherBaseTest(HcclAllGatherTestBase):
29 pg.barrier()24 pg.barrier()
30 p2c.get()25 p2c.get()
31 26 
27+ @SupportedDevices(['Ascend910A', 'Ascend910B', 'Ascend910_93'])
32 @skipIfUnsupportMultiNPU(2)28 @skipIfUnsupportMultiNPU(2)
33 def test_all_gather_base_dist(self):29 def test_all_gather_base_dist(self):
34 ranks = [2]30 ranks = [2]
@@ -1,14 +1,13 @@
1-import unittest
2import os1import os
3- 
4import numpy as np2import numpy as np
3+ 
5import torch4import torch
6import torch.distributed as dist5import torch.distributed as dist
7import torch.multiprocessing as mp6import torch.multiprocessing as mp
8-import torch_npu
9 7 
8+import torch_npu
10from torch_npu.testing.testcase import TestCase, run_tests9from torch_npu.testing.testcase import TestCase, run_tests
11-from torch_npu.testing.common_utils import create_common_tensor10+from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices
12from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU11from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU
13 12 
14 13 
@@ -73,6 +72,7 @@ class HcclReduceTest(TestCase):
73 72 
74 return expected73 return expected
75 74 
75+ @SupportedDevices(['Ascend910A', 'Ascend910B', 'Ascend910_93'])
76 @skipIfUnsupportMultiNPU(2)76 @skipIfUnsupportMultiNPU(2)
77 def test_reduce_dist(self):77 def test_reduce_dist(self):
78 ranks = [2, 4, 8]78 ranks = [2, 4, 8]
@@ -1,15 +1,14 @@
1-import unittest
2import os1import os
3from random import randint2from random import randint
4- 
5import numpy as np3import numpy as np
4+ 
6import torch5import torch
7import torch.distributed as dist6import torch.distributed as dist
8import torch.multiprocessing as mp7import torch.multiprocessing as mp
9-import torch_npu
10 8 
9+import torch_npu
11from torch_npu.testing.testcase import TestCase, run_tests10from torch_npu.testing.testcase import TestCase, run_tests
12-from torch_npu.testing.common_utils import create_common_tensor11+from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices
13from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU12from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU
14 13 
15 14 
@@ -114,6 +113,7 @@ class HcclReduceScatterTest(HcclReduceScatterTestBase):
114 with test_case.assertRaisesRegex(RuntimeError, error_expect):113 with test_case.assertRaisesRegex(RuntimeError, error_expect):
115 pg.reduce_scatter(output, input_list_npu)114 pg.reduce_scatter(output, input_list_npu)
116 115 
116+ @SupportedDevices(['Ascend910A', 'Ascend910B', 'Ascend910_93'])
117 @skipIfUnsupportMultiNPU(2)117 @skipIfUnsupportMultiNPU(2)
118 def test_reduce_scatter(self):118 def test_reduce_scatter(self):
119 ranks = [2]119 ranks = [2]
@@ -135,6 +135,7 @@ class HcclReduceScatterTest(HcclReduceScatterTestBase):
135 self._test_multiprocess(HcclReduceScatterTest._test_reduce_scatter,135 self._test_multiprocess(HcclReduceScatterTest._test_reduce_scatter,
136 HcclReduceScatterTest._init_dist_hccl, expected, input_list, world_size)136 HcclReduceScatterTest._init_dist_hccl, expected, input_list, world_size)
137 137 
138+ @SupportedDevices(['Ascend910A', 'Ascend910B', 'Ascend910_93'])
138 @skipIfUnsupportMultiNPU(2)139 @skipIfUnsupportMultiNPU(2)
139 def test_reduce_scatter_with_different_shape(self):140 def test_reduce_scatter_with_different_shape(self):
140 ranks = [2]141 ranks = [2]
@@ -1,14 +1,11 @@
1-import unittest
2-import os
3- 
4import numpy as np1import numpy as np
2+ 
5import torch3import torch
6import torch.distributed as dist4import torch.distributed as dist
7-import torch.multiprocessing as mp
8-import torch_npu
9 5 
10-from torch_npu.testing.testcase import TestCase, run_tests6+import torch_npu
11-from torch_npu.testing.common_utils import create_common_tensor7+from torch_npu.testing.testcase import run_tests
8+from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices
12from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU9from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU
13 10 
14from test_reduce_scatter import HcclReduceScatterTestBase11from test_reduce_scatter import HcclReduceScatterTestBase
@@ -28,6 +25,7 @@ class HcclReduceScatterBaseTest(HcclReduceScatterTestBase):
28 pg.barrier()25 pg.barrier()
29 p2c.get()26 p2c.get()
30 27 
28+ @SupportedDevices(['Ascend910A', 'Ascend910B', 'Ascend910_93'])
31 @skipIfUnsupportMultiNPU(2)29 @skipIfUnsupportMultiNPU(2)
32 def test_reduce_scatter_base(self):30 def test_reduce_scatter_base(self):
33 ranks = [2]31 ranks = [2]
@@ -4749,8 +4749,13 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::allreduce(
4749 [&](std::vector<c10_npu::NPUStream>& hcclStreams, c10::intrusive_ptr<ProcessGroupHCCL::WorkHCCL>&) {4749 [&](std::vector<c10_npu::NPUStream>& hcclStreams, c10::intrusive_ptr<ProcessGroupHCCL::WorkHCCL>&) {
4750 if (opts.reduceOp == c10d::ReduceOp::AVG) {4750 if (opts.reduceOp == c10d::ReduceOp::AVG) {
4751 c10_npu::NPUStreamGuard guard(hcclStreams[0]);4751 c10_npu::NPUStreamGuard guard(hcclStreams[0]);
4752+ bool is_atlas_a5 = c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend950;
4752 for (auto& tensor : tensors_cp) {4753 for (auto& tensor : tensors_cp) {
4753- tensor.div_(getSize());4754+ if (is_atlas_a5 && at::isIntegralType(tensor.scalar_type(), /*includeBool=*/false)) {
4755+ tensor.div_(getSize(), "trunc");
4756+ } else {
4757+ tensor.div_(getSize());
4758+ }
4754 }4759 }
4755 }4760 }
4756 if (tensors_cp[0].scalar_type() != tensors[0].scalar_type()) {4761 if (tensors_cp[0].scalar_type() != tensors[0].scalar_type()) {
@@ -5087,8 +5092,13 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::reduce(
5087 [&](std::vector<c10_npu::NPUStream>& hcclStreams, c10::intrusive_ptr<ProcessGroupHCCL::WorkHCCL>&) {5092 [&](std::vector<c10_npu::NPUStream>& hcclStreams, c10::intrusive_ptr<ProcessGroupHCCL::WorkHCCL>&) {
5088 if (opts.reduceOp == c10d::ReduceOp::AVG) {5093 if (opts.reduceOp == c10d::ReduceOp::AVG) {
5089 c10_npu::NPUStreamGuard guard(hcclStreams[0]);5094 c10_npu::NPUStreamGuard guard(hcclStreams[0]);
5095+ bool is_atlas_a5 = c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend950;
5090 for (auto& tensor : tensors_cp) {5096 for (auto& tensor : tensors_cp) {
5091- tensor.div_(getSize());5097+ if (is_atlas_a5 && at::isIntegralType(tensor.scalar_type(), /*includeBool=*/false)) {
5098+ tensor.div_(getSize(), "trunc");
5099+ } else {
5100+ tensor.div_(getSize());
5101+ }
5092 }5102 }
5093 }5103 }
5094 if (tensors_cp[0].scalar_type() != tensors[0].scalar_type()) {5104 if (tensors_cp[0].scalar_type() != tensors[0].scalar_type()) {
@@ -5915,8 +5925,13 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::reduce_scatter(
5915 [&](std::vector<c10_npu::NPUStream>& hcclStreams, c10::intrusive_ptr<ProcessGroupHCCL::WorkHCCL>&) {5925 [&](std::vector<c10_npu::NPUStream>& hcclStreams, c10::intrusive_ptr<ProcessGroupHCCL::WorkHCCL>&) {
5916 if (opts.reduceOp == c10d::ReduceOp::AVG) {5926 if (opts.reduceOp == c10d::ReduceOp::AVG) {
5917 c10_npu::NPUStreamGuard guard(hcclStreams[0]);5927 c10_npu::NPUStreamGuard guard(hcclStreams[0]);
5928+ bool is_atlas_a5 = c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend950;
5918 for (auto& tensor : outputTensors) {5929 for (auto& tensor : outputTensors) {
5919- tensor.div_(getSize());5930+ if (is_atlas_a5 && at::isIntegralType(tensor.scalar_type(), /*includeBool=*/false)) {
5931+ tensor.div_(getSize(), "trunc");
5932+ } else {
5933+ tensor.div_(getSize());
5934+ }
5920 }5935 }
5921 }5936 }
5922 },5937 },
@@ -6022,8 +6037,13 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::reduce_scatter(
6022 }6037 }
6023 if (opts.reduceOp == c10d::ReduceOp::AVG) {6038 if (opts.reduceOp == c10d::ReduceOp::AVG) {
6024 c10_npu::NPUStreamGuard guard(hcclStreams[0]);6039 c10_npu::NPUStreamGuard guard(hcclStreams[0]);
6040+ bool is_atlas_a5 = c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend950;
6025 for (auto& tensor : outputTensors) {6041 for (auto& tensor : outputTensors) {
6026- tensor.div_(getSize());6042+ if (is_atlas_a5 && at::isIntegralType(tensor.scalar_type(), /*includeBool=*/false)) {
6043+ tensor.div_(getSize(), "trunc");
6044+ } else {
6045+ tensor.div_(getSize());
6046+ }
6027 }6047 }
6028 }6048 }
6029 },6049 },