[object Object]

[object Object][object Object]undefined
[object Object]
  • Description: This operator is a part of the cross entropy computation module in the vocabulary parallelism scenario. It solves the video memory and computing efficiency problems in the case of ultra-large vocabulary. This part involves the gradient computation implementation, which is used to compute the gradients of leaf nodes [object Object] and [object Object]. The outputs of [object Object] and [object Object], along with the global communication result related to [object Object], need to be obtained as the input of this API.
  • Formula:

   High-performance mode, where the value of softmaxOptional is not nullptr:

softmaxRBT×V\text{softmax} \in \mathbb{R}^{BT \times V} arange_1d=[0,1,,BT1]NBT\text{arange\_1d} = [0, 1, \dots, BT-1] \in \mathbb{N}^{BT} softmax_update=1target_mask.view(1)RBT\text{softmax\_update} = \mathbf{1} - \text{target\_mask}.view(-1) \in \mathbb{R}^{BT} softmax[arange_1d,masked_target]softmax[arange_1d,masked_target]softmax_update\text{softmax}[\text{arange\_1d}, \text{masked\_target}] \leftarrow \text{softmax}[\text{arange\_1d}, \text{masked\_target}] - \text{softmax\_update} softmaxsoftmaxgrad.unsqueeze(1)RBT×V\text{softmax} \leftarrow \text{softmax} \odot \text{grad}.unsqueeze(-1) \in \mathbb{R}^{BT \times V} grad_input=softmaxweightTRBT×H\text{grad\_input} = \text{softmax} \cdot \text{weight}^T \in \mathbb{R}^{BT \times H} grad_weight=softmaxTinputRV×H\text{grad\_weight} = \text{softmax}^T \cdot \text{input} \in \mathbb{R}^{V \times H} [object Object]vocab_parallel_logits=inputweightTRBT×V\text{vocab\_parallel\_logits} = \text{input} \cdot \text{weight}^T \quad \in \mathbb{R}^{BT \times V} logits_sub=vocab_parallel_logitslogits_max.unsqueeze(1)RBT×V\text{logits\_sub} = \text{vocab\_parallel\_logits} - \text{logits\_max}.unsqueeze(-1) \quad \in \mathbb{R}^{BT \times V} exp_logits=exp(logits_sub)RBT×V\text{exp\_logits} = \exp(\text{logits\_sub}) \quad \in \mathbb{R}^{BT \times V} exp_logitsexp_logitssum_exp_logits.unsqueeze(1)RBT×V\text{exp\_logits} \gets \frac{\text{exp\_logits}}{\text{sum\_exp\_logits}.unsqueeze(-1)} \quad \in \mathbb{R}^{BT \times V} grad_logits=exp_logitsRBT×V\text{grad\_logits} = \text{exp\_logits} \quad \in \mathbb{R}^{BT \times V} grad_2d=grad_logits.view(1,partition_vocab_size)RBT×V\text{grad\_2d} = \text{grad\_logits}.view(-1, \text{partition\_vocab\_size}) \quad \in \mathbb{R}^{BT \times V} arange_1d=[0,1,,BT1]NBT\text{arange\_1d} = [0, 1, \dots, BT-1] \quad \in \mathbb{N}^{BT} softmax_update=1target_mask.view(1)RBT\text{softmax\_update} = 1 - \text{target\_mask}.view(-1) \quad \in \mathbb{R}^{BT} grad_2d[arange_1d,masked_target_1d]grad_2d[arange_1d,masked_target_1d]softmax_update\text{grad\_2d}[\text{arange\_1d}, \text{masked\_target\_1d}] \gets \text{grad\_2d}[\text{arange\_1d}, \text{masked\_target\_1d}] - \text{softmax\_update} grad_logitsgrad_logitsgrad.unsqueeze(1)RBT×V\text{grad\_logits} \gets \text{grad\_logits} \odot \text{grad}.unsqueeze(-1) \quad \in \mathbb{R}^{BT \times V} grad_input=grad_logitsweightRBT×H\text{grad\_input} = \text{grad\_logits} \cdot \text{weight} \quad \in \mathbb{R}^{BT \times H} grad_weight=grad_logitsTinputRV×H\text{grad\_weight} = \text{grad\_logits}^T \cdot \text{input} \quad \in \mathbb{R}^{V \times H} [object Object]

Each operator has calls. First, [object Object] is called to obtain the workspace size required for computation and the executor that contains the operator computation process. Then, [object Object] 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]
  • Deterministic description:
    • The aclnnFusedLinearCrossEntropyLossGrad is implemented in a deterministic manner by default.
[object Object]

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

[object Object]