FilesLast commitLast update
7 days ago
3 months ago
3 days ago
8 months ago
3 days ago
9 months ago
3 months ago
3 days ago
30 days ago
14 days ago
README

KlDivV2

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: computes the KL divergence.
  • Computation formula:
    • Defines loss_pointwise to store intermediate results.

      loss_pointwisei={NaN if logTarget=false and targeti<=0,targeti∗(log⁡(targeti)−selfi) if logTarget=false,exp⁡targeti∗(targeti−selfi) else. loss\_pointwise_i=\begin{cases} NaN & \text{ if }&logTarget=false \text{ and } target_i <= 0, \\ target_i * \left ( \log{(target_i)}- self_i \right ) & \text{ if }& logTarget=false, \\ \exp^ {target_i} * \left ( target_i- self_i \right ) & \text{ else. } \end{cases}

    • The computation formula of out is:

      out={loss_pointwiseˉ if reduction=1,∑loss_pointwise elif reduction=2,∑loss_pointwiseself.size(0) elif reduction=3,loss_pointwise else. out=\begin{cases} \bar{loss\_pointwise} & \text{ if }& reduction= 1, \\ \sum loss\_pointwise & \text{ elif }& reduction= 2,\\ \frac{\sum loss\_pointwise}{self.size(0)} & \text{ elif }& reduction= 3,\\ loss\_pointwise & \text{ else. } \end{cases}

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
x Input Input tensor x in the formula. FLOAT, FLOAT16, BFLOAT16 ND
target Input Input tensor x in the formula. FLOAT, FLOAT16, BFLOAT16 ND
reduction Optional attribute
  • reduction in the formula.
  • The default value is mean.
STRING ND
log_target Optional attribute
  • logTarget in the formula.
  • The default value is false.
BOOL ND
y Output Output tensor y in the formula. FLOAT, FLOAT16, BFLOAT16 ND

Constraint Description

None

Invocation Description

Invocation Method Invocation Sample Description
aclnn invocation test_aclnn_kl_div_v2 Invokes the KlDivV2 operator through the aclnnKlDiv API.
Graph-mode invocation test_geir_kl_div_v2 Invokes the KlDivV2 operator by building a graph through the operator IR.