| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 10 天前 | ||
| 19 天前 | ||
| 1 个月前 | ||
| 10 天前 | ||
| 1 个月前 | ||
| 10 天前 | ||
| 1 个月前 | ||
| 10 天前 |
SparseApplyFtrl
产品支持情况
| 产品 | 是否支持 |
|---|---|
| Ascend 950PR/Ascend 950DT | √ |
| Atlas A3 训练系列产品/Atlas A3 推理系列产品 | × |
| Atlas A2 训练系列产品/Atlas A2 推理系列产品 | × |
| Atlas 200I/500 A2 推理产品 | × |
| Atlas 推理系列产品 | × |
| Atlas 训练系列产品 | × |
功能说明
-
算子功能:SparseApplyFtrl是FTRL-Proximal(Follow The Regularized Leader)优化器的稀疏更新算子。根据
indices选择var、accum、linear的对应行,使用梯度grad进行FTRL-Proximal更新。该算子广泛用于推荐系统、CTR预估等场景中的稀疏特征权重更新。 -
计算公式:
accum_new=accum+grad2\text{accum\_new} = \text{accum} + \text{grad}^2
σ=accum−lr_power−accum_new−lr_powerlr\sigma = \frac{\text{accum}^{-\text{lr\_power}} - \text{accum\_new}^{-\text{lr\_power}}}{\text{lr}}
linear_new=linear+grad+σ⋅var\text{linear\_new} = \text{linear} + \text{grad} + \sigma \cdot \text{var}
x=clamp(linear_new,−l1,l1)−linear_newx = \text{clamp}(\text{linear\_new}, -l1, l1) - \text{linear\_new}
y=accum_new−lr_powerlr+2⋅l2y = \frac{\text{accum\_new}^{-\text{lr\_power}}}{\text{lr}} + 2 \cdot l2
var_new=xy\text{var\_new} = \frac{x}{y}
参数说明
| 参数名 | 输入/输出/属性 | 描述 | 数据类型 | 数据格式 |
|---|---|---|---|---|
| var | 输入 | 待更新的变量tensor,≥2维 | FLOAT | ND |
| accum | 输入 | 梯度平方累加器,shape与var相同 | FLOAT | ND |
| linear | 输入 | 线性累加器,shape与var相同 | FLOAT | ND |
| grad | 输入 | 梯度tensor,shape[1:] == var.shape[1:] | FLOAT | ND |
| indices | 输入 | 索引向量,1-D,shape[0] == grad.shape[0] | INT32、INT64 | ND |
| lr | 输入 | 学习率,标量tensor | FLOAT | ND |
| l1 | 输入 | L1正则化系数,标量tensor | FLOAT | ND |
| l2 | 输入 | L2正则化系数,标量tensor | FLOAT | ND |
| lr_power | 输入 | 学习率幂次,标量tensor | FLOAT | ND |
| var | 输出 | 更新后的变量,shape/dtype同输入var | FLOAT | ND |
| accum | 输出 | 更新后的累加器,shape/dtype同输入accum | FLOAT | ND |
| linear | 输出 | 更新后的线性累加器,shape/dtype同输入linear | FLOAT | ND |
| use_locking | 属性 | 是否使用锁保护更新操作(当前实现未使用) | BOOL | - |
约束说明
- var/accum/linear必须具有相同的shape和dtype(float32)。
- grad.shape[1:] 必须等于var.shape[1:],grad.shape[0] 必须等于indices.shape[0]。
- indices必须为1-D tensor。
- lr/l1/l2/lr_power为标量tensor(0-D)。
- lr为学习率,作为输入时不能为0。
- indices必须唯一(不可有重复值)。TensorFlow和Ascend官方均声明:indices重复时行为未定义。
- indices取值范围必须满足0 <= indices[i] < var.shape[0]。kernel不做运行时越界检查,越界将导致内存越界读写。
- 输入tensor必须为连续内存布局。kernel使用扁平寻址假设连续内存;
AutoContiguous()仅在aclnn通路生效,geir/tf通路需调用方保证输入连续。
调用说明
| 调用方式 | 调用样例 | 说明 |
|---|---|---|
| 图模式调用 | - | 通过[算子IR](..op_graph/sparse_apply_ftrl_proto.h)构图方式调用SparseApplyFtrl算子。 |