Description: The
[object Object]operator is the backward operator of[object Object], additionally integrating the Loss function. The[object Object]operator filters out the TopK with the highest intrinsic correlation between[object Object]and[object Object], storing them in[object Object], thereby reducing the computational load of attention in long-sequence scenarios and accelerating the inference and training performance of long-sequence networks.Formula: The formula for computing the value used to take the Top-k can be expressed as:
Here, represents the weights corresponding to the -th token, is the matrix obtained by concatenating the query heads corresponding to the -th token, and is the matrix of the -th row.
The
[object Object]will be trained separately, and the corresponding loss function is:Among them, is the target distribution, obtained by summing the main attention scores across all heads and then applying L1 normalization along the context direction. is the KL divergence, whose expression is:
By taking the derivative, the gradient expression of Loss can be obtained:
Using the chain rule, the gradients of the weights, query, and key matrices can be calculated:
Here, S is the result of the softmax operation on the QK matrix.
Each operator has calls. First call [object Object] to obtain the input parameters and calculate the required workspace size based on the computation process. Then, call [object Object] to execute the computation.
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]
- Deterministic computation:
[object Object]defaults to a non-deterministic implementation. Enabling deterministic computation through[object Object]is not supported.
- Common constraints
- Handling scenarios where input parameters are empty:
- If the query is an empty Tensor: return directly.
- In public constraints, the scenario where the input parameter is empty should be consistent with FAG.
- Handling scenarios where input parameters are empty:
- Specification constraints[object Object]
- Typical value[object Object]
The following example is for reference only. For details, see .