已合并
在A5环境上输入数据类型是int类型时调用tensor.div_加rounding_mode=trunc;在A5环境跳过ND->NC1HWC0格式的转换。 #41486
xiaoqi-zhou创建于 7月13日
在A5环境上输入数据类型是int类型时调用tensor.div_加rounding_mode=trunc;在A5环境跳过ND->NC1HWC0格式的转换。 #41486
已合并
共 6 个文件变更+47-31
| @@ -1,16 +1,15 @@ | |||
| 1 | -import unittest | ||
| 2 | import os | 1 | import os |
| 3 | from random import randint | 2 | from random import randint |
| 4 | - | ||
| 5 | import numpy as np | 3 | import numpy as np |
| 4 | + | ||
| 6 | import torch | 5 | import torch |
| 7 | import torch.distributed as dist | 6 | import torch.distributed as dist |
| 8 | import torch.multiprocessing as mp | 7 | import torch.multiprocessing as mp |
| 9 | -import torch_npu | ||
| 10 | 8 | ||
| 9 | +import torch_npu | ||
| 11 | import torch_npu.distributed | 10 | import torch_npu.distributed |
| 12 | from torch_npu.testing.testcase import TestCase, run_tests | 11 | from torch_npu.testing.testcase import TestCase, run_tests |
| 13 | -from torch_npu.testing.common_utils import create_common_tensor | 12 | +from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices |
| 14 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU | 13 | from 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 | + | ||
| 158 | 158 | ||
| 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 | + | ||
| 177 | 178 | ||
| 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 | - | ||
| 5 | import numpy as np | 1 | import numpy as np |
| 2 | + | ||
| 6 | import torch | 3 | import torch |
| 7 | import torch.distributed as dist | 4 | import 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_tests | 6 | +from torch_npu.testing.testcase import run_tests |
| 12 | -from torch_npu.testing.common_utils import create_common_tensor | 7 | +from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices |
| 13 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU | 8 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU |
| 14 | 9 | ||
| 15 | from test_allgather import HcclAllGatherTestBase | 10 | from 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 | + | ||
| 32 | 28 | ||
| 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 | ||
| 2 | import os | 1 | import os |
| 3 | - | ||
| 4 | import numpy as np | 2 | import numpy as np |
| 3 | + | ||
| 5 | import torch | 4 | import torch |
| 6 | import torch.distributed as dist | 5 | import torch.distributed as dist |
| 7 | import torch.multiprocessing as mp | 6 | import torch.multiprocessing as mp |
| 8 | -import torch_npu | ||
| 9 | 7 | ||
| 8 | +import torch_npu | ||
| 10 | from torch_npu.testing.testcase import TestCase, run_tests | 9 | from torch_npu.testing.testcase import TestCase, run_tests |
| 11 | -from torch_npu.testing.common_utils import create_common_tensor | 10 | +from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices |
| 12 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU | 11 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU |
| 13 | 12 | ||
| 14 | 13 | ||
| @@ -73,6 +72,7 @@ class HcclReduceTest(TestCase): | |||
| 73 | 72 | ||
| 74 | return expected | 73 | return expected |
| 75 | 74 | ||
| 75 | + | ||
| 76 | 76 | ||
| 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 | ||
| 2 | import os | 1 | import os |
| 3 | from random import randint | 2 | from random import randint |
| 4 | - | ||
| 5 | import numpy as np | 3 | import numpy as np |
| 4 | + | ||
| 6 | import torch | 5 | import torch |
| 7 | import torch.distributed as dist | 6 | import torch.distributed as dist |
| 8 | import torch.multiprocessing as mp | 7 | import torch.multiprocessing as mp |
| 9 | -import torch_npu | ||
| 10 | 8 | ||
| 9 | +import torch_npu | ||
| 11 | from torch_npu.testing.testcase import TestCase, run_tests | 10 | from torch_npu.testing.testcase import TestCase, run_tests |
| 12 | -from torch_npu.testing.common_utils import create_common_tensor | 11 | +from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices |
| 13 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU | 12 | from 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 | + | ||
| 117 | 117 | ||
| 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 | + | ||
| 138 | 139 | ||
| 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 | - | ||
| 4 | import numpy as np | 1 | import numpy as np |
| 2 | + | ||
| 5 | import torch | 3 | import torch |
| 6 | import torch.distributed as dist | 4 | import 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_tests | 6 | +import torch_npu |
| 11 | -from torch_npu.testing.common_utils import create_common_tensor | 7 | +from torch_npu.testing.testcase import run_tests |
| 8 | +from torch_npu.testing.common_utils import create_common_tensor, SupportedDevices | ||
| 12 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU | 9 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU |
| 13 | 10 | ||
| 14 | from test_reduce_scatter import HcclReduceScatterTestBase | 11 | from 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 | + | ||
| 31 | 29 | ||
| 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 | }, |