Merged
modify anti_mx_quant aclnn #14252
modify anti_mx_quant aclnn #14252
Merged
pyongqAdd on 10 days ago
Total: 6 files changed+239-17
@@ -85,7 +85,7 @@ aclnnStatus aclnnAntiMxQuant(
85 <td>x (aclTensor*)</td>85 <td>x (aclTensor*)</td>
86 <td>输入</td>86 <td>输入</td>
87 <td>表示算子输入的量化Tensor。对应公式中的Xq。</td>87 <td>表示算子输入的量化Tensor。对应公式中的Xq。</td>
88- <td>支持空Tensor。</td>88+ <td><ul><li>支持空Tensor。</li><li>x为空Tensor时,y与mxscale也须为空Tensor。</li></ul></td>
89 <td>FLOAT4_E2M1、FLOAT4_E1M2、FLOAT8_E4M3FN、FLOAT8_E5M2</td>89 <td>FLOAT4_E2M1、FLOAT4_E1M2、FLOAT8_E4M3FN、FLOAT8_E5M2</td>
90 <td>ND</td>90 <td>ND</td>
91 <td>1-7,需要和DynamicMxQuant的输出保持一致</td>91 <td>1-7,需要和DynamicMxQuant的输出保持一致</td>
@@ -95,7 +95,7 @@ aclnnStatus aclnnAntiMxQuant(
95 <td>mxscale (aclTensor*)</td>95 <td>mxscale (aclTensor*)</td>
96 <td>输入</td>96 <td>输入</td>
97 <td>调用DynamicMxQuant计算得到的量化尺度。对应公式中的sf。</td>97 <td>调用DynamicMxQuant计算得到的量化尺度。对应公式中的sf。</td>
98- <td><ul><li>支持空Tensor。</li><li>shape需满足约束说明中的公式。</li></ul></td>98+ <td><ul><li>仅当x为空Tensor时允许为空Tensor,其余情况不支持空Tensor(shape中含0维),返回161002。</li><li>shape需满足约束说明中的公式。</li></ul></td>
99 <td>FLOAT8_E8M0</td>99 <td>FLOAT8_E8M0</td>
100 <td>ND</td>100 <td>ND</td>
101 <td>2-8,需要和DynamicMxQuant的输出保持一致</td>101 <td>2-8,需要和DynamicMxQuant的输出保持一致</td>
@@ -125,7 +125,7 @@ aclnnStatus aclnnAntiMxQuant(
125 <td>y (aclTensor*)</td>125 <td>y (aclTensor*)</td>
126 <td>输出</td>126 <td>输出</td>
127 <td>表示反量化后的输出Tensor。对应公式中的Xdq。</td>127 <td>表示反量化后的输出Tensor。对应公式中的Xdq。</td>
128- <td><ul><li>支持空Tensor。</li><li>shape维度与x保持一致。</li><li>数据类型需与dstType对应。</li></ul></td>128+ <td><ul><li>仅当x为空Tensor时允许为空Tensor,其余情况不支持空Tensor。</li><li>shape需与x完全一致。</li><li>数据类型需与dstType对应。</li></ul></td>
129 <td>FLOAT16、BFLOAT16、FLOAT32</td>129 <td>FLOAT16、BFLOAT16、FLOAT32</td>
130 <td>ND</td>130 <td>ND</td>
131 <td>1-7</td>131 <td>1-7</td>
@@ -179,8 +179,8 @@ aclnnStatus aclnnAntiMxQuant(
179 <tr>179 <tr>
180 </tr>180 </tr>
181 <tr>181 <tr>
182- <td rowspan="5">ACLNN_ERR_PARAM_INVALID</td>182+ <td rowspan="6">ACLNN_ERR_PARAM_INVALID</td>
183- <td rowspan="5">161002</td>183+ <td rowspan="6">161002</td>
184 <td>x、mxscale、y的数据类型不在支持的范围之内。</td>184 <td>x、mxscale、y的数据类型不在支持的范围之内。</td>
185 </tr>185 </tr>
186 <tr>186 <tr>
@@ -195,6 +195,9 @@ aclnnStatus aclnnAntiMxQuant(
195 <tr>195 <tr>
196 <td>y的数据类型和dstType不符合对应关系。</td>196 <td>y的数据类型和dstType不符合对应关系。</td>
197 </tr>197 </tr>
198+ <tr>
199+ <td>仅x、mxscale、y中的部分输入为空Tensor。</td>
200+ </tr>
198 <tr>201 <tr>
199 <td rowspan="1">ACLNN_ERR_RUNTIME_ERROR</td>202 <td rowspan="1">ACLNN_ERR_RUNTIME_ERROR</td>
200 <td rowspan="1">361001</td>203 <td rowspan="1">361001</td>
@@ -256,6 +259,7 @@ aclnnStatus aclnnAntiMxQuant(
256 - mxscale.shape[-1] = 2。259 - mxscale.shape[-1] = 2。
257 - rank(mxscale) = rank(x) + 1。260 - rank(mxscale) = rank(x) + 1。
258 - 其它维度与输入x一致。261 - 其它维度与输入x一致。
262+- 空Tensor约束:仅支持x、y、mxscale同时为空Tensor的场景,此时接口返回成功且workspaceSize为0;仅部分输入为空Tensor(如mxscale的shape含0维而x非空)属于非法入参,返回161002。
259 263 
260## 调用示例264## 调用示例
261 265 
@@ -87,7 +87,7 @@ aclnnStatus aclnnAntiMxQuant(
87 <td>x (aclTensor*)</td>87 <td>x (aclTensor*)</td>
88 <td>Input</td>88 <td>Input</td>
89 <td>Quantization tensor input of the operator. Corresponds to Xq in the formula.</td>89 <td>Quantization tensor input of the operator. Corresponds to Xq in the formula.</td>
90- <td>Supports empty tensors.</td>90+ <td><ul><li>Supports empty tensors.</li><li>If x is an empty tensor, y and mxscale must also be empty tensors.</li></ul></td>
91 <td>FLOAT4_E2M1, FLOAT4_E1M2, FLOAT8_E4M3FN, FLOAT8_E5M2</td>91 <td>FLOAT4_E2M1, FLOAT4_E1M2, FLOAT8_E4M3FN, FLOAT8_E5M2</td>
92 <td>ND</td>92 <td>ND</td>
93 <td>1-7, must be consistent with the output of DynamicMxQuant</td>93 <td>1-7, must be consistent with the output of DynamicMxQuant</td>
@@ -97,7 +97,7 @@ aclnnStatus aclnnAntiMxQuant(
97 <td>mxscale (aclTensor*)</td>97 <td>mxscale (aclTensor*)</td>
98 <td>Input</td>98 <td>Input</td>
99 <td>Quantization scale computed by calling DynamicMxQuant. Corresponds to sf in the formula.</td>99 <td>Quantization scale computed by calling DynamicMxQuant. Corresponds to sf in the formula.</td>
100- <td><ul><li>Supports empty tensors.</li><li>The shape must satisfy the formula in Constraints.</li></ul></td>100+ <td><ul><li>Empty tensors are allowed only when x is an empty tensor. Otherwise, empty tensors (shapes containing a 0 dimension) are not supported and 161002 is returned.</li><li>The shape must satisfy the formula in Constraints.</li></ul></td>
101 <td>FLOAT8_E8M0</td>101 <td>FLOAT8_E8M0</td>
102 <td>ND</td>102 <td>ND</td>
103 <td>2-8, must be consistent with the output of DynamicMxQuant</td>103 <td>2-8, must be consistent with the output of DynamicMxQuant</td>
@@ -127,7 +127,7 @@ aclnnStatus aclnnAntiMxQuant(
127 <td>y (aclTensor*)</td>127 <td>y (aclTensor*)</td>
128 <td>Output</td>128 <td>Output</td>
129 <td>Indicates the dequantized output tensor. Corresponds to Xdq in the corresponding formula.</td>129 <td>Indicates the dequantized output tensor. Corresponds to Xdq in the corresponding formula.</td>
130- <td><ul><li>Supports empty tensors.</li><li>The shape must be the same as that of x.</li><li>The data type must correspond to dstType.</li></ul></td>130+ <td><ul><li>Empty tensors are allowed only when x is an empty tensor. Otherwise, empty tensors are not supported.</li><li>The shape must be exactly the same as that of x.</li><li>The data type must correspond to dstType.</li></ul></td>
131 <td>FLOAT16, BFLOAT16, FLOAT32</td>131 <td>FLOAT16, BFLOAT16, FLOAT32</td>
132 <td>ND</td>132 <td>ND</td>
133 <td>1-7</td>133 <td>1-7</td>
@@ -181,8 +181,8 @@ aclnnStatus aclnnAntiMxQuant(
181 <tr>181 <tr>
182 </tr>182 </tr>
183 <tr>183 <tr>
184- <td rowspan="5">ACLNN_ERR_PARAM_INVALID</td>184+ <td rowspan="6">ACLNN_ERR_PARAM_INVALID</td>
185- <td rowspan="5">161002</td>185+ <td rowspan="6">161002</td>
186 <td>The data type of x, mxscale, or y is not within the supported range.</td>186 <td>The data type of x, mxscale, or y is not within the supported range.</td>
187 </tr>187 </tr>
188 <tr>188 <tr>
@@ -197,6 +197,9 @@ aclnnStatus aclnnAntiMxQuant(
197 <tr>197 <tr>
198 <td>The data type of y does not satisfy the corresponding relationship with dstType.</td>198 <td>The data type of y does not satisfy the corresponding relationship with dstType.</td>
199 </tr>199 </tr>
200+ <tr>
201+ <td>Only some of x, mxscale, and y are empty tensors.</td>
202+ </tr>
200 <tr>203 <tr>
201 <td rowspan="1">ACLNN_ERR_RUNTIME_ERROR</td>204 <td rowspan="1">ACLNN_ERR_RUNTIME_ERROR</td>
202 <td rowspan="1">361001</td>205 <td rowspan="1">361001</td>
@@ -258,6 +261,7 @@ aclnnStatus aclnnAntiMxQuant(
258 - mxscale.shape[-1] = 2.261 - mxscale.shape[-1] = 2.
259 - rank(mxscale) = rank(x) + 1.262 - rank(mxscale) = rank(x) + 1.
260 - Other dimensions are the same as those of input x.263 - Other dimensions are the same as those of input x.
264+- Empty tensor constraint: only the scenario where x, y, and mxscale are all empty tensors is supported. In this case, the API returns success and workspaceSize is 0. If only some of the inputs are empty tensors (for example, mxscale contains a 0 dimension in its shape while x is not empty), the input is invalid and 161002 is returned.
261 265 
262## Example266## Example
263 267 
@@ -12,6 +12,8 @@
12#include "anti_mx_quant.h"12#include "anti_mx_quant.h"
13#include "aclnn_kernels/contiguous.h"13#include "aclnn_kernels/contiguous.h"
14#include "aclnn_kernels/common/op_error_check.h"14#include "aclnn_kernels/common/op_error_check.h"
15+#include "log/log.h"
16+#include <string>
15#include "opdev/common_types.h"17#include "opdev/common_types.h"
16#include "opdev/data_type_utils.h"18#include "opdev/data_type_utils.h"
17#include "opdev/format_utils.h"19#include "opdev/format_utils.h"
@@ -33,6 +35,8 @@ static constexpr int64_t FP4_NUMS_IN_UINT8 = 2;
33static constexpr int64_t NUM_FLOAT32 = 0;35static constexpr int64_t NUM_FLOAT32 = 0;
34static constexpr int64_t NUM_FLOAT16 = 1;36static constexpr int64_t NUM_FLOAT16 = 1;
35static constexpr int64_t NUM_BFLOAT16 = 27;37static constexpr int64_t NUM_BFLOAT16 = 27;
38+static constexpr int64_t MX_BLOCK_SIZE = 32;
39+static constexpr int64_t MXSCALE_TAIL_DIM = 2;
36 40 
37static const std::initializer_list<DataType> X_DTYPE_SUPPORT_LIST = {41static const std::initializer_list<DataType> X_DTYPE_SUPPORT_LIST = {
38 op::DataType::DT_FLOAT4_E2M1, op::DataType::DT_FLOAT4_E1M2, op::DataType::DT_FLOAT8_E5M2,42 op::DataType::DT_FLOAT4_E2M1, op::DataType::DT_FLOAT4_E1M2, op::DataType::DT_FLOAT8_E5M2,
@@ -78,6 +82,14 @@ static bool CheckShape(const aclTensor* x, const aclTensor* y, const aclTensor*
78 return false;82 return false;
79 }83 }
80 84 
85+ // y和x的shape必须一致
86+ OP_CHECK(xShape == yShape,
87+ OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(
88+ "aclnnAntiMxQuant", "y,x",
89+ (std::string(op::ToString(yShape).GetString()) + ", " + op::ToString(xShape).GetString()).c_str(),
90+ "shapes of y and x should be the same"),
91+ return false);
92+ 
81 // x dim num check93 // x dim num check
82 OP_CHECK_MAX_DIM(x, MAX_DIM_LEN, return false);94 OP_CHECK_MAX_DIM(x, MAX_DIM_LEN, return false);
83 95 
@@ -102,6 +114,23 @@ static bool CheckShape(const aclTensor* x, const aclTensor* y, const aclTensor*
102 return false;114 return false;
103 }115 }
104 116 
117+ // Construct expected mxscale shape:
118+ // mxscale.shape[axis] = (ceil(x.shape[axis] / blocksize) + 2 - 1) / 2
119+ // mxscale.shape[-1] = 2
120+ // mxscale rank = x rank + 1
121+ auto expectedMxscaleShape = xShape;
122+ int64_t axisScaledSize = (xShape.GetDim(axisChange) + MX_BLOCK_SIZE - 1) / MX_BLOCK_SIZE;
123+ axisScaledSize = (axisScaledSize + 1) / MXSCALE_TAIL_DIM;
124+ expectedMxscaleShape.SetDim(axisChange, axisScaledSize);
125+ expectedMxscaleShape.AppendDim(MXSCALE_TAIL_DIM);
126+ // mxscale与期望形状必须一致
127+ const std::string expectedShapeStr = op::ToString(expectedMxscaleShape).GetString();
128+ OP_CHECK(
129+ mxscaleShape == expectedMxscaleShape,
130+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON("aclnnAntiMxQuant", "mxscale", op::ToString(mxscaleShape).GetString(),
131+ ("shape of mxscale should be " + expectedShapeStr).c_str()),
132+ return false);
133+ 
105 OP_LOGD("CheckShape end");134 OP_LOGD("CheckShape end");
106 return true;135 return true;
107}136}
@@ -146,8 +175,8 @@ aclnnStatus aclnnAntiMxQuantGetWorkspaceSize(const aclTensor* x, const aclTensor
146 auto ret = CheckParams(x, mxscale, axis, dstType, y);175 auto ret = CheckParams(x, mxscale, axis, dstType, y);
147 CHECK_RET(ret == ACLNN_SUCCESS, ret);176 CHECK_RET(ret == ACLNN_SUCCESS, ret);
148 177 
149- // 空Tensor处理178+ // 空Tensor处理,CheckShape已保证mxscale为空时x必为空
150- if (x->IsEmpty() || mxscale->IsEmpty()) {179+ if (x->IsEmpty()) {
151 *workspaceSize = 0;180 *workspaceSize = 0;
152 uniqueExecutor.ReleaseTo(executor);181 uniqueExecutor.ReleaseTo(executor);
153 return ACLNN_SUCCESS;182 return ACLNN_SUCCESS;
@@ -23,18 +23,21 @@ extern "C" {
23 * @param [in] x: 待进行AntiMxQuant计算的入参。npu device侧的aclTensor,23 * @param [in] x: 待进行AntiMxQuant计算的入参。npu device侧的aclTensor,
24 * 数据类型支持FLOAT4_E2M1、FLOAT4_E1M2、FLOAT8_E5M2、FLOAT8_E4M3FN,24 * 数据类型支持FLOAT4_E2M1、FLOAT4_E1M2、FLOAT8_E5M2、FLOAT8_E4M3FN,
25 * 数据格式支持ND,FLOAT8支持非连续的Tensor,FLOAT4不支持非连续的Tensor。25 * 数据格式支持ND,FLOAT8支持非连续的Tensor,FLOAT4不支持非连续的Tensor。
26- * @param [in] mxscale: npu device侧的aclTensor, 数据类型支持FLOAT8_E8M026+ * 支持空Tensor,x为空Tensor时y与mxscale也须为空Tensor。
27+ * @param [in] mxscale: npu device侧的aclTensor, 数据类型支持FLOAT8_E8M0,
28+ * shape需满足算子约束说明中的公式,仅当x为空Tensor时允许为空Tensor。
27 * @param [in] axis: host侧的aclScalar, 数据类型int64,指定反量化轴。29 * @param [in] axis: host侧的aclScalar, 数据类型int64,指定反量化轴。
28 * @param [in] dstType: host侧的aclScalar, 数据类型int64,指定输出y的数据类型30 * @param [in] dstType: host侧的aclScalar, 数据类型int64,指定输出y的数据类型
29 * @param [in] y: AntiMxQuant计算的出参。npu device侧的aclTensor,31 * @param [in] y: AntiMxQuant计算的出参。npu device侧的aclTensor,
30- * 数据类型支持FLOAT16、BF16、FLOAT32,数据格式支持ND,支持非连续的Tensor。32+ * 数据类型支持FLOAT16、BF16、FLOAT32,数据格式支持ND,支持非连续的Tensor,
33+ * shape需与x完全一致,仅当x为空Tensor时允许为空Tensor。
31 * @param [out] workspaceSize: 返回用户需要在npu device侧申请的workspace大小。34 * @param [out] workspaceSize: 返回用户需要在npu device侧申请的workspace大小。
32 * @param [out] executor: 返回op执行器,包含算子计算流程。35 * @param [out] executor: 返回op执行器,包含算子计算流程。
33 * @return aclnnStatus: 返回状态码。36 * @return aclnnStatus: 返回状态码。
34 */37 */
35-__attribute__((visibility("default"))) aclnnStatus aclnnAntiMxQuantGetWorkspaceSize(38+__attribute__((visibility("default"))) aclnnStatus
36- const aclTensor* x, const aclTensor* mxscale, int64_t axis, int64_t dstType, const aclTensor* y,39+aclnnAntiMxQuantGetWorkspaceSize(const aclTensor* x, const aclTensor* mxscale, int64_t axis, int64_t dstType,
37- uint64_t* workspaceSize, aclOpExecutor** executor);40+ const aclTensor* y, uint64_t* workspaceSize, aclOpExecutor** executor);
38 41 
39/**42/**
40 * @brief aclnnAntiMxQuant的第二段接口,用于执行计算。43 * @brief aclnnAntiMxQuant的第二段接口,用于执行计算。
@@ -0,0 +1,14 @@
1+# -----------------------------------------------------------------------------------------------------------
2+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+# CANN Open Software License Agreement Version 2.0 (the "License").
5+# Please refer to the License for details. You may not use this file except in compliance with the License.
6+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+# See LICENSE in the root of the software repository for the full text of the License.
9+# -----------------------------------------------------------------------------------------------------------
10+ 
11+file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
12+if(UT_TEST_ALL OR OP_API_UT)
13+ add_modules_ut_sources(HOSTNAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
14+endif()
@@ -0,0 +1,168 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file test_aclnn_anti_mx_quant.cpp
13+ * \brief
14+ */
15+#include <vector>
16+ 
17+#include "gtest/gtest.h"
18+#include "../../../op_api/aclnn_anti_mx_quant.h"
19+#include "op_api_ut_common/tensor_desc.h"
20+#include "op_api_ut_common/scalar_desc.h"
21+#include "op_api_ut_common/op_api_ut.h"
22+#include "opdev/platform.h"
23+ 
24+using namespace op;
25+using namespace std;
26+ 
27+class l2_anti_mx_quant_test : public testing::Test {
28+protected:
29+ static void SetUpTestCase() { cout << "l2_anti_mx_quant_test SetUp" << endl; }
30+ 
31+ static void TearDownTestCase() { cout << "l2_anti_mx_quant_test TearDown" << endl; }
32+};
33+ 
34+TEST_F(l2_anti_mx_quant_test, ascend950_anti_mx_quant_e4m3_bf16_success)
35+{
36+ TensorDesc x_desc = TensorDesc({1, 4}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND);
37+ TensorDesc mxscale_desc = TensorDesc({1, 1, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND);
38+ TensorDesc y_desc = TensorDesc({1, 4}, ACL_BF16, ACL_FORMAT_ND);
39+ int64_t axis = -1;
40+ int64_t dstType = static_cast<int64_t>(ACL_BF16);
41+ 
42+ class SocVersionManager testSocVersion(SocVersion::ASCEND950);
43+ auto ut = OP_API_UT(aclnnAntiMxQuant, INPUT(x_desc, mxscale_desc, axis, dstType), OUTPUT(y_desc));
44+ uint64_t workspace_size = 0;
45+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
46+ EXPECT_EQ(aclRet, ACL_SUCCESS);
47+}
48+ 
49+TEST_F(l2_anti_mx_quant_test, ascend950_anti_mx_quant_e4m3_fp32_axis1_success)
50+{
51+ TensorDesc x_desc = TensorDesc({2, 64}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND);
52+ TensorDesc mxscale_desc = TensorDesc({2, 1, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND);
atomgit-bot
atomgit-botatomgit-bot10 days ago

🟡 Medium Priority

变更行:aclnn_anti_mx_quant.cpp 新增 expectedMxscaleShape 校验,核心公式为 axisScaledSize = ceil(x.shape[axis]/MX_BLOCK_SIZE),再 (axisScaledSize+1)/MXSCALE_TAIL_DIM(MX_BLOCK_SIZE=32、TAIL_DIM=2)。 证据链:新增 UT 的两个成功用例量化轴(axis 维)长度分别是 4(x{1,4}, axis=-1)和 64(x{2,64}, axis=1): 即当前 6 个用例(含 mismatch/zero-dim/axis 越界)在 blocksize 常量被误改为 64 时全部仍然通过,无法发现该常量回归;同理 (blocks+1)/2 中的打包除数在 blocks≤2 时 behaviours 也重合。op_host 侧 tiling 用例 x{60,14,16,128}+scale{60,14,16,2,2}(ceil(128/32)=4→2)才是能区分 32/64 的边界值,但 ACLNN 层没有对应用例。 失败模式:后续有人改动 MX_BLOCK_SIZE / 打包除数或公式时,op_api 会接受错误形状或拒绝合法形状(128 宽张量被误判为 {…,1,2}),现有 UT 无法拦截。

建议:增加一个量化轴长度 ≥65(推荐 128)的成功/失败用例,验证 ceil(dim/32) 后再按 2 打包的结果,从而能区分 blocksize=32 与 64 的错误实现。

likedislike
Incorrect?
53+ TensorDesc y_desc = TensorDesc({2, 64}, ACL_FLOAT, ACL_FORMAT_ND);
54+ int64_t axis = 1;
55+ int64_t dstType = static_cast<int64_t>(ACL_FLOAT);
56+ 
57+ class SocVersionManager testSocVersion(SocVersion::ASCEND950);
58+ auto ut = OP_API_UT(aclnnAntiMxQuant, INPUT(x_desc, mxscale_desc, axis, dstType), OUTPUT(y_desc));
59+ uint64_t workspace_size = 0;
60+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
61+ EXPECT_EQ(aclRet, ACL_SUCCESS);
62+}
63+ 
64+TEST_F(l2_anti_mx_quant_test, ascend950_anti_mx_quant_empty_tensor_success)
65+{
66+ TensorDesc x_desc = TensorDesc({0, 4}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND);
67+ TensorDesc mxscale_desc = TensorDesc({0, 1, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND);
68+ TensorDesc y_desc = TensorDesc({0, 4}, ACL_BF16, ACL_FORMAT_ND);
69+ int64_t axis = -1;
70+ int64_t dstType = static_cast<int64_t>(ACL_BF16);
71+ 
72+ class SocVersionManager testSocVersion(SocVersion::ASCEND950);
73+ auto ut = OP_API_UT(aclnnAntiMxQuant, INPUT(x_desc, mxscale_desc, axis, dstType), OUTPUT(y_desc));
74+ uint64_t workspace_size = 0;
75+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
76+ EXPECT_EQ(aclRet, ACL_SUCCESS);
77+ EXPECT_EQ(workspace_size, 0);
78+}
79+ 
80+TEST_F(l2_anti_mx_quant_test, ascend950_anti_mx_quant_e4m3_fp32_axis1_block_boundary_success)
81+{
82+ TensorDesc x_desc = TensorDesc({2, 128}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND);
83+ TensorDesc mxscale_desc = TensorDesc({2, 2, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND);
84+ TensorDesc y_desc = TensorDesc({2, 128}, ACL_FLOAT, ACL_FORMAT_ND);
85+ int64_t axis = 1;
86+ int64_t dstType = static_cast<int64_t>(ACL_FLOAT);
87+ 
88+ class SocVersionManager testSocVersion(SocVersion::ASCEND950);
89+ auto ut = OP_API_UT(aclnnAntiMxQuant, INPUT(x_desc, mxscale_desc, axis, dstType), OUTPUT(y_desc));
90+ uint64_t workspace_size = 0;
91+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
92+ EXPECT_EQ(aclRet, ACL_SUCCESS);
93+}
94+ 
95+TEST_F(l2_anti_mx_quant_test, ascend950_anti_mx_quant_mxscale_block_boundary_fail)
96+{
97+ TensorDesc x_desc = TensorDesc({2, 128}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND);
98+ TensorDesc mxscale_desc = TensorDesc({2, 1, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND);
99+ TensorDesc y_desc = TensorDesc({2, 128}, ACL_BF16, ACL_FORMAT_ND);
100+ int64_t axis = 1;
101+ int64_t dstType = static_cast<int64_t>(ACL_BF16);
102+ 
103+ class SocVersionManager testSocVersion(SocVersion::ASCEND950);
104+ auto ut = OP_API_UT(aclnnAntiMxQuant, INPUT(x_desc, mxscale_desc, axis, dstType), OUTPUT(y_desc));
105+ uint64_t workspace_size = 0;
106+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
107+ EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
108+}
109+ 
110+TEST_F(l2_anti_mx_quant_test, ascend950_anti_mx_quant_mxscale_zero_dim_fail)
111+{
112+ TensorDesc x_desc = TensorDesc({1, 4}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND);
113+ TensorDesc mxscale_desc = TensorDesc({1, 1, 0}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND);
114+ TensorDesc y_desc = TensorDesc({1, 4}, ACL_BF16, ACL_FORMAT_ND);
115+ int64_t axis = -1;
116+ int64_t dstType = static_cast<int64_t>(ACL_BF16);
117+ 
118+ class SocVersionManager testSocVersion(SocVersion::ASCEND950);
119+ auto ut = OP_API_UT(aclnnAntiMxQuant, INPUT(x_desc, mxscale_desc, axis, dstType), OUTPUT(y_desc));
120+ uint64_t workspace_size = 0;
121+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
122+ EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
123+}
124+ 
125+TEST_F(l2_anti_mx_quant_test, ascend950_anti_mx_quant_mxscale_shape_mismatch_fail)
126+{
127+ TensorDesc x_desc = TensorDesc({1, 4}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND);
128+ TensorDesc mxscale_desc = TensorDesc({1, 2, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND);
129+ TensorDesc y_desc = TensorDesc({1, 4}, ACL_BF16, ACL_FORMAT_ND);
130+ int64_t axis = -1;
131+ int64_t dstType = static_cast<int64_t>(ACL_BF16);
132+ 
133+ class SocVersionManager testSocVersion(SocVersion::ASCEND950);
134+ auto ut = OP_API_UT(aclnnAntiMxQuant, INPUT(x_desc, mxscale_desc, axis, dstType), OUTPUT(y_desc));
135+ uint64_t workspace_size = 0;
136+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
137+ EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
138+}
139+ 
140+TEST_F(l2_anti_mx_quant_test, ascend950_anti_mx_quant_y_shape_mismatch_fail)
141+{
142+ TensorDesc x_desc = TensorDesc({1, 4}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND);
143+ TensorDesc mxscale_desc = TensorDesc({1, 1, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND);
144+ TensorDesc y_desc = TensorDesc({2, 4}, ACL_BF16, ACL_FORMAT_ND);
145+ int64_t axis = -1;
146+ int64_t dstType = static_cast<int64_t>(ACL_BF16);
147+ 
148+ class SocVersionManager testSocVersion(SocVersion::ASCEND950);
149+ auto ut = OP_API_UT(aclnnAntiMxQuant, INPUT(x_desc, mxscale_desc, axis, dstType), OUTPUT(y_desc));
150+ uint64_t workspace_size = 0;
151+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
152+ EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
153+}
154+ 
155+TEST_F(l2_anti_mx_quant_test, ascend950_anti_mx_quant_axis_out_of_range_fail)
156+{
157+ TensorDesc x_desc = TensorDesc({1, 4}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND);
158+ TensorDesc mxscale_desc = TensorDesc({1, 1, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND);
159+ TensorDesc y_desc = TensorDesc({1, 4}, ACL_BF16, ACL_FORMAT_ND);
160+ int64_t axis = 2;
161+ int64_t dstType = static_cast<int64_t>(ACL_BF16);
162+ 
163+ class SocVersionManager testSocVersion(SocVersion::ASCEND950);
164+ auto ut = OP_API_UT(aclnnAntiMxQuant, INPUT(x_desc, mxscale_desc, axis, dstType), OUTPUT(y_desc));
165+ uint64_t workspace_size = 0;
166+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
167+ EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
168+}