| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 2 个月前 | ||
| 7 个月前 | ||
| 7 个月前 | ||
| 1 个月前 | ||
| 2 个月前 | ||
| 3 个月前 | ||
| 8 个月前 | ||
| 1 个月前 |
ApplyFusedEmaAdam
产品支持情况
| 产品 | 是否支持 |
|---|---|
| Ascend 950PR/Ascend 950DT | √ |
| Atlas A3 训练系列产品/Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品/Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | × |
| Atlas 推理系列产品 | × |
| Atlas 训练系列产品 | × |
功能说明
-
算子功能:实现FusedEmaAdam融合优化器功能,结合了Adam优化器和指数移动平均(EMA)技术。
-
计算公式:
(correctionβ1,correctionβ2,)={(1,1),biasCorrection=False(1−β1step,1−β2step),biasCorrection=True(correction_{\beta_1},correction_{\beta_2},)=\begin{cases} (1,1),&biasCorrection=False\\ (1-\beta_1^{step},1-\beta_2^{step}),&biasCorrection=True \end{cases}
grad={grad+weightDecay∗var,mode=0grad,mode=1grad=\begin{cases} grad+weightDecay*var,&mode=0\\ grad,&mode=1 \end{cases}
mout=β1∗m+(1−β1)∗gradm_{out}=\beta_1*m+(1-\beta_1)*grad
vout=β2∗v+(1−β2)∗grad2v_{out}=\beta_2*v+(1-\beta_2)*grad^2
mnext=mout/correctionβ1m_{next}=m_{out}/correction_{\beta_1}
vnext=vout/correctionβ2v_{next}=v_{out}/correction_{\beta_2}
denom=vnext+epsdenom=\sqrt{v_{next}}+eps
update={mnext/denom,mode=0mnext/denom+weightDecay∗var,mode=1update=\begin{cases} m_{next}/denom,&mode=0\\ m_{next}/denom+weightDecay*var,&mode=1 \end{cases}
varout=var−lr∗updatevar_{out}=var-lr*update
sout=emaDecay∗s+(1−emaDecay)∗varouts_{out}=emaDecay*s+(1-emaDecay)*var_{out}
参数说明
| 参数名 | 输入/输出/属性 | 描述 | 数据类型 | 数据格式 |
|---|---|---|---|---|
| grad | 输入 | 待更新参数对应的梯度,对应公式中的grad。 | BFLOAT16、FLOAT16、FLOAT | ND |
| varRef | 输入/输出 | 待更新参数,对应公式中的var。 | BFLOAT16、FLOAT16、FLOAT | ND |
| mRef | 输入/输出 | 待更新参数对应的一阶动量,对应公式中的m。 | BFLOAT16、FLOAT16、FLOAT | ND |
| vRef | 输入/输出 | 待更新参数对应的二阶动量,对应公式中的v。 | BFLOAT16、FLOAT16、FLOAT | ND |
| sRef | 输入/输出 | 待更新参数对应的EMA权重,对应公式中的s。 | BFLOAT16、FLOAT16、FLOAT | ND |
| step | 输入 | 优化器当前的更新次数,对应公式中的step。 | INT64 | ND |
| lr | 属性 | 学习率,对应公式中的lr,取值范围是(0,1),默认为1e-3。 | FLOAT | - |
| emaDecay | 属性 | 指数移动平均(EMA)的衰减速率,对应公式中的emaDecay,取值范围是(0,1),默认为0.9999。 | FLOAT | - |
| beta1 | 属性 | 计算一阶动量的系数,对应公式中的β1,取值范围是(0,1),默认为0.9。 | FLOAT | - |
| beta2 | 属性 | 计算二阶动量的系数,对应公式中的β2,取值范围是(0,1),默认为0.999。 | FLOAT | - |
| eps | 属性 | 加到分母上的项,用于数值稳定性,对应公式中的eps,默认为1e-8。 | FLOAT | - |
| mode | 属性 | 控制应用L2正则化还是权重衰减,对应公式中的mode,1为adamw,0为L2,默认为1。 | INT64 | - |
| biasCorrection | 属性 | 控制是否进行偏差校正,对应公式中的biasCorrection,true表示进行校正,false表示不做校正,默认为True。 | BOOL | - |
| weightDecay | 属性 | 权重衰减,对应公式中的weightDecay,取值范围是(0,1),默认为0.0。 | FLOAT | - |
约束说明
- 输入grad、var、m、v、s的数据类型和shape必须保持一致。
调用说明
| 调用方式 | 样例代码 | 说明 |
|---|---|---|
| aclnn接口 | test_aclnn_apply_fused_ema_adam | 通过aclnnApplyFusedEmaAdam接口方式调用ApplyFusedEmaAdam算子。 |