LayerNormGrad
产品支持情况
| 产品 | 是否支持 |
|---|---|
| Ascend 950PR/Ascend 950DT | √ |
| Atlas A3 训练系列产品/Atlas A3 推理系列产品 | × |
| Atlas A2 训练系列产品/Atlas A2 推理系列产品 | × |
| Atlas 200I/500 A2 推理产品 | × |
| Atlas 推理系列产品 | × |
| Atlas 训练系列产品 | × |
功能说明
-
算子功能:LayerNorm的反向传播。用于计算输入张量的梯度,以便在反向传播过程中更新模型参数。
-
计算公式:
rstd=1variance+epsilonrstd = \frac{1}{\sqrt{variance + epsilon}}
res_for_gamma=(input−mean)×rstdres\_for\_gamma = (input - mean) \times rstd
dy_g=gradOut×weightdy\_g = gradOut \times weight
temp1=1/N×∑reduce_axis_1gradOut×weighttemp_1 = 1/N \times \sum_{reduce\_axis\_1} gradOut \times weight
temp2=1/N×(input−mean)×rstd×∑reduce_axis_1(gradOut×weight×(input−mean)×rstd)temp_2 = 1/N \times (input - mean) \times rstd \times \sum_{reduce\_axis\_1}(gradOut \times weight \times (input - mean) \times rstd)
gradInputOut=(gradOut×weight−(temp1+temp2))×rstdgradInputOut = (gradOut \times weight - (temp_1 + temp_2)) \times rstd
gradWeightOut=∑reduce_axis_0gradOut×(input−mean)×rstdgradWeightOut = \sum_{reduce\_axis\_0}gradOut \times (input - mean) \times rstd
gradBiasOut=∑reduce_axis_0gradOutgradBiasOut = \sum_{reduce\_axis\_0}gradOut
其中,N为进行归一化计算的轴的维度,即归一化轴维度的大小。
参数说明
| 参数名 | 输入/输出 | 描述 | 数据类型 | 数据格式 |
|---|---|---|---|---|
| dy | 输入 |
|
FLOAT32、FLOAT16、BFLOAT16 | ND |
| x | 输入 |
|
FLOAT32、FLOAT16、BFLOAT16 | ND |
| variance | 输入 |
|
FLOAT32、FLOAT16、BFLOAT16 | ND |
| mean | 输入 |
|
FLOAT32、FLOAT16、BFLOAT16 | ND |
| gamma | 输入 |
|
FLOAT32、FLOAT16、BFLOAT16 | ND |
| pd_x | 输出 |
|
FLOAT32、FLOAT16、BFLOAT16 | ND |
| pd_gamma | 输出 |
|
FLOAT32、FLOAT16、BFLOAT16 | ND |
| pd_beta | 输出 |
|
FLOAT32、FLOAT16、BFLOAT16 | ND |
约束说明
无
调用说明
| 调用方式 | 样例代码 | 说明 |
|---|---|---|
| 图模式 | - | 通过算子IR构图方式调用LayerNormGrad算子。 |