[object Object]

[object Object][object Object]undefined
[object Object]
  • Description: Calculates the KL divergence.
  • Formula:
    • Defines loss_pointwise and saves the intermediate result.

      loss_pointwisei={NaN if logTarget=false and targeti<=0,targeti(log(targeti)selfi) if logTarget=false,exptargeti(targetiselfi) 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}
    • Formula for computing [object Object]:

      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}
[object Object]

Each operator has calls. First, [object Object] is called to obtain the input parameters and compute the required workspace size based on the process. Then, [object Object] is called to perform computation.

  • [object Object]
  • [object Object]
[object Object]
  • Parameters:

    • [object Object] (aclTensor*, compute input): [object Object] in the formula. [object Object] on the device. The data type must meet the type deduction rules (for details, see ) with target, and the shape must meet the with target. are supported. The can be ND.
      • [object Object]Atlas A2 training products/Atlas A2 inference products[object Object] and [object Object]Atlas A3 training products/Atlas A3 inference products[object Object].
      • [object Object]Atlas inference products[object Object] and [object Object]Atlas training products[object Object]: FLOAT, FLOAT16.
    • [object Object] (aclTensor*, compute input): [object Object] in the formula. The data type must meet the type deduction rules (see ) with self, and the shape must meet the with self. are supported. The can be ND. [object Object]Atlas A2 training products/Atlas A2 inference products[object Object] and [object Object]Atlas A3 training products/Atlas A3 inference products[object Object]. [object Object]Atlas inference products[object Object] and [object Object]Atlas training products[object Object]: FLOAT, FLOAT16.
    • [object Object] (int64_t, compute input): [object Object] in the formula, which specifies the operation after loss_pointwise is computed.
      • 0: none, indicating that the reduction operation is not performed.
      • 1: mean, indicating that the mean value of loss_pointwise is computed.
      • 2: sum, indicating the sum of loss_pointwise.
      • 3: batchmean, indicating that the average loss of a batch is computed, which is consistent with the mathematical definition of Kullback-Leibler divergence.
    • [object Object] (bool, compute input): specifies whether the input target data has been computed using the logarithm.
    • [object Object] (aclTensor*, compute output): [object Object] in the formula. The data types of out and self must meet the type deduction rules (see ). When [object Object] is 0, the shape must meet the with [object Object] and [object Object]. When [object Object] is not 0, the shape is fixed at (1,). The can be ND. [object Object]Atlas A2 training products/Atlas A2 inference products[object Object] and [object Object]Atlas A3 training products/Atlas A3 inference products[object Object]. [object Object]Atlas inference products[object Object] and [object Object]Atlas training products[object Object]: FLOAT, FLOAT16.
    • [object Object] (uint64_t*, output): size of the workspace to be allocated on the device.
    • [object Object] (aclOpExecutor**, output): operator executor, containing the operator computation process.
  • Returns:

    [object Object]: status code. For details, see .

    [object Object]
[object Object]
  • Parameters:

    • [object Object] (void*, input): address of the workspace to be allocated on the device.
    • [object Object] (uint64_t, input): size of the workspace to be allocated on the device, which is obtained by calling aclnnKlDivGetWorkspaceSize.
    • [object Object] (aclOpExecutor*, input): operator executor, containing the operator computation process.
    • [object Object] (aclrtStream, input): stream for executing the task.
  • Returns:

    [object Object]: status code. For details, see .

[object Object]
  • Deterministic computation:
    • [object Object] defaults to a deterministic implementation.
[object Object]

The following example is for reference only. For details, see .

[object Object]