[object Object]

[object Object][object Object]undefined
[object Object]
  • Description: Computes the backward pass of aclnnCrossEntropyLoss.
  • Formula:ignoreMasktarget(t)={1,target(t)ignoreIndex0,target(t)=ignoreIndexignoreMask_{target(t)}=\begin{cases} 1, &target(t) ≠ ignoreIndex \\ 0, &target(t) = ignoreIndex \end{cases} smoothLossGrad={grad/sum(weighttargetignoreMask)labelSmoothing/C,reduction=meangradlabelSmoothing/C,reduction=sumgradlabelSmoothing/C,reduction=nonesmoothLossGrad=\begin{cases} grad / sum(weight_{target}* ignoreMask) * labelSmoothing / C, &reduction = mean \\ grad * labelSmoothing / C, &reduction = sum \\ grad * labelSmoothing / C, &reduction = none \end{cases} lossOutGrad={grad(1labelSmoothing)/sum(weighttargetignoreMask)ignoreMask,reduction=meangrad(1labelSmoothing)ignoreMask,reduction=sumgrad(1labelSmoothing)ignoreMask,reduction=nonelossOutGrad=\begin{cases} grad * (1-labelSmoothing) / sum(weight_{target}* ignoreMask) * ignoreMask, &reduction = mean \\ grad * (1-labelSmoothing) * ignoreMask, &reduction = sum \\ grad * (1-labelSmoothing) * ignoreMask, &reduction = none \end{cases} nllLossGrad=lossOutGradweighttargetnllLossGrad = lossOutGrad * weight_{target} logSoftmaxGradLossOutSubPart=exp(logProb)nllLossGradlogSoftmaxGradLossOutSubPart = exp(logProb) * nllLossGrad predictionsGradLossOutij={nllLossGradi,j=target(i)0,jtarget(i)predictionsGradLossOut_{ij}=\begin{cases} nllLossGrad_i, & j=target(i) \\ 0, & j ≠ target(i) \end{cases} predictionsGradLossOut=logSoftmaxGradLossOutSubPartpredictionsGradLossOutpredictionsGradLossOut = logSoftmaxGradLossOutSubPart - predictionsGradLossOut smoothLossGrad=smoothLossGradignoreMasksmoothLossGrad = smoothLossGrad * ignoreMask logSoftmaxGradSmoothLoss=smoothLossGradweightlogSoftmaxGradSmoothLoss = smoothLossGrad * weight predictionsGradSmoothLoss=exp(logProb)sum(logSoftmaxGradSmoothLoss)logSoftmaxGradSmoothLosspredictionsGradSmoothLoss = exp(logProb) * sum(logSoftmaxGradSmoothLoss) - logSoftmaxGradSmoothLoss Non-zloss scenario:xGradout=predictionsGradLossOut+predictionsGradSmoothLossxGrad_{out} = predictionsGradLossOut + predictionsGradSmoothLoss zloss scenario:gradZ={grad+gradZloss,ifgradZlossisprovidedgrad,ifgradZlossisnotprovidedgradZ=\begin{cases} grad + gradZloss, & if gradZloss is provided \\ grad, & if gradZloss is not provided \end{cases} zlossGrad={gradZ/sum(ignoreMask),reduction=meangradZ,reduction=sumgradZ,reduction=nonezlossGrad=\begin{cases} gradZ / sum(ignoreMask), & &reduction = mean \\ gradZ, & &reduction = sum \\ gradZ, & &reduction = none \end{cases} lseGrad=2lseSquareScaleForZlosslseForZlossignoreMaskzlossGradlseGrad = 2 * lseSquareScaleForZloss * lseForZloss * ignoreMask * zlossGrad zlossOutputGrad=exp(logProb)lseGradzlossOutputGrad = exp(logProb) * lseGrad With zloss enabled, the output gradient is accumulated:xGradout=xGradout+zlossOutputGradxGrad_{out} = xGrad_{out} + zlossOutputGrad
[object Object]

Each operator has calls. First, aclnnCrossEntropyLossGradGetWorkspaceSize is called to obtain the workspace size required for computation and the executor that contains the operator computation flow. Then, aclnnCrossEntropyLossGrad is called to perform computation.

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

    [object Object]
  • Returns

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

    The first-phase API implements input parameter verification. The following errors may be thrown.

    [object Object]
[object Object]
  • Parameters

    [object Object]
  • Returns

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

[object Object]
  • target only supports class label indices; probabilistic inputs are not supported.

  • The data types of gradLoss, logProb, gradZlossOptional, lseForZlossOptional, and xGradOut must be the same.

  • The zloss-related features are currently not supported. Parameters gradZlossOptional, lseForZlossOptional, and lseSquareScaleForZloss are ignored even if provided.

  • Deterministic computation:

    • aclnnCrossEntropyLossGrad defaults to a deterministic implementation.
[object Object]

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

[object Object]