文件最后提交记录最后更新时间
14 天前
15 天前
15 天前
15 天前
15 天前
15 天前
15 天前
15 天前
1 个月前
14 天前
README

LpNormV2

产品支持情况

产品 是否支持
Ascend 950PR/Ascend 950DT
Atlas A3 训练系列产品/Atlas A3 推理系列产品
Atlas A2 训练系列产品/Atlas A2 推理系列产品
Atlas 200I/500 A2 推理产品
Atlas 推理系列产品
Atlas 训练系列产品

功能说明

  • 接口功能:返回给定张量的矩阵范数或者向量范数。

  • 计算公式:支持1/2范数、无穷范数以及其他p为float类型的范数计算。

    • 1-范数:

      ∥x∥=max(∑i=1N∣xi∣,epsilon)\Vert x \Vert = max(\sum_{i=1}^{N}{\vert x_i \vert}, epsilon)

    • 2-范数(默认值):

      ∥x∥2=max((∑i=1N∣xi∣2)12,epsilon)\Vert x \Vert_2 = max((\sum_{i=1}^{N}{\vert x_i \vert^2})^{\frac{1}{2}}, epsilon)

    • 无穷范数:

      ∥x∥∞=max(max⁡i∣xi∣,epsilon)\Vert x \Vert_\infty = max(\max\limits_{i}{\vert x_i \vert}, epsilon)

      ∥x∥−∞=max(min⁡i∣xi∣,epsilon)\Vert x \Vert_{-\infty} = max(\min\limits_{i}{\vert x_i \vert}, epsilon)

    • p范数:

      ∥x∥p=max((∑i=1N∣xi∣p)1p,epsilon)\Vert x \Vert_p = max((\sum_{i=1}^{N}{\vert x_i \vert^p})^{\frac{1}{p}}, epsilon)

参数说明

参数名 输入/输出/属性 描述 数据类型 数据格式
x 输入 公式中的x。 FLOAT32、FLOAT16、BFLOAT16 ND
p 可选属性 表示范数的类型,公式中的p。 FLOAT32 -
axes 可选属性 计算self范数的维度。 INT64 -
keepdim 可选属性 决定输出张量是否保留dim参数指定的轴。 BOOL -
epsilon 可选属性 防止范数结果为0,以确保数值稳定。默认值为:1e-12f。 - -
y 输出 公式中的输出。 FLOAT32、FLOAT16、BFLOAT16 ND

约束说明

调用示例

调用方式 样例代码 说明
aclnn接口 test_aclnn_norm 通过aclnnNorm接口方式调用LpNormV2算子。
aclnn接口 test_aclnn_linalg_vector_norm 通过aclnnLinalgVectorNorm接口方式调用LpNormV2算子。
图模式 - 通过算子IR构图方式调用LpNormV2算子。