已合并
BNInfer,InplaceApplyRMSProp以及ApplyCamePart1算子检视意见闭环 #9453
tianyu52创建于 1 天前
BNInfer,InplaceApplyRMSProp以及ApplyCamePart1算子检视意见闭环 #9453
已合并
共 30 个文件变更+295-279
| @@ -1,5 +1,5 @@ | |||
| 1 | # This program is free software, you can redistribute it and/or modify. | 1 | # This program is free software, you can redistribute it and/or modify. |
| 2 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | # This file is a part of the CANN Open Software. | 3 | # This file is a part of the CANN Open Software. |
| 4 | # Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | # Licensed under 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. | 5 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -13,7 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | ## 功能说明 | 14 | ## 功能说明 |
| 15 | 15 | ||
| 16 | -- 算子功能:推理场景下对输入张量x执行批量归一化,使用已给定的均值mean和方差variance计算输出y。 | 16 | +- 算子功能:在推理场景下,使用给定的均值`mean`和方差`variance`对输入`x`进行批归一化,得到输出`y`。 |
| 17 | 17 | ||
| 18 | - 计算公式: | 18 | - 计算公式: |
| 19 | 19 | ||
| @@ -21,7 +21,7 @@ | |||
| 21 | y = scale \times \frac{x - mean}{\sqrt{variance + epsilon}} + offset | 21 | y = scale \times \frac{x - mean}{\sqrt{variance + epsilon}} + offset |
| 22 | $$ | 22 | $$ |
| 23 | 23 | ||
| 24 | - scale、offset、mean、variance均为一维张量,长度等于输入x的通道维。 | 24 | + `scale`、`offset`、`mean`和`variance`均为一维张量,长度等于输入`x`的通道数。 |
| 25 | 25 | ||
| 26 | ## 参数说明 | 26 | ## 参数说明 |
| 27 | 27 | ||
| @@ -44,62 +44,70 @@ | |||
| 44 | <tr> | 44 | <tr> |
| 45 | <td>x</td> | 45 | <td>x</td> |
| 46 | <td>输入</td> | 46 | <td>输入</td> |
| 47 | - <td>被归一化的输入张量。A2/A3兼容声明包含NC1HWC0、NULL及其未知形状映射;Ascend950物理执行路径按950实现收窄为ND、NCHW、NCDHW、NHWC和NDHWC,未提供NC1HWC0和NULL路径。ND格式下通道维为第1维,NCHW/NCDHW格式下通道维为C维,NHWC/NDHWC格式下通道维为最后一维。</td> | 47 | + <td>待归一化的输入张量。不同数据格式对应的通道维见约束说明。</td> |
| 48 | <td>FLOAT、FLOAT16、BFLOAT16</td> | 48 | <td>FLOAT、FLOAT16、BFLOAT16</td> |
| 49 | - <td>ND、NCHW、NCDHW、NHWC、NDHWC</td> | 49 | + <td>NC1HWC0、NULL、ND、NCHW、NCDHW、NHWC、NDHWC</td> |
C | |||
| 50 | </tr> | 50 | </tr> |
| 51 | <tr> | 51 | <tr> |
| 52 | <td>scale</td> | 52 | <td>scale</td> |
| 53 | <td>输入</td> | 53 | <td>输入</td> |
| 54 | - <td>缩放参数,一维张量,shape为(C)。</td> | 54 | + <td>缩放参数,一维张量,shape为[C]。</td> |
| 55 | <td>FLOAT</td> | 55 | <td>FLOAT</td> |
| 56 | - <td>ND</td> | 56 | + <td>ND、NC1HWC0、NULL、NCDHW</td> |
| 57 | </tr> | 57 | </tr> |
| 58 | <tr> | 58 | <tr> |
| 59 | <td>offset</td> | 59 | <td>offset</td> |
| 60 | <td>输入</td> | 60 | <td>输入</td> |
| 61 | - <td>偏置参数,一维张量,shape为(C)。</td> | 61 | + <td>偏置参数,一维张量,shape为[C]。</td> |
| 62 | <td>FLOAT</td> | 62 | <td>FLOAT</td> |
| 63 | - <td>ND</td> | 63 | + <td>ND、NC1HWC0、NULL、NCDHW</td> |
| 64 | </tr> | 64 | </tr> |
| 65 | <tr> | 65 | <tr> |
| 66 | <td>mean</td> | 66 | <td>mean</td> |
| 67 | <td>输入</td> | 67 | <td>输入</td> |
| 68 | - <td>推理使用的均值,一维张量,shape为(C)。</td> | 68 | + <td>推理时使用的均值,一维张量,shape为[C]。</td> |
| 69 | <td>FLOAT</td> | 69 | <td>FLOAT</td> |
| 70 | - <td>ND</td> | 70 | + <td>ND、NC1HWC0、NULL、NCDHW</td> |
| 71 | </tr> | 71 | </tr> |
| 72 | <tr> | 72 | <tr> |
| 73 | <td>variance</td> | 73 | <td>variance</td> |
| 74 | <td>输入</td> | 74 | <td>输入</td> |
| 75 | - <td>推理使用的方差,一维张量,shape为(C)。</td> | 75 | + <td>推理时使用的方差,一维张量,shape为[C]。</td> |
| 76 | <td>FLOAT</td> | 76 | <td>FLOAT</td> |
| 77 | - <td>ND</td> | 77 | + <td>ND、NC1HWC0、NULL、NCDHW</td> |
| 78 | </tr> | 78 | </tr> |
| 79 | <tr> | 79 | <tr> |
| 80 | <td>epsilon</td> | 80 | <td>epsilon</td> |
| 81 | <td>必选属性</td> | 81 | <td>必选属性</td> |
| 82 | - <td>添加到方差中的小值,用于避免除0。</td> | 82 | + <td>添加到方差中的数值稳定性常数,用于避免除零。</td> |
| 83 | <td>FLOAT</td> | 83 | <td>FLOAT</td> |
| 84 | <td>-</td> | 84 | <td>-</td> |
| 85 | </tr> | 85 | </tr> |
| 86 | <tr> | 86 | <tr> |
| 87 | <td>y</td> | 87 | <td>y</td> |
| 88 | <td>输出</td> | 88 | <td>输出</td> |
| 89 | - <td>归一化后的输出张量,声明格式、数据类型和shape与x一致;Ascend950物理执行格式与x相同。</td> | 89 | + <td>归一化后的输出张量,数据类型、数据格式和shape与x一致。</td> |
| 90 | <td>FLOAT、FLOAT16、BFLOAT16</td> | 90 | <td>FLOAT、FLOAT16、BFLOAT16</td> |
| 91 | - <td>ND、NCHW、NCDHW、NHWC、NDHWC</td> | 91 | + <td>NC1HWC0、NULL、ND、NCHW、NCDHW、NHWC、NDHWC</td> |
| 92 | </tr> | 92 | </tr> |
| 93 | </tbody></table> | 93 | </tbody></table> |
| 94 | 94 | ||
| 95 | ## 约束说明 | 95 | ## 约束说明 |
| 96 | 96 | ||
| 97 | -- scale、offset、mean、variance的数据类型必须为FLOAT。 | 97 | +- scale、offset、mean和variance的数据类型必须为FLOAT,且均为shape为[C]的一维张量,其中C为x的通道数。 |
| 98 | -- scale、offset、mean、variance必须为一维张量,长度必须等于x的通道维大小。 | 98 | +- <term>Ascend 950PR/Ascend 950DT</term>: |
| 99 | -- ND格式下x维度数必须大于等于2;NCHW和NHWC格式下x必须为4维;NCDHW和NDHWC格式下x必须为5维。 | 99 | + - x和y支持ND、NCHW、NCDHW、NHWC和NDHWC格式,不支持NC1HWC0和NULL格式。 |
| 100 | -- Ascend950物理执行路径不支持x的任一参与维度为0的空Tensor;host tiling返回`GRAPH_FAILED`,不会进入kernel。 | 100 | + - scale、offset、mean和variance仅支持ND格式。 |
| 101 | -- A2/A3原型契约保留NC1HWC0和NULL;Ascend950 AscendC物理执行面按950实现收窄为ND、NCHW、NCDHW、NHWC和NDHWC。由于950 Vector kernel/tiling未实现NC1HWC0存储布局,且已知形状NULL无法映射到950物理路径,host tiling在kernel前结构化拒绝这两类格式;该差异通过950独立OpDef/config和tiling隔离,不修改A2/A3实现。 | 101 | + - ND格式下,x的rank不小于2,通道维为第1维;NCHW和NCDHW格式下,通道维为C维;NHWC和NDHWC格式下,通道维为最后一维。 |
| 102 | -- 本算子为GE图内部算子,不提供公开aclnnBNInfer接口;aclnn/torch单算子接口不涉及。 | 102 | + - NCHW和NHWC格式下,x必须为4维;NCDHW和NDHWC格式下,x必须为5维。 |
| 103 | + - 不支持空Tensor,x的所有维度大小均必须大于0。 | ||
| 104 | +- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>、<term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term>: | ||
| 105 | + - x和y支持NC1HWC0、NULL和NCDHW格式;动态shape场景下,NULL格式支持NCHW和NHWC映射。 | ||
| 106 | + - scale、offset、mean和variance支持NC1HWC0、NULL和NCDHW格式。 | ||
| 107 | + - x和y不支持ND和NDHWC格式。 | ||
| 108 | +- <term>Atlas 200I/500 A2 推理产品</term>、<term>Atlas 推理系列产品</term>、<term>Atlas 训练系列产品</term>: | ||
| 109 | + - x和y不支持BFLOAT16。 | ||
| 110 | +- 本算子支持GE图模式和TensorFlow Parser调用,不提供公开的aclnn接口。 | ||
| 103 | 111 | ||
| 104 | ## 调用说明 | 112 | ## 调用说明 |
| 105 | 113 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | # This program is free software, you can redistribute it and/or modify. | 1 | # This program is free software, you can redistribute it and/or modify. |
| 2 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | # This file is a part of the CANN Open Software. | 3 | # This file is a part of the CANN Open Software. |
| 4 | # Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | # Licensed under 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. | 5 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -18,18 +18,19 @@ namespace ge { | |||
| 18 | * @brief Performs batch normalization inference. | 18 | * @brief Performs batch normalization inference. |
| 19 | * | 19 | * |
| 20 | * @par Inputs: | 20 | * @par Inputs: |
| 21 | - * @li x: A 4D tensor of type float16 or float32 or bfloat16, with format NHWC or NCHW. | 21 | + * @li x: A tensor of type float16 or float32 or bfloat16, with format NC1HWC0, NULL, ND, NCHW, NCDHW, |
| 22 | + * NHWC or NDHWC. | ||
| 22 | * @li scale: A 1D tensor of type float32, for the scale factor, the shape is same as dim C of input x. \n | 23 | * @li scale: A 1D tensor of type float32, for the scale factor, the shape is same as dim C of input x. \n |
| 23 | * @li offset: A 1D tensor of type float32, for the offset, the shape is same as dim C of input x. \n | 24 | * @li offset: A 1D tensor of type float32, for the offset, the shape is same as dim C of input x. \n |
| 24 | * @li mean: A 1D tensor of type float32, for the mean, the shape is same as dim C of input x. \n | 25 | * @li mean: A 1D tensor of type float32, for the mean, the shape is same as dim C of input x. \n |
| 25 | * @li variance: A 1D tensor of type float32, for the variance, the shape is same as dim C of input x. \n | 26 | * @li variance: A 1D tensor of type float32, for the variance, the shape is same as dim C of input x. \n |
| 26 | * | 27 | * |
| 27 | * @par Attributes: | 28 | * @par Attributes: |
| 28 | - * epsilon: An optional float32, specifying the small value added to variance to | 29 | + * epsilon: A required float32 attribute, specifying the small value added to variance to |
| 29 | - * avoid dividing by zero. Defaults to "0.0001" . \n | 30 | + * avoid dividing by zero. \n |
| 30 | * | 31 | * |
| 31 | * @par Outputs: | 32 | * @par Outputs: |
| 32 | - * y: A 4D tensor of type float16 or float32 or bfloat16 for the normalized "x", with format NHWC or NCHW. \n | 33 | + * y: A tensor of type float16 or float32 or bfloat16 for the normalized "x", with the same format as x. \n |
| 33 | * | 34 | * |
| 34 | * @attention Constraints: | 35 | * @attention Constraints: |
| 35 | * For Atlas 200/300/500 Inference Product, the result accuracy fails to reach 1/1000 due to the | 36 | * For Atlas 200/300/500 Inference Product, the result accuracy fails to reach 1/1000 due to the |
| @@ -1,5 +1,5 @@ | |||
| 1 | # This program is free software, you can redistribute it and/or modify. | 1 | # This program is free software, you can redistribute it and/or modify. |
| 2 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | # This file is a part of the CANN Open Software. | 3 | # This file is a part of the CANN Open Software. |
| 4 | # Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | # Licensed under 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. | 5 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -443,6 +443,13 @@ ge::graphStatus BNInferLastChannelTiling::FillLastChannelTilingForBSplit(int64_t | |||
| 443 | bInner > 1) { | 443 | bInner > 1) { |
| 444 | bInner--; | 444 | bInner--; |
| 445 | } | 445 | } |
| 446 | + const int64_t requiredUbBytes = paramBytes + cacheBytes + | ||
| 447 | + bInner * fusedALen * INPUT_OUTPUT_NUM * DOUBLE_BUFFER * bytesPerElement; | ||
| 448 | + OP_CHECK_IF(requiredUbBytes > static_cast<int64_t>(aicoreParams_.ubSize), | ||
| 449 | + OP_LOGE_FOR_INVALID_VALUES_WITH_REASON(context_->GetNodeName(), "requiredUbBytes", | ||
| 450 | + std::to_string(requiredUbBytes).c_str(), | ||
| 451 | + "last-channel tiling exceeds available UB"), | ||
| 452 | + return ge::GRAPH_FAILED); | ||
| 446 | int64_t bOuter = Ops::Base::CeilDiv(fusedBLen, bInner); | 453 | int64_t bOuter = Ops::Base::CeilDiv(fusedBLen, bInner); |
| 447 | int64_t bTail = fusedBLen % bInner; | 454 | int64_t bTail = fusedBLen % bInner; |
| 448 | int64_t tileBlockBTail = bTail == 0 ? bInner : bTail; | 455 | int64_t tileBlockBTail = bTail == 0 ? bInner : bTail; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -25,9 +25,9 @@ __spec__ = { | |||
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | _TOL = { | 27 | _TOL = { |
| 28 | - "float32": {"standard": "stat_rel_err", "threshold": 1e-2}, | 28 | + "float32": {"standard": "cross_check", "threshold": 1e-2}, |
| 29 | - "float16": {"standard": "stat_rel_err", "threshold": 2e-2}, | 29 | + "float16": {"standard": "cross_check", "threshold": 2e-2}, |
| 30 | - "bfloat16": {"standard": "stat_rel_err", "threshold": 4e-2}, | 30 | + "bfloat16": {"standard": "cross_check", "threshold": 4e-2}, |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | 33 | ||
| @@ -209,6 +209,12 @@ TEST_F(BNInferTilingTest, nhwcFloatContinuousATilingKey901000) | |||
| 209 | EXPECT_EQ(tilingKey, 901000); | 209 | EXPECT_EQ(tilingKey, 901000); |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | +TEST_F(BNInferTilingTest, rejectLastChannelWhenChannelCacheExceedsUb) | ||
| 213 | +{ | ||
| 214 | + auto status = RunBNInferTiling({1, 1, 1, 4096}, ge::DT_FLOAT, ge::FORMAT_NHWC); | ||
| 215 | + EXPECT_EQ(status, ge::GRAPH_FAILED); | ||
| 216 | +} | ||
| 217 | + | ||
| 212 | TEST_F(BNInferTilingTest, nhwcSmallATilingKey902000) | 218 | TEST_F(BNInferTilingTest, nhwcSmallATilingKey902000) |
| 213 | { | 219 | { |
| 214 | uint64_t tilingKey = 0; | 220 | uint64_t tilingKey = 0; |
| @@ -73,6 +73,10 @@ TEST_F(BNInferInferShapeTest, staticShape) { CheckInferShape({2, 3, 4}); } | |||
| 73 | 73 | ||
| 74 | TEST_F(BNInferInferShapeTest, dynamicShape) { CheckInferShape({2, -1, 16}); } | 74 | TEST_F(BNInferInferShapeTest, dynamicShape) { CheckInferShape({2, -1, 16}); } |
| 75 | 75 | ||
| 76 | +TEST_F(BNInferInferShapeTest, nchwLikeShape) { CheckInferShape({2, 3, 4, 5}); } | ||
| 77 | + | ||
| 78 | +TEST_F(BNInferInferShapeTest, ndhwcLikeShape) { CheckInferShape({2, 3, 4, 5, 6}); } | ||
| 79 | + | ||
| 76 | TEST_F(BNInferInferShapeTest, unknownRank) { CheckInferShape({-2}); } | 80 | TEST_F(BNInferInferShapeTest, unknownRank) { CheckInferShape({-2}); } |
| 77 | 81 | ||
| 78 | void CheckInferDataType(ge::DataType xDataType) | 82 | void CheckInferDataType(ge::DataType xDataType) |
| @@ -13,26 +13,28 @@ | |||
| 13 | 13 | ||
| 14 | ## 功能说明 | 14 | ## 功能说明 |
| 15 | 15 | ||
| 16 | -- **算子功能**:计算CAME(Confidence-guided Adaptive Memory Efficient)优化器第一阶段的平方梯度归约值。 | 16 | +- 算子功能:计算CAME(Confidence-guided Adaptive Memory Efficient)优化器第一阶段的平方梯度归约值。 |
| 17 | 17 | ||
| 18 | -- **计算公式**: | 18 | +- 计算公式: |
| 19 | 19 | ||
| 20 | - 对二维输入张量 `grad` 中的元素 $g_{i,j}$,以及标量张量 `eps`,先计算: | 20 | + 对输入`grad`最后两维$[N, M]$上的元素$g_{b,\dots,i,j}$,先计算: |
| 21 | 21 | ||
| 22 | $$ | 22 | $$ |
| 23 | - x_{i,j} = g_{i,j}^{2} + eps | 23 | + x_{b,\dots,i,j} = g_{b,\dots,i,j}^{2} + eps |
| 24 | $$ | 24 | $$ |
| 25 | 25 | ||
| 26 | - 再分别进行行、列和全局归约: | 26 | + 再对每个批次切片分别进行行、列和二维归约: |
| 27 | 27 | ||
| 28 | $$ | 28 | $$ |
| 29 | \begin{aligned} | 29 | \begin{aligned} |
| 30 | - sum\_grad\_r_i &= \sum_j x_{i,j} \\ | 30 | + sum\_grad\_r_{b,\dots,i} &= \sum_j x_{b,\dots,i,j} \\ |
| 31 | - sum\_grad\_c_j &= \sum_i x_{i,j} \\ | 31 | + sum\_grad\_c_{b,\dots,j} &= \sum_i x_{b,\dots,i,j} \\ |
| 32 | - sum\_grad\_rc &= \sum_i \sum_j x_{i,j} | 32 | + sum\_grad\_rc_{b,\dots} &= \sum_i \sum_j x_{b,\dots,i,j} |
| 33 | \end{aligned} | 33 | \end{aligned} |
| 34 | $$ | 34 | $$ |
| 35 | 35 | ||
| 36 | + 其中,$b,\dots$表示批次维度索引,$i$和$j$分别表示最后两维的索引。 | ||
| 37 | + | ||
| 36 | ## 参数说明 | 38 | ## 参数说明 |
| 37 | 39 | ||
| 38 | <table style="table-layout: fixed; width: 100%"> | 40 | <table style="table-layout: fixed; width: 100%"> |
| @@ -53,49 +55,58 @@ | |||
| 53 | </tr> | 55 | </tr> |
| 54 | </thead> | 56 | </thead> |
| 55 | <tbody> | 57 | <tbody> |
| 56 | - <tr> | 58 | + <tr> |
| 57 | - <td>grad</td> | 59 | + <td>grad</td> |
| 58 | - <td>输入</td> | 60 | + <td>输入</td> |
| 59 | - <td>梯度张量,公式中的<code>grad</code>,rank不小于2;最后两维为<code>[N, M]</code>,前导维为batch维。</td> | 61 | + <td>梯度张量,最后两维为<code>[N, M]</code>,具体shape要求见约束说明。</td> |
| 60 | - <td>FLOAT16、FLOAT32、BFLOAT16</td> | 62 | + <td>FLOAT16、FLOAT、BFLOAT16</td> |
| 61 | - <td>ND</td> | 63 | + <td>ND</td> |
| 62 | - </tr> | 64 | + </tr> |
| 63 | - <tr> | 65 | + <tr> |
| 64 | - <td>eps</td> | 66 | + <td>eps</td> |
| 65 | - <td>输入</td> | 67 | + <td>输入</td> |
| 66 | - <td>数值稳定项,公式中的<code>eps</code>,为标量或单元素一维张量。</td> | 68 | + <td>数值稳定性常数,具体shape要求见约束说明。</td> |
| 67 | - <td>FLOAT32</td> | 69 | + <td>FLOAT</td> |
| 68 | - <td>ND</td> | 70 | + <td>ND</td> |
| 69 | - </tr> | 71 | + </tr> |
| 70 | - <tr> | 72 | + <tr> |
| 71 | - <td>sum_grad_r</td> | 73 | + <td>sum_grad_r</td> |
| 72 | - <td>输出</td> | 74 | + <td>输出</td> |
| 73 | - <td>按列归约后的行结果,shape为<code>[batch..., N]</code>,对应公式中的<code>sum_grad_r</code>。</td> | 75 | + <td>对最后一维进行归约得到的结果,具体shape见约束说明。</td> |
| 74 | - <td>FLOAT32</td> | 76 | + <td>FLOAT</td> |
| 75 | - <td>ND</td> | 77 | + <td>ND</td> |
| 76 | - </tr> | 78 | + </tr> |
| 77 | <tr> | 79 | <tr> |
| 78 | <td>sum_grad_c</td> | 80 | <td>sum_grad_c</td> |
| 79 | <td>输出</td> | 81 | <td>输出</td> |
| 80 | - <td>按行归约后的列结果,shape为<code>[batch..., M]</code>,对应公式中的<code>sum_grad_c</code>。</td> | 82 | + <td>对倒数第二维进行归约得到的结果,具体shape见约束说明。</td> |
| 81 | - <td>FLOAT32</td> | 83 | + <td>FLOAT</td> |
| 82 | <td>ND</td> | 84 | <td>ND</td> |
| 83 | </tr> | 85 | </tr> |
| 84 | - <tr> | 86 | + <tr> |
| 85 | - <td>sum_grad_rc</td> | 87 | + <td>sum_grad_rc</td> |
| 86 | - <td>输出</td> | 88 | + <td>输出</td> |
| 87 | - <td>全局归约结果,shape为<code>[batch...]</code>,对应公式中的<code>sum_grad_rc</code>。</td> | 89 | + <td>对最后两维进行归约得到的结果,具体shape见约束说明。</td> |
| 88 | - <td>FLOAT32</td> | 90 | + <td>FLOAT</td> |
| 89 | - <td>ND</td> | 91 | + <td>ND</td> |
| 90 | - </tr> | 92 | + </tr> |
| 91 | -</tbody> | 93 | + </tbody> |
| 92 | </table> | 94 | </table> |
| 93 | 95 | ||
| 94 | ## 约束说明 | 96 | ## 约束说明 |
| 95 | 97 | ||
| 96 | -- `grad` rank不小于2,数据格式为ND,所有维度都必须大于0;最后两维为<code>[N, M]</code>,前导维作为batch维。 | 98 | +- `grad`必须为非空ND张量,所有维度的大小均必须大于0。 |
| 97 | -- `eps` 为FLOAT32类型、ND格式的标量或单元素一维张量。 | 99 | +- `eps`必须为仅含一个FLOAT类型元素的ND张量。 |
| 98 | -- `sum_grad_r`、`sum_grad_c`和`sum_grad_rc`的数据类型均为FLOAT32。 | 100 | +- <term>Ascend 950PR/Ascend 950DT</term>: |
| 101 | + - `grad`的rank不小于2,最后两维为`[N, M]`,其余维度为批次维度。 | ||
| 102 | + - `grad`所有维度大小的乘积不能超过INT64的最大值。 | ||
| 103 | + - `eps`支持标量或shape为`[1]`的一维张量。 | ||
| 104 | + - `sum_grad_r`、`sum_grad_c`和`sum_grad_rc`的shape分别为`[batch..., N]`、`[batch..., M]`和`[batch...]`;当`grad`的rank为2时,`sum_grad_rc`为标量。 | ||
| 105 | +- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>、<term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term>: | ||
| 106 | + - `grad`仅支持shape为`[N, M]`的二维张量。 | ||
| 107 | + - `eps`仅支持标量。 | ||
| 108 | + - `sum_grad_r`、`sum_grad_c`和`sum_grad_rc`的shape分别为`[N]`、`[M]`和`[1]`。 | ||
| 109 | +- 本算子仅支持GE图模式调用,不提供公开的aclnn接口。 | ||
| 99 | 110 | ||
| 100 | ## 调用说明 | 111 | ## 调用说明 |
| 101 | 112 | ||
| @@ -18,14 +18,14 @@ namespace ge { | |||
| 18 | * | 18 | * |
| 19 | * @par Inputs: | 19 | * @par Inputs: |
| 20 | * including: | 20 | * including: |
| 21 | - * @li grad: A mutable Tensor with rank 2, such as [n, m] , support types: | 21 | + * @li grad: A mutable Tensor with rank not less than 2, such as [batch..., n, m] , support types: |
| 22 | * float16, float32, bfloat16. | 22 | * float16, float32, bfloat16. |
| 23 | - * @li eps: A scalar, support types: float32. \n | 23 | + * @li eps: A scalar or 1-element Tensor, support types: float32. \n |
| 24 | * | 24 | * |
| 25 | * @par Outputs: | 25 | * @par Outputs: |
| 26 | - * @li sum_grad_r: A 1-dimensional Tensor, such as [n], support types: float32. | 26 | + * @li sum_grad_r: A Tensor with shape [batch..., n], support types: float32. |
| 27 | - * @li sum_grad_c: A 1-dimensional Tensor, such as [m], support types: float32. | 27 | + * @li sum_grad_c: A Tensor with shape [batch..., m], support types: float32. |
| 28 | - * @li sum_grad_rc: A 1-dimensional Tensor, such as [1], support | 28 | + * @li sum_grad_rc: A Tensor with shape [batch...], and a scalar when grad rank is 2, support |
| 29 | * types: float32. \n | 29 | * types: float32. \n |
| 30 | * | 30 | * |
| 31 | * @par Restrictions: | 31 | * @par Restrictions: |
| @@ -1,38 +0,0 @@ | |||
| 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 | - * Generated By CANNBot | ||
| 11 | - */ | ||
| 12 | - | ||
| 13 | -/** | ||
| 14 | - * NOTE: Portions of this code were AI-generated and have been | ||
| 15 | - * technically reviewed for functional accuracy and security | ||
| 16 | - */ | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | -using namespace ge; | ||
| 21 | - | ||
| 22 | -namespace ops { | ||
| 23 | -namespace { | ||
| 24 | -constexpr size_t kSumGradRIndex = 0; | ||
| 25 | -constexpr size_t kSumGradCIndex = 1; | ||
| 26 | -constexpr size_t kSumGradRCIndex = 2; | ||
| 27 | -} // namespace | ||
| 28 | - | ||
| 29 | -static ge::graphStatus InferDataType4ApplyCamePart1(gert::InferDataTypeContext* context) | ||
| 30 | -{ | ||
| 31 | - context->SetOutputDataType(kSumGradRIndex, ge::DT_FLOAT); | ||
| 32 | - context->SetOutputDataType(kSumGradCIndex, ge::DT_FLOAT); | ||
| 33 | - context->SetOutputDataType(kSumGradRCIndex, ge::DT_FLOAT); | ||
| 34 | - return ge::GRAPH_SUCCESS; | ||
| 35 | -} | ||
| 36 | - | ||
| 37 | -IMPL_OP(ApplyCamePart1).InferDataType(InferDataType4ApplyCamePart1); | ||
| 38 | -} // namespace ops | ||
| @@ -159,7 +159,6 @@ | |||
| 159 | - `u`和输入`m`必须为形状相同的二维ND张量,两个维度都必须大于0,且每个维度不超过`INT32_MAX`。 | 159 | - `u`和输入`m`必须为形状相同的二维ND张量,两个维度都必须大于0,且每个维度不超过`INT32_MAX`。 |
| 160 | - `eps`、`beta1`、`clip_threshold`和`sum_square_u`必须为FLOAT32类型的标量或单元素一维张量。 | 160 | - `eps`、`beta1`、`clip_threshold`和`sum_square_u`必须为FLOAT32类型的标量或单元素一维张量。 |
| 161 | - `global_shape`为可选INT64类型输入,必须是一维长度为2的张量`[global_n, global_m]`;未提供时使用输入`u`的二维形状进行归约计算。 | 161 | - `global_shape`为可选INT64类型输入,必须是一维长度为2的张量`[global_n, global_m]`;未提供时使用输入`u`的二维形状进行归约计算。 |
| 162 | -- 本仓新增Ascend950/arch35实现;Atlas A2/A3产品沿用canndev既有实现。当前未提供aclnn接口,使用图模式调用。 | ||
| 163 | 162 | ||
| 164 | ## 调用说明 | 163 | ## 调用说明 |
| 165 | 164 | ||
| @@ -5,29 +5,27 @@ | |||
| 5 | | 产品 | 是否支持 | | 5 | | 产品 | 是否支持 | |
| 6 | | :----------------------------------------- | :------:| | 6 | | :----------------------------------------- | :------:| |
| 7 | | <term>Ascend 950PR/Ascend 950DT</term> | √ | | 7 | | <term>Ascend 950PR/Ascend 950DT</term> | √ | |
| 8 | -| <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ | | 8 | +| <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | × | |
| 9 | -| <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | √ | | 9 | +| <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | × | |
| 10 | | <term>Atlas 200I/500 A2 推理产品</term> | × | | 10 | | <term>Atlas 200I/500 A2 推理产品</term> | × | |
| 11 | | <term>Atlas 推理系列产品</term> | × | | 11 | | <term>Atlas 推理系列产品</term> | × | |
| 12 | | <term>Atlas 训练系列产品</term> | × | | 12 | | <term>Atlas 训练系列产品</term> | × | |
| 13 | 13 | ||
| 14 | ## 功能说明 | 14 | ## 功能说明 |
| 15 | 15 | ||
| 16 | -- 算子功能:InplaceApplyCenteredRMSProp是Centered RMSProp优化器步进的in-place实现,对标TensorFlow `ResourceApplyCenteredRMSProp`,在模型训练的每步迭代中根据梯度、学习率和衰减率就地更新权重变量(var)、梯度移动平均(mg)、梯度平方移动平均(ms)和动量缓冲区(mom)。 | 16 | +- 算子功能:实现Centered RMSProp优化器的参数更新。在模型训练过程中,根据当前梯度、学习率和衰减系数,原地更新模型参数`var`、梯度一阶矩`mg`、梯度二阶矩`ms`和动量`mom`。 |
| 17 | - 计算公式: | 17 | - 计算公式: |
| 18 | 18 | ||
| 19 | -$$ | 19 | + $$ |
| 20 | -\begin{aligned} | 20 | + \begin{aligned} |
| 21 | -\text{mg}_t &= \rho \cdot \text{mg}_{t-1} + (1 - \rho) \cdot \text{grad} \\ | 21 | + mg_t &= \rho \cdot mg_{t-1} + (1 - \rho) \cdot g_t \\ |
| 22 | -\text{ms}_t &= \rho \cdot \text{ms}_{t-1} + (1 - \rho) \cdot \text{grad}^2 \\ | 22 | + ms_t &= \rho \cdot ms_{t-1} + (1 - \rho) \cdot g_t^2 \\ |
| 23 | -\text{mom}_t &= \text{momentum} \cdot \text{mom}_{t-1} + \frac{\text{lr} \cdot \text{grad}}{\sqrt{\text{ms}_t - \text{mg}_t^2 + \epsilon}} \\ | 23 | + mom_t &= \mu \cdot mom_{t-1} + lr \cdot \frac{g_t}{\sqrt{ms_t - mg_t^2 + \epsilon}} \\ |
| 24 | -\text{var}_t &= \text{var}_{t-1} - \text{mom}_t | 24 | + var_t &= var_{t-1} - mom_t |
| 25 | -\end{aligned} | 25 | + \end{aligned} |
| 26 | -$$ | 26 | + $$ |
| 27 | 27 | ||
| 28 | -其中:var为权重,mg为梯度移动平均,ms为梯度平方移动平均,mom为动量缓冲区,grad为梯度,lr为学习率,rho为衰减率,momentum为动量系数,epsilon为数值稳定性常数。 | 28 | + 其中,$var$表示模型参数,$mg$表示梯度一阶矩,$ms$表示梯度二阶矩,$mom$表示动量,$g_t$表示当前步梯度,$lr$表示学习率,$\rho$表示衰减系数,$\mu$表示动量系数,$\epsilon$表示数值稳定性常数。$\epsilon$位于平方根内部,与TensorFlow `ResourceApplyCenteredRMSProp`的计算方式一致。 |
| 29 | - | ||
| 30 | -epsilon加在sqrt内部(`sqrt(ms - mg² + epsilon)`),对标TensorFlow。PyTorch的epsilon在sqrt之外,不作为对标对象。 | ||
| 31 | 29 | ||
| 32 | ## 参数说明 | 30 | ## 参数说明 |
| 33 | 31 | ||
| @@ -49,99 +47,99 @@ epsilon加在sqrt内部(`sqrt(ms - mg² + epsilon)`),对标TensorFlow。Py | |||
| 49 | <tbody> | 47 | <tbody> |
| 50 | <tr> | 48 | <tr> |
| 51 | <td>var</td> | 49 | <td>var</td> |
| 52 | - <td>输入 / 输出(inplace)</td> | 50 | + <td>输入</td> |
| 53 | - <td>模型权重张量。Kernel内inplace更新,GE IR输出视图与输入var共享Device内存。</td> | 51 | + <td>待更新的模型参数,shape与mg、ms、mom和grad一致。</td> |
| 54 | <td>FLOAT、FLOAT16</td> | 52 | <td>FLOAT、FLOAT16</td> |
| 55 | <td>ND</td> | 53 | <td>ND</td> |
| 56 | </tr> | 54 | </tr> |
| 57 | <tr> | 55 | <tr> |
| 58 | <td>mg</td> | 56 | <td>mg</td> |
| 59 | - <td>输入(inplace更新)</td> | 57 | + <td>输入</td> |
| 60 | - <td>梯度移动平均。shape/dtype必须与var一致;Kernel内显式写回输入GM地址。</td> | 58 | + <td>梯度一阶矩的指数移动平均,shape与var一致。</td> |
| 61 | <td>FLOAT、FLOAT16</td> | 59 | <td>FLOAT、FLOAT16</td> |
| 62 | <td>ND</td> | 60 | <td>ND</td> |
| 63 | </tr> | 61 | </tr> |
| 64 | <tr> | 62 | <tr> |
| 65 | <td>ms</td> | 63 | <td>ms</td> |
| 66 | - <td>输入(inplace更新)</td> | 64 | + <td>输入</td> |
| 67 | - <td>梯度平方移动平均。shape/dtype必须与var一致;Kernel内显式写回输入GM地址。</td> | 65 | + <td>梯度二阶矩的指数移动平均,shape与var一致。</td> |
| 68 | <td>FLOAT、FLOAT16</td> | 66 | <td>FLOAT、FLOAT16</td> |
| 69 | <td>ND</td> | 67 | <td>ND</td> |
| 70 | </tr> | 68 | </tr> |
| 71 | <tr> | 69 | <tr> |
| 72 | <td>mom</td> | 70 | <td>mom</td> |
| 73 | - <td>输入(inplace更新)</td> | 71 | + <td>输入</td> |
| 74 | - <td>动量缓冲区。shape/dtype必须与var一致;Kernel内显式写回输入GM地址。</td> | 72 | + <td>动量,shape与var一致。</td> |
| 75 | <td>FLOAT、FLOAT16</td> | 73 | <td>FLOAT、FLOAT16</td> |
| 76 | <td>ND</td> | 74 | <td>ND</td> |
| 77 | </tr> | 75 | </tr> |
| 78 | <tr> | 76 | <tr> |
| 79 | <td>lr</td> | 77 | <td>lr</td> |
| 80 | <td>输入</td> | 78 | <td>输入</td> |
| 81 | - <td>学习率(0-d tensor)。dtype必须与var一致。</td> | 79 | + <td>学习率。必须为标量或仅含一个元素的一维张量。</td> |
| 82 | <td>FLOAT、FLOAT16</td> | 80 | <td>FLOAT、FLOAT16</td> |
| 83 | <td>ND</td> | 81 | <td>ND</td> |
| 84 | </tr> | 82 | </tr> |
| 85 | <tr> | 83 | <tr> |
| 86 | <td>rho</td> | 84 | <td>rho</td> |
| 87 | <td>输入</td> | 85 | <td>输入</td> |
| 88 | - <td>衰减率(0-d tensor)。dtype必须与var一致。</td> | 86 | + <td>衰减系数。必须为标量或仅含一个元素的一维张量。</td> |
| 89 | <td>FLOAT、FLOAT16</td> | 87 | <td>FLOAT、FLOAT16</td> |
| 90 | <td>ND</td> | 88 | <td>ND</td> |
| 91 | </tr> | 89 | </tr> |
| 92 | <tr> | 90 | <tr> |
| 93 | <td>momentum</td> | 91 | <td>momentum</td> |
| 94 | <td>输入</td> | 92 | <td>输入</td> |
| 95 | - <td>动量系数(0-d tensor)。dtype必须与var一致。</td> | 93 | + <td>动量系数。必须为标量或仅含一个元素的一维张量。</td> |
| 96 | <td>FLOAT、FLOAT16</td> | 94 | <td>FLOAT、FLOAT16</td> |
| 97 | <td>ND</td> | 95 | <td>ND</td> |
| 98 | </tr> | 96 | </tr> |
| 99 | <tr> | 97 | <tr> |
| 100 | <td>epsilon</td> | 98 | <td>epsilon</td> |
| 101 | <td>输入</td> | 99 | <td>输入</td> |
| 102 | - <td>数值稳定性常数(0-d tensor),加在sqrt内部。dtype必须与var一致。</td> | 100 | + <td>数值稳定性常数。必须为标量或仅含一个元素的一维张量。</td> |
| 103 | <td>FLOAT、FLOAT16</td> | 101 | <td>FLOAT、FLOAT16</td> |
| 104 | <td>ND</td> | 102 | <td>ND</td> |
| 105 | </tr> | 103 | </tr> |
| 106 | <tr> | 104 | <tr> |
| 107 | <td>grad</td> | 105 | <td>grad</td> |
| 108 | <td>输入</td> | 106 | <td>输入</td> |
| 109 | - <td>当前步梯度。shape/dtype必须与var一致。</td> | 107 | + <td>当前步梯度,shape与var一致。</td> |
| 110 | <td>FLOAT、FLOAT16</td> | 108 | <td>FLOAT、FLOAT16</td> |
| 111 | <td>ND</td> | 109 | <td>ND</td> |
| 112 | </tr> | 110 | </tr> |
| 113 | <tr> | 111 | <tr> |
| 114 | <td>use_locking</td> | 112 | <td>use_locking</td> |
| 115 | <td>属性</td> | 113 | <td>属性</td> |
| 116 | - <td>是否在更新时加锁。默认false。当前实现不强制互斥锁,仅作语义占位。</td> | 114 | + <td>可选兼容属性,默认值为false,取值不影响计算结果。</td> |
| 117 | <td>BOOL</td> | 115 | <td>BOOL</td> |
| 118 | <td>-</td> | 116 | <td>-</td> |
| 119 | </tr> | 117 | </tr> |
| 120 | <tr> | 118 | <tr> |
| 121 | - <td>var (output)</td> | 119 | + <td>var</td> |
| 122 | <td>输出</td> | 120 | <td>输出</td> |
| 123 | - <td>更新后的var Tensor,与输入var共享Device内存(inplace)。</td> | 121 | + <td>更新后的模型参数,与输入var共享存储。</td> |
| 124 | <td>FLOAT、FLOAT16</td> | 122 | <td>FLOAT、FLOAT16</td> |
| 125 | <td>ND</td> | 123 | <td>ND</td> |
| 126 | </tr> | 124 | </tr> |
| 127 | <tr> | 125 | <tr> |
| 128 | - <td>mg (output)</td> | 126 | + <td>mg</td> |
| 129 | <td>输出</td> | 127 | <td>输出</td> |
| 130 | - <td>更新后的mg Tensor,与输入mg共享Device内存(inplace)。</td> | 128 | + <td>更新后的梯度一阶矩,与输入mg共享存储。</td> |
| 131 | <td>FLOAT、FLOAT16</td> | 129 | <td>FLOAT、FLOAT16</td> |
| 132 | <td>ND</td> | 130 | <td>ND</td> |
| 133 | </tr> | 131 | </tr> |
| 134 | <tr> | 132 | <tr> |
| 135 | - <td>ms (output)</td> | 133 | + <td>ms</td> |
| 136 | <td>输出</td> | 134 | <td>输出</td> |
| 137 | - <td>更新后的ms Tensor,与输入ms共享Device内存(inplace)。</td> | 135 | + <td>更新后的梯度二阶矩,与输入ms共享存储。</td> |
| 138 | <td>FLOAT、FLOAT16</td> | 136 | <td>FLOAT、FLOAT16</td> |
| 139 | <td>ND</td> | 137 | <td>ND</td> |
| 140 | </tr> | 138 | </tr> |
| 141 | <tr> | 139 | <tr> |
| 142 | - <td>mom (output)</td> | 140 | + <td>mom</td> |
| 143 | <td>输出</td> | 141 | <td>输出</td> |
| 144 | - <td>更新后的mom Tensor,与输入mom共享Device内存(inplace)。</td> | 142 | + <td>更新后的动量,与输入mom共享存储。</td> |
| 145 | <td>FLOAT、FLOAT16</td> | 143 | <td>FLOAT、FLOAT16</td> |
| 146 | <td>ND</td> | 144 | <td>ND</td> |
| 147 | </tr> | 145 | </tr> |
| @@ -149,14 +147,16 @@ epsilon加在sqrt内部(`sqrt(ms - mg² + epsilon)`),对标TensorFlow。Py | |||
| 149 | 147 | ||
| 150 | ## 约束说明 | 148 | ## 约束说明 |
| 151 | 149 | ||
| 152 | -- **数据类型一致性**:var、mg、ms、mom、grad五个tensor的数据类型必须一致;lr、rho、momentum、epsilon四个scalar的数据类型必须与tensor一致。 | 150 | +- var、mg、ms、mom和grad的shape必须完全一致。 |
| 153 | -- **Shape约束**:var、mg、ms、mom、grad的shape必须完全相同;lr、rho、momentum、epsilon必须为scalar(0-d tensor);tensor维度范围0-8维。 | 151 | +- lr、rho、momentum和epsilon必须为标量或仅含一个元素的一维张量。 |
| 154 | -- **In-place语义**:var、mg、ms、mom四个参数为就地更新,执行后原始数据被覆盖。 | 152 | +- 所有输入和输出的数据类型必须相同,支持FLOAT和FLOAT16。 |
| 155 | -- **epsilon位置**:epsilon必须加在sqrt内部(`sqrt(ms - mg² + ε)`),禁止实现为 `sqrt(ms - mg²) + ε`。 | 153 | +- var、mg、ms和mom均为原地更新,输出与对应输入共享存储。 |
| 156 | -- **标量精度**:lr/rho/momentum/epsilon统一在FP32域读取,禁止用FP16标量参与计算。 | 154 | +- <term>Ascend 950PR/Ascend 950DT</term>: |
| 157 | -- **FP16计算**:FP16输入在kernel内部提升到FP32计算,结果cast回FP16(CAST_NONE输入 / CAST_RINT输出)。 | 155 | + - var、mg、ms、mom、grad及其对应输出仅支持ND格式,rank不超过8。 |
| 158 | -- **大值溢出**:当 `ms - mg² + ε` 接近零时,`lr * grad / sqrt(denom)` 会产生大值溢出,kernel保持数学正确性(不截断、不饱和),输出可能为Inf/NaN。 | 156 | + - 支持空Tensor。 |
| 159 | -- **空Tensor**:支持空Tensor(numel=0),kernel跳过计算。 | 157 | + - FLOAT16输入在内部使用FLOAT精度进行计算,结果转换为FLOAT16后输出。 |
| 158 | +- `use_locking`仅用于接口兼容,当前实现不提供额外的互斥锁。 | ||
| 159 | +- 本算子仅支持GE图模式调用,不提供公开的aclnn接口。 | ||
| 160 | 160 | ||
| 161 | ## 调用说明 | 161 | ## 调用说明 |
| 162 | 162 | ||
NULL数据格式?有这种format?