CdistGrad
English | 简体中文
Product Support Status
| Product | Supported |
|---|---|
| Ascend 950PR&950DT products | √ |
| Atlas A3 products | √ |
| Atlas A2 products | √ |
| Atlas 200I/500 A2 inference products | × |
| Atlas inference products | √ |
| Atlas training products | √ |
Function Description
-
Operator function: performs the backpropagation of Cdist.
-
Computation formula:
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: variable difference
- cdist=∑(x1−x2)pp\mathrm{cdist} = \sqrt[p]{\sum (x_1 - x_2)^p}: pp-norm distance
Parameter Description
| Parameter Name | Input/Output/Attribute | Description | Data Type | Data Format |
|---|---|---|---|---|
| grad | Input | Input grad in the formula. | FLOAT16, FLOAT32 | ND |
| x1 | Input | Input x1 in the formula. | FLOAT16, FLOAT32 | ND |
| x2 | Input | Input x2 in the formula. | FLOAT16, FLOAT32 | ND |
| cdist | Input | Input cdist in the formula. | FLOAT16, FLOAT32 | ND |
| p | Attribute | Input p in the formula. | float | ND |
| out | Output | Output out in the formula. | FLOAT16, FLOAT32 | ND |
Constraint Description
None
Invocation Description
| Invocation Method | Sample Code | Description |
|---|---|---|
| aclnn API | test_aclnn_cdist_backward | Invokes the CdistGrad operator through the aclnnCdistBackward API. |