已合并
修改dyanmic_dual_level_mx_quant的demo & 修改grouped_dyanmic_mx_quant的非连续说明 #8100
季骏创建于 7月30日
修改dyanmic_dual_level_mx_quant的demo & 修改grouped_dyanmic_mx_quant的非连续说明 #8100
已合并
共 5 个文件变更+28-16
| @@ -405,7 +405,7 @@ aclnnStatus aclnnDynamicDualLevelMxQuant( | |||
| 405 | 405 | ||
| 406 | // 2. 构造输入与输出,需要根据API的接口自定义构造 | 406 | // 2. 构造输入与输出,需要根据API的接口自定义构造 |
| 407 | std::vector<int64_t> xShape = {1, 512}; | 407 | std::vector<int64_t> xShape = {1, 512}; |
| 408 | - std::vector<int64_t> smoothScaleOptionalShape = {1}; | 408 | + std::vector<int64_t> smoothScaleOptionalShape = {512}; |
| 409 | std::vector<int64_t> yOutShape = {1, 512}; | 409 | std::vector<int64_t> yOutShape = {1, 512}; |
| 410 | std::vector<int64_t> level0ScaleOutShape = {1, 1}; | 410 | std::vector<int64_t> level0ScaleOutShape = {1, 1}; |
| 411 | std::vector<int64_t> level1ScaleOutShape = {1, 8, 2}; | 411 | std::vector<int64_t> level1ScaleOutShape = {1, 8, 2}; |
| @@ -422,7 +422,7 @@ aclnnStatus aclnnDynamicDualLevelMxQuant( | |||
| 422 | 422 | ||
| 423 | // 对应 BF16 的值 (0->0, 16640->8, 17024->64, 17408->512) | 423 | // 对应 BF16 的值 (0->0, 16640->8, 17024->64, 17408->512) |
| 424 | std::vector<uint16_t> xHostData(512, 16640); | 424 | std::vector<uint16_t> xHostData(512, 16640); |
| 425 | - std::vector<uint16_t> smoothScaleOptionalHostData = {0}; | 425 | + std::vector<uint16_t> smoothScaleOptionalHostData(512, 0); |
| 426 | // 对应 float4_e2m1 的值 (0->0, 72->4, 96->32, 120->256) | 426 | // 对应 float4_e2m1 的值 (0->0, 72->4, 96->32, 120->256) |
| 427 | std::vector<uint8_t> yOutHostData(512, 0); | 427 | std::vector<uint8_t> yOutHostData(512, 0); |
| 428 | // 对应 float32 的值 (0->0) | 428 | // 对应 float32 的值 (0->0) |
| @@ -1,12 +1,16 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * This program is free software, you can redistribute it and/or modify. | ||
| 3 | * Copyright (c) 2026 Huawei Technologies Co., Ltd. | 2 | * Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 4 | - * This file is a part of the CANN Open Software. | 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | - * Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | * Please refer to the License for details. You may not use this file except in compliance with the License. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| 7 | - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | - * BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. See LICENSE in the root of | 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 9 | - * the software repository for the full text of the License. | 8 | + * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file test_aclnn_dynamic_dual_level_mx_quant.cpp | ||
| 13 | + * \brief | ||
| 10 | */ | 14 | */ |
| 11 | 15 | ||
| 12 | #include <iostream> | 16 | #include <iostream> |
| @@ -95,7 +99,7 @@ int aclnnDynamicDualLevelMxQuantTest(int32_t deviceId, aclrtStream& stream) | |||
| 95 | 99 | ||
| 96 | // 2. 构造输入与输出,需要根据API的接口自定义构造 | 100 | // 2. 构造输入与输出,需要根据API的接口自定义构造 |
| 97 | std::vector<int64_t> xShape = {1, 512}; | 101 | std::vector<int64_t> xShape = {1, 512}; |
| 98 | - std::vector<int64_t> smoothScaleOptionalShape = {1}; | 102 | + std::vector<int64_t> smoothScaleOptionalShape = {512}; |
| 99 | std::vector<int64_t> yOutShape = {1, 512}; | 103 | std::vector<int64_t> yOutShape = {1, 512}; |
| 100 | std::vector<int64_t> level0ScaleOutShape = {1, 1}; | 104 | std::vector<int64_t> level0ScaleOutShape = {1, 1}; |
| 101 | std::vector<int64_t> level1ScaleOutShape = {1, 8, 2}; | 105 | std::vector<int64_t> level1ScaleOutShape = {1, 8, 2}; |
| @@ -112,12 +116,12 @@ int aclnnDynamicDualLevelMxQuantTest(int32_t deviceId, aclrtStream& stream) | |||
| 112 | 116 | ||
| 113 | // 对应 BF16 的值 (0->0, 16640->8, 17024->64, 17408->512) | 117 | // 对应 BF16 的值 (0->0, 16640->8, 17024->64, 17408->512) |
| 114 | std::vector<uint16_t> xHostData(512, 16640); | 118 | std::vector<uint16_t> xHostData(512, 16640); |
| 115 | - std::vector<uint16_t> smoothScaleOptionalHostData = {0}; | 119 | + std::vector<uint16_t> smoothScaleOptionalHostData(512, 0); |
| 116 | // 对应 float4_e2m1 的值 (0->0, 72->4, 96->32, 120->256) | 120 | // 对应 float4_e2m1 的值 (0->0, 72->4, 96->32, 120->256) |
| 117 | std::vector<uint8_t> yOutHostData(512, 0); | 121 | std::vector<uint8_t> yOutHostData(512, 0); |
| 118 | // 对应 float32 的值 (0->0) | 122 | // 对应 float32 的值 (0->0) |
| 119 | std::vector<float> level0ScaleOutHostData = {{0}}; | 123 | std::vector<float> level0ScaleOutHostData = {{0}}; |
| 120 | - //对应float8_e8m0的值(128->2) | 124 | + // 对应float8_e8m0的值(128->2) |
| 121 | std::vector<std::vector<std::vector<uint8_t>>> level1ScaleOutHostData( | 125 | std::vector<std::vector<std::vector<uint8_t>>> level1ScaleOutHostData( |
| 122 | 1, std::vector<std::vector<uint8_t>>(8, std::vector<uint8_t>(2, 0))); | 126 | 1, std::vector<std::vector<uint8_t>>(8, std::vector<uint8_t>(2, 0))); |
| 123 | const char* roundModeOptional = "rint"; | 127 | const char* roundModeOptional = "rint"; |
| @@ -179,7 +183,7 @@ int aclnnDynamicDualLevelMxQuantTest(int32_t deviceId, aclrtStream& stream) | |||
| 179 | ret = aclnnDynamicDualLevelMxQuant(workspaceAddr, workspaceSize, executor, stream); | 183 | ret = aclnnDynamicDualLevelMxQuant(workspaceAddr, workspaceSize, executor, stream); |
| 180 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnDynamicDualLevelMxQuant failed. ERROR: %d\n", ret); return ret); | 184 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnDynamicDualLevelMxQuant failed. ERROR: %d\n", ret); return ret); |
| 181 | 185 | ||
| 182 | - //(固定写法)同步等待任务执行结束 | 186 | + // (固定写法)同步等待任务执行结束 |
| 183 | ret = aclrtSynchronizeStream(stream); | 187 | ret = aclrtSynchronizeStream(stream); |
| 184 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | 188 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); |
| 185 | 189 | ||
| @@ -226,4 +230,4 @@ int main() | |||
| 226 | 230 | ||
| 227 | Finalize(deviceId, stream); | 231 | Finalize(deviceId, stream); |
| 228 | return 0; | 232 | return 0; |
| 229 | -} | 233 | +} |
| @@ -167,7 +167,7 @@ aclnnStatus aclnnGroupedDynamicMxQuant( | |||
| 167 | <td>FLOAT8_E8M0</td> | 167 | <td>FLOAT8_E8M0</td> |
| 168 | <td>ND</td> | 168 | <td>ND</td> |
| 169 | <td>3</td> | 169 | <td>3</td> |
| 170 | - <td>√</td> | 170 | + <td>×</td> |
| 171 | </tr> | 171 | </tr> |
| 172 | <tr> | 172 | <tr> |
| 173 | <td>workspaceSize</td> | 173 | <td>workspaceSize</td> |
| @@ -243,7 +243,7 @@ aclnnStatus aclnnGroupedDynamicMxQuantV2( | |||
| 243 | <td>FLOAT4_E2M1、FLOAT4_E1M2、FLOAT8_E4M3FN、FLOAT8_E5M2</td> | 243 | <td>FLOAT4_E2M1、FLOAT4_E1M2、FLOAT8_E4M3FN、FLOAT8_E5M2</td> |
| 244 | <td>ND</td> | 244 | <td>ND</td> |
| 245 | <td>2</td> | 245 | <td>2</td> |
| 246 | - <td>√</td> | 246 | + <td>FLOAT8支持非连续,FLOAT4不支持非连续</td> |
| 247 | </tr> | 247 | </tr> |
| 248 | <tr> | 248 | <tr> |
| 249 | <td>mxscale (aclTensor*)</td> | 249 | <td>mxscale (aclTensor*)</td> |
| @@ -253,7 +253,7 @@ aclnnStatus aclnnGroupedDynamicMxQuantV2( | |||
| 253 | <td>FLOAT8_E8M0</td> | 253 | <td>FLOAT8_E8M0</td> |
| 254 | <td>ND</td> | 254 | <td>ND</td> |
| 255 | <td>3</td> | 255 | <td>3</td> |
| 256 | - <td>√</td> | 256 | + <td>×</td> |
| 257 | </tr> | 257 | </tr> |
| 258 | <tr> | 258 | <tr> |
| 259 | <td>workspaceSize</td> | 259 | <td>workspaceSize</td> |
| @@ -176,6 +176,13 @@ aclnnStatus aclnnGroupedDynamicMxQuantV2GetWorkspaceSize(const aclTensor* x, con | |||
| 176 | return ACLNN_SUCCESS; | 176 | return ACLNN_SUCCESS; |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | + // 当输出y是FP4时,不支持非连续 | ||
| 180 | + if ((y->GetDataType() == op::DataType::DT_FLOAT4_E2M1 || y->GetDataType() == op::DataType::DT_FLOAT4_E1M2) && | ||
| 181 | + !IsContiguous(y)) { | ||
| 182 | + OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When the data type of y is float4, it must be contiguous"); | ||
| 183 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 184 | + } | ||
| 185 | + | ||
| 179 | // x如果非连续,需要转连续 | 186 | // x如果非连续,需要转连续 |
| 180 | auto selfContiguous = l0op::Contiguous(x, uniqueExecutor.get()); | 187 | auto selfContiguous = l0op::Contiguous(x, uniqueExecutor.get()); |
| 181 | CHECK_RET(selfContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | 188 | CHECK_RET(selfContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| @@ -190,6 +197,7 @@ aclnnStatus aclnnGroupedDynamicMxQuantV2GetWorkspaceSize(const aclTensor* x, con | |||
| 190 | // 如果出参y是非连续Tensor,需要把计算完的连续Tensor转非连续 | 197 | // 如果出参y是非连续Tensor,需要把计算完的连续Tensor转非连续 |
| 191 | auto viewCopyResult0 = l0op::ViewCopy(yOut, y, uniqueExecutor.get()); | 198 | auto viewCopyResult0 = l0op::ViewCopy(yOut, y, uniqueExecutor.get()); |
| 192 | CHECK_RET(viewCopyResult0 != nullptr, ACLNN_ERR_INNER_NULLPTR); | 199 | CHECK_RET(viewCopyResult0 != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 200 | + | ||
| 193 | if (!IsContiguous(mxscale)) { | 201 | if (!IsContiguous(mxscale)) { |
| 194 | OP_LOGE(ACLNN_ERR_PARAM_INVALID, "mxscale must be contiguous."); | 202 | OP_LOGE(ACLNN_ERR_PARAM_INVALID, "mxscale must be contiguous."); |
| 195 | return ACLNN_ERR_PARAM_INVALID; | 203 | return ACLNN_ERR_PARAM_INVALID; |