CdistGrad

产品支持情况

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

功能说明

  • 算子功能:完成Cdist的反向。。

  • 计算公式:

    out=grad⋅y′=grad⋅(∑(x1−x2)pp)′=grad⋅1p×(∑(x1−x2)p)1p−1×p×(x1−x2)p−1=grad⋅(∑(x1−x2)p)−(p−1)p×(x1−x2)p−1=grad⋅(∑(x1−x2)p)1p×(−(p−1))×(x1−x2)p−1=grad⋅diffp−1cdistp−1=grad⋅diff×∣diff∣p−2cdistp−1\begin{aligned} out&=grad \cdot y' \\ &= grad \cdot \left( \sqrt[p]{\sum (x_1 - x_2)^p} \right)' \\ &= grad \cdot \frac{1}{p} \times \left( \sum (x_1 - x_2)^p \right)^{\frac{1}{p}-1} \times p \times (x_1 - x_2)^{p-1} \\ &= grad \cdot \left( \sum (x_1 - x_2)^p \right)^{\frac{-(p-1)}{p}} \times (x_1 - x_2)^{p-1} \\ &= grad \cdot \left( \sum (x_1 - x_2)^p \right)^{\frac{1}{p} \times (-(p-1))} \times (x_1 - x_2)^{p-1} \\ &= grad \cdot \frac{diff^{p-1}}{cdist^{p-1}} \\ &= grad \cdot \frac{diff \times |diff|^{p-2}}{cdist^{p-1}} \end{aligned}

    • diff=x1−x2\mathrm{diff} = x_1 - x_2 :变量差值
    • cdist=∑(x1−x2)pp\mathrm{cdist} = \sqrt[p]{\sum (x_1 - x_2)^p}pp -范数距离

参数说明

参数名 输入/输出/属性 描述 数据类型 数据格式
grad 输入 公式中的输入grad。 FLOAT16、FLOAT32 ND
x1 输入 公式中的输入x1。 FLOAT16、FLOAT32 ND
x2 输入 公式中的输入x2。 FLOAT16、FLOAT32 ND
cdist 输入 公式中的输入cdist。 FLOAT16、FLOAT32 ND
p 属性 公式中的输入p。 float ND
out 输出 公式中的输出out。 FLOAT16、FLOAT32 ND

约束说明

调用说明

调用方式 样例代码 说明
aclnn接口 test_aclnn_cdist_backward 通过aclnnCdistBackward接口方式调用CdistGrad算子。