diff --git a/ops_configs/atb_ops_info.ini b/ops_configs/atb_ops_info.ini index 183cc7981c8cb770b7d0836e2838dd416f5061a9..95f76caa904e778c001161122ff3c38a58e2e89a 100644 --- a/ops_configs/atb_ops_info.ini +++ b/ops_configs/atb_ops_info.ini @@ -1,10 +1,10 @@ [ActivationOperationGELUAndFORWARD] input0.name=x -input0.dtype=float,float16,bf16,float,float16,bf16 -input0.format=nd,nd,nd,fractal_nz,fractal_nz,fractal_nz +input0.dtype=float,float16,bf16 +input0.format=nd,nd,nd output0.name=y -output0.dtype=float,float16,bf16,float,float16,bf16 -output0.format=nd,nd,nd,fractal_nz,fractal_nz,fractal_nz +output0.dtype=float,float16,bf16 +output0.format=nd,nd,nd [ActivationOperationLOG] input0.name=x input0.dtype=float,float16,bf16 @@ -53,11 +53,11 @@ output0.format=nd,nd,nd [ActivationOperationFasterGeluForward] input0.name=x -input0.dtype=float,float16,bf16,float,float16,bf16 -input0.format=nd,nd,nd,fractal_nz,fractal_nz,fractal_nz +input0.dtype=float,float16,bf16 +input0.format=nd,nd,nd output0.name=y -output0.dtype=float,float16,bf16,float,float16,bf16 -output0.format=nd,nd,nd,fractal_nz,fractal_nz,fractal_nz +output0.dtype=float,float16,bf16 +output0.format=nd,nd,nd [AllGatherVOperation] input0.name=x diff --git a/src/ops_infer/activation/activation_operation.cpp b/src/ops_infer/activation/activation_operation.cpp index 6b26ecedd25d668913b146ab49fe553688678664..71b592977efcf4fdecf59c4b8a0f84afdb0e3cf8 100644 --- a/src/ops_infer/activation/activation_operation.cpp +++ b/src/ops_infer/activation/activation_operation.cpp @@ -121,7 +121,7 @@ Status ActivationOperation::CheckSwigluBackwardInTensor(const SVector(splitDim) == i) { if (inTensorDescs.at(1).shape.dims[i] != SPLIT_NUM * inTensorDescs.at(0).shape.dims[i]) { - ATB_LOG(ERROR) << GetLogPrefix() << "Dims[" << i << "] of inTensor0 should be half of inTnesor1."; + ATB_LOG(ERROR) << GetLogPrefix() << "Dims[" << i << "] of inTensor0 should be half of inTensor1."; return ERROR_INVALID_TENSOR_DIM; } } else { diff --git a/tests/apitest/opstest/python/operations/activation/test_activation.py b/tests/apitest/opstest/python/operations/activation/test_activation.py index 0bfcd0679493ca7a20494f3b17748dca27e824b6..13f5d3be081b6230d44d512e89949a467822d17e 100644 --- a/tests/apitest/opstest/python/operations/activation/test_activation.py +++ b/tests/apitest/opstest/python/operations/activation/test_activation.py @@ -89,60 +89,6 @@ class TestSwigluBackwardOperation(operation_test.OperationTest): self.execute(OP_NAME, {"activationType": 7, "dim": self.SPLIT_DIM}, [torch.from_numpy(input0).npu().float(), torch.from_numpy(input1).npu().float()]) -class TestFasterGeluForwardNz310pFp16Operation(operation_test.OperationTest): - def golden_calc(self, in_tensors): - float_in_tensors = in_tensors[0].float() - float_result = get_golden_data(float_in_tensors) - return [float_result.half()] - - def test(self): - if operation_test.get_soc_version() == 'Ascend310B': - logging.info("this testcase don't supports Ascend310B") - return True - for shape in [[40, 24], [1, 1024], [8, 5504], [8, 64], [8192, 5504], [8192, 64], [1123, 4032]]: - intensor0 = torch.rand(shape[0], shape[1], dtype=torch.float16).npu().half() - intensor0 = intensor0 * (HIGH_NUM - (LOW_NUM)) + LOW_NUM - intensor0 = tensor_nd_to_nz_2d(intensor0) - intensor0 = torch_npu.npu_format_cast(intensor0, 29) - self.execute(OP_NAME, PARAM_FASTER_GELU_FORWARD, [intensor0]) - - -class TestFasterGeluForwardNz310pFp32Operation(operation_test.OperationTest): - def golden_calc(self, in_tensors): - float_in_tensors = in_tensors[0].float() - float_result = get_golden_data(float_in_tensors) - return [float_result.float()] - - def test(self): - if operation_test.get_soc_version() == 'Ascend310B': - logging.info("this testcase don't supports Ascend310B") - return True - for shape in [[40, 24], [1, 1024], [8, 5504], [8, 64], [8192, 5504], [8192, 64], [1123, 4032]]: - intensor0 = torch.rand(shape[0], shape[1]).npu().float() - intensor0 = intensor0 * (HIGH_NUM - (LOW_NUM)) + LOW_NUM - intensor0 = tensor_nd_to_nz_2d(intensor0) - intensor0 = torch_npu.npu_format_cast(intensor0, 29) - self.execute(OP_NAME, PARAM_FASTER_GELU_FORWARD, [intensor0]) - - -class TestFasterGeluForwardNz910Bf16Operation(operation_test.OperationTest): - def golden_calc(self, in_tensors): - float_in_tensors = in_tensors[0].bfloat16() - float_result = get_golden_data(float_in_tensors) - return [float_result.bfloat16()] - - def test(self): - if not operation_test.get_soc_version() == 'Ascend910B': - print("this testcase only supports Ascend910B") - return True - for shape in [[40, 24], [1, 1024], [8, 5504], [8, 64], [8192, 5504], [8192, 64], [1123, 4032]]: - intensor0 = torch.rand(shape[0], shape[1]).npu().bfloat16() - intensor0 = intensor0 * (HIGH_NUM - (LOW_NUM)) + LOW_NUM - intensor0 = tensor_nd_to_nz_2d(intensor0) - intensor0 = torch_npu.npu_format_cast(intensor0, 29) - self.execute(OP_NAME, PARAM_FASTER_GELU_FORWARD, [intensor0]) - - class TestFasterGeluForwardNd310pFp16Operation(operation_test.OperationTest): def golden_calc(self, in_tensors): float_in_tensors = in_tensors[0].float() @@ -278,85 +224,5 @@ def get_golden_data(in_tensors): return in_tensors * torch.exp(0.851 * (in_tensors - torch.abs(in_tensors))) / ( 1 + torch.exp(-1.702 * torch.abs(in_tensors))) - -def tensor_nd_to_nz_2d(in_tensors): - ALIGN_INT8 = 32 - DEFAULT_ALIGN = 16 - - aux_dims = [0, 0, 0, 0] - aux_dims[0] = 1 - aux_dims[1] = round_up(in_tensors.size(0), DEFAULT_ALIGN) - - pad_dims = [0, 0, 0, 0] - pad_dims[3] = round_up(in_tensors.size(0), DEFAULT_ALIGN) - in_tensors.size(0) - - if in_tensors.dtype == torch.int8: - aux_dims[2] = round_up(in_tensors.size(1), ALIGN_INT8) // ALIGN_INT8 - aux_dims[3] = ALIGN_INT8 - pad_dims[1] = round_up(in_tensors.size(1), ALIGN_INT8) - in_tensors.size(1) - else: - aux_dims[2] = round_up(in_tensors.size(1), DEFAULT_ALIGN) // DEFAULT_ALIGN - aux_dims[3] = DEFAULT_ALIGN - pad_dims[1] = round_up(in_tensors.size(1), DEFAULT_ALIGN) - in_tensors.size(1) - - return custom_transpose(custom_reshape(custom_pad(in_tensors, pad_dims), aux_dims), 1, 2).contiguous() - - -def tensor_nd_to_nz_3d(in_tensors): - ALIGN_INT8 = 32 - DEFAULT_ALIGN = 16 - - aux_dims = [0, 0, 0, 0] - aux_dims[0] = in_tensors.size(0) - aux_dims[1] = round_up(in_tensors.size(1), DEFAULT_ALIGN) - - pad_dims = [0, 0, 0, 0] - pad_dims[3] = round_up(in_tensors.size(1), DEFAULT_ALIGN) - in_tensors.size(1) - - if in_tensors[0].dtype == torch.int8: - aux_dims[2] = round_up(in_tensors.size(2), ALIGN_INT8) // ALIGN_INT8 - aux_dims[3] = ALIGN_INT8 - pad_dims[1] = round_up(in_tensors.size(2), ALIGN_INT8) - in_tensors.size(2) - else: - aux_dims[2] = round_up(in_tensors.size(2), DEFAULT_ALIGN) // DEFAULT_ALIGN - aux_dims[3] = DEFAULT_ALIGN - pad_dims[1] = round_up(in_tensors.size(2), DEFAULT_ALIGN) - in_tensors.size(2) - - pad_op = custom_pad(in_tensors, pad_dims) - reshape_op = custom_reshape(pad_op, aux_dims) - transpose_op = custom_transpose(reshape_op, 1, 2) - - return transpose_op.contiguous() - - -def tensor_nz_to_nd(in_tensors, outCrops): - aux_dims = [0, 0, 0] - aux_dims[0] = in_tensors.size(0) - aux_dims[1] = in_tensors.size(2) - aux_dims[2] = in_tensors.size(1) * in_tensors.size(3) - transpose_op = custom_transpose(in_tensors, 1, 2) - reshape_op = custom_reshape(transpose_op, aux_dims) - split_op = reshape_op[:, :outCrops[0], :outCrops[1]] - return split_op - - -def round_up(x, align): - if align == 0: - return -1 - return (x + align - 1) // align * align - - -def custom_transpose(x, dim1, dim2): - return x.transpose(dim1, dim2) - - -def custom_pad(x, pad_dims): - return torch.nn.functional.pad(x, pad_dims) - - -def custom_reshape(x, target_shape): - return x.reshape(target_shape) - - if __name__ == '__main__': unittest.main()