diff --git a/test/npu/test_cann_version.py b/test/npu/test_cann_version.py index bb8a8224a7daff00a0c6d3b0d95ef36a320b9544..75e818066f49a9c3eccdd82abcd7f37237f130bb 100644 --- a/test/npu/test_cann_version.py +++ b/test/npu/test_cann_version.py @@ -11,15 +11,40 @@ class TestCANNversion(TestCase): def test_get_cann_version(self): version_env = get_cann_version_from_env() version = get_cann_version(module="CANN") - if not version_env.startswith("CANN") and version_env >= "8.1.RC1": - is_match = (re.match("([0-9]+).([0-9]+).RC([0-9]+)", version) - or re.match("([0-9]+).([0-9]+).([0-9]+)", version) - or re.match("([0-9]+).([0-9]+).T([0-9]+)", version) - or re.match("([0-9]+).([0-9]+).RC([0-9]+).alpha([0-9]+)", version)) - self.assertTrue(is_match, f"The env version is {version_env}. The format of cann version {version} is invalid.") + if not version_env.startswith("CANN"): + if version_env >= "8.1.RC1": + is_match = (re.match("([0-9]+)\.([0-9]+)\.RC([0-9]+)$", version) + or re.match("([0-9]+)\.([0-9]+)\.([0-9]+)$", version) + or re.match("([0-9]+)\.([0-9]+)\.T([0-9]+)$", version) + or re.match("([0-9]+)\.([0-9]+)\.RC([0-9]+)\.alpha([0-9]+)$", version)) + self.assertTrue(is_match, f"The env version is {version_env}. The format of cann version {version} is invalid.") + else: + self.assertTrue(version == "", "When verssion_env < '8.1.RC1', the result of get_cann_version is not right.") version = get_cann_version(module="CAN") self.assertTrue(version == "", "When module is invalid, the result of get_cann_version is not right.") + + def test_get_driver_version(self): + try: + version = get_cann_version(module="DRIVER") + except UnicodeDecodeError: + print("Failed to get driver version. Your driver version is too old, or the environment information about the driver may be incomplete.") + return + if re.match("([0-9]+)\.([0-9]+)\.RC([0-9]+)\.B([0-9]+)$", version, re.IGNORECASE): + version = re.sub(".B([0-9]+)", "", version, flags=re.IGNORECASE) + if re.match("([0-9]+)\.", version): + if version >= "25.": + is_match = (re.match("([0-9]+)\.([0-9]+)\.RC([0-9]+)$", version, re.IGNORECASE) + or re.match("([0-9]+)\.([0-9]+)\.([0-9]+)$", version) + or re.match("([0-9]+)\.([0-9]+)\.RC([0-9]+)\.([0-9]+)$", version, re.IGNORECASE) + or re.match("([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$", version) + or re.match("([0-9]+)\.([0-9]+)\.T([0-9]+)$", version, re.IGNORECASE) + or re.match("([0-9]+)\.([0-9]+)\.RC([0-9]+)\.beta([0-9]+)$", version, re.IGNORECASE) + or re.match("([0-9]+)\.([0-9]+)\.RC([0-9]+)\.alpha([0-9]+)$", version, re.IGNORECASE) + ) + self.assertTrue(is_match, f"The format of driver version {version} is invalid.") + else: + self.assertTrue(version == "", "When verssion_env < '25.', the result of get_cann_version is not right.") def test_compare_cann_version(self): version_env = get_cann_version_from_env() diff --git a/test/test_fake_tensor.py b/test/test_fake_tensor.py index ccb4493a7d9df6f19bbcb1e8ff886fe6e5e9eb2e..dc109317f98f64f25f4139defd4a5004da6a0a6f 100644 --- a/test/test_fake_tensor.py +++ b/test/test_fake_tensor.py @@ -1781,7 +1781,7 @@ class TestGroupedMatmul(TestCase): group_list = None split_item = 0 - res = torch_npu.npu_grouped_matmul(x, w, bias=b, group_list=group_list, split_item=split_item) + res = torch_npu.npu_grouped_matmul(x, w, bias=b, group_list=group_list, split_item=split_item, group_type=-1) self.assertTrue(x[0].shape[0] == res[0].shape[0]) self.assertTrue(x[1].shape[0] == res[1].shape[0]) self.assertTrue(x[2].shape[0] == res[2].shape[0]) @@ -1805,7 +1805,7 @@ class TestGroupedMatmul(TestCase): group_list = [256, 1280, 1792] split_item = 1 - res = torch_npu.npu_grouped_matmul(x, w, bias=b, group_list=group_list, split_item=split_item) + res = torch_npu.npu_grouped_matmul(x, w, bias=b, group_list=group_list, split_item=split_item, group_type=-1) self.assertTrue(group_list[0] == res[0].shape[0]) self.assertTrue(group_list[1] - group_list[0] == res[1].shape[0]) self.assertTrue(group_list[2] - group_list[1] == res[2].shape[0]) @@ -1831,7 +1831,7 @@ class TestGroupedMatmul(TestCase): group_list = None split_item = 2 - res = torch_npu.npu_grouped_matmul(x, w, bias=b, group_list=group_list, split_item=split_item) + res = torch_npu.npu_grouped_matmul(x, w, bias=b, group_list=group_list, split_item=split_item, group_type=0) dim0 = 0 for xi in x: dim0 += xi.shape[0] @@ -1854,7 +1854,7 @@ class TestGroupedMatmul(TestCase): group_list = [256, 1280, 1792] split_item = 3 - res = torch_npu.npu_grouped_matmul(x, w, bias=b, group_list=group_list, split_item=split_item) + res = torch_npu.npu_grouped_matmul(x, w, bias=b, group_list=group_list, split_item=split_item, group_type=0) self.assertTrue(x[0].shape[0] == res[0].shape[0]) self.assertTrue(w[0].shape[1] == res[0].shape[1]) @@ -1885,20 +1885,20 @@ class TestQuantMatmul(TestCase): expect_ret = torch.randint(-1, 1, (1, 1, 100), dtype=torch.int8).npu() scale = torch.randn(1, dtype=torch.float32).npu() offset = torch.randn(1, dtype=torch.float32).npu() - bias = torch.randint(-1, -1, (1, 1, 100), dtype=torch.int32).npu() + bias = torch.randint(-1, 1, (1, 1, 100), dtype=torch.int32).npu() res = torch_npu.npu_quant_matmul(x1, x2, scale, offset=offset, bias=bias) self.assertTrue(expect_ret.shape == res.shape) self.assertTrue(expect_ret.dtype == res.dtype) expect_ret_bf16 = torch.randint(-1, 1, (1, 1, 100), dtype=torch.bfloat16).npu() scale_bf16 = torch.randn(1, dtype=torch.bfloat16).npu() - bias_bf16 = torch.randint(-1, -1, (1, 1, 100), dtype=torch.bfloat16).npu() + bias_bf16 = torch.randint(-1, 1, (1, 1, 100), dtype=torch.bfloat16).npu() res_bf16 = torch_npu.npu_quant_matmul(x1, x2, scale_bf16, offset=None, bias=bias_bf16, output_dtype=torch.bfloat16) self.assertTrue(expect_ret_bf16.shape == res_bf16.shape) self.assertTrue(expect_ret_bf16.dtype == res_bf16.dtype) expect_ret_fp16 = torch.randint(-1, 1, (1, 1, 100), dtype=torch.float16).npu() - bias_fp32 = torch.randint(-1, -1, (1, 1, 100), dtype=torch.float32).npu() + bias_fp32 = torch.randint(-1, 1, (1, 1, 100), dtype=torch.float32).npu() pertoken_scale = torch.randn(1, dtype=torch.float32).npu() res_fp16 = torch_npu.npu_quant_matmul(x1, x2, scale, offset=None, pertoken_scale=pertoken_scale, bias=bias_fp32, output_dtype=torch.float16) @@ -1906,7 +1906,7 @@ class TestQuantMatmul(TestCase): self.assertTrue(expect_ret_fp16.dtype == res_fp16.dtype) expect_ret_int32 = torch.randint(-1, 1, (1, 1, 100), dtype=torch.int32).npu() - bias_int32 = torch.randint(-1, -1, (1, 1, 100), dtype=torch.int32).npu() + bias_int32 = torch.randint(-1, 1, (1, 1, 100), dtype=torch.int32).npu() res_int32 = torch_npu.npu_quant_matmul(x1, x2, scale, offset=None, pertoken_scale=None, bias=bias_int32, output_dtype=torch.int32) self.assertTrue(expect_ret_int32.shape == res_int32.shape) @@ -1916,7 +1916,7 @@ class TestQuantMatmul(TestCase): x2 = torch.randint(-1, 1, (64, 5), dtype=torch.int32).npu() expect_ret = torch.randint(-1, 1, (16, 40), dtype=torch.float16).npu() scale = torch.randn(1, dtype=torch.float32).npu() - bias = torch.randint(-1, -1, (40,), dtype=torch.int32).npu() + bias = torch.randint(-1, 1, (40,), dtype=torch.int32).npu() res = torch_npu.npu_quant_matmul(x1, x2, scale, offset=None, bias=bias, output_dtype=torch.float16) self.assertTrue(expect_ret.shape == res.shape) self.assertTrue(expect_ret.dtype == res.dtype)