[object Object]

[object Object][object Object]undefined
[object Object]
  • Description: Computes the negative log-likelihood loss.

  • Formula:

    If [object Object] is [object Object]:

    (x,y)=L={l1,,lN},ln=wynxn,yn,wc=weight[c]1{cignoreIndex},\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad l_n = - w_{y_n} x_{n,y_n}, \quad w_{c} = \text{weight}[c] \cdot \mathbb{1}\{c \not= \text{ignoreIndex}\},

    xx indicates self, yy indicates target, ww indicates weight, and NN indicates the batch size. If [object Object] is not [object Object]:

    (x,y)={n=1N1n=1Nwynln,if reduction=‘mean’;n=1Nln,if reduction=‘sum’.\ell(x, y) = \begin{cases} \sum_{n=1}^N \frac{1}{\sum_{n=1}^N w_{y_n}} l_n, & \text{if reduction} = \text{`mean';}\\ \sum_{n=1}^N l_n, & \text{if reduction} = \text{`sum'.} \end{cases} totalWeight=n=1NwyntotalWeight = \sum_{n=1}^N w_{y_n}
[object Object]

Each operator has calls. First, aclnnNLLLossGetWorkspaceSize is called to obtain the workspace size required for computation and the executor that contains the operator computation process. Then, aclnnNLLLoss is called to perform computation.

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

    • self (aclTensor*, compute input): input tensor, [object Object] in the formula. The shape is (N, C) or (C). It is an aclTensor on the device. N indicates the batch size, and C indicates the number of classes. are supported. The can be ND.

      • [object Object]Atlas inference series products[object Object] and [object Object]Atlas training series products[object Object]: The data type can be FLOAT or FLOAT16.
      • [object Object]Atlas A2 training products/Atlas A2 inference products[object Object] and [object Object]Atlas A3 training series products/Atlas A3 inference series products[object Object]: The data type can be FLOAT, FLOAT16, or BFLOAT16.
    • target (aclTensor*, compute input): real label, input [object Object] in the formula, aclTensor on the device. When the shape of self is (N, C), the shape of target is (N). When the shape of self is (C), the shape of target is (), and the value range of each element is [0, C – 1]. The data type can be INT64, UINT8, or INT32. are supported. The can be ND.

    • weight (aclTensor*, compute input): scaling weight of each class, input [object Object] in the formula, aclTensor on the device. The shape is (C). are supported. The can be ND. The data type is the same as that of self.

    • reduction (int64_t*, compute input): reduction to be applied to the output, [object Object] in the formula. The value can be 0 ('none') | 1 ('mean') | 2 ('sum'). none indicates that no reduction is applied; mean indicates that the sum of the output will be divided by the number of elements in the output; sum indicates that the output will be summed.

    • ignoreIndex (int64_t*, compute input): target value that is ignored and does not affect the input gradient, [object Object] in the formula.

    • out (aclTensor*, compute output): [object Object] in the formula. When reduction is 0 (none) and the shape of self is two-dimensional, the shape of out is (N,). Otherwise, the shape is (1,). The can be ND. The data type is the same as that of self.

    • totalWeightOut (aclTensor*, compute output): [object Object] in the formula. The output value is valid when reduction is not 0 (none). The shape is (1,). The can be ND. The data type is the same as that of self.

    • workspaceSize (uint64_t*, output): size of the workspace to be allocated on the device.

    • executor (aclOpExecutor**, output): operator executor, containing the operator computation process.

  • Returns:

    aclnnStatus: status code. For details, see .

[object Object]
[object Object]
  • Parameters:

    • workspace (void*, input): address of the workspace to be allocated on the device.

    • workspaceSize (uint64_t, input): size of the workspace to be allocated on the device, which is obtained by the first-phase API aclnnNLLLossGetWorkspaceSize.

    • executor (aclOpExecutor*, input): operator executor, containing the operator computation process.

    • stream (aclrtStream, input): stream for executing the task.

  • Returns:

    aclnnStatus: status code. For details, see .

[object Object]
  • Deterministic compute:
    • aclnnNLLLoss defaults to a non-deterministic implementation. You can call aclrtCtxSetSysParamOpt to enable deterministic compute.
[object Object]

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

[object Object]