Function: Rearranges data of the selectedBlockSize size from the key and value based on topkIndices, and then performs the backward output of attention calculation in the training scenario.
Calculation formula: Rearranges selectedBlockCount pieces of data of the selectedBlockSize size from the keyIn and value based on the input topkIndice. The formula is as follows:
Phase 1: Calculate and according to the matrix multiplication derivative rules.
[object Object] [object Object]Phase 2: Calculate .
[object Object] [object Object]Phase 3: Calculate and .
[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.
Parameters
[object Object]Return Value
[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:
- By default, aclnnSparseFlashAttentionGrad is implemented in non-deterministic mode. Deterministic computing can be enabled by using aclrtCtxSetSysParamOpt.
Common Constraints
- Handling of scenarios where the input parameter is empty:
- If
[object Object]is an empty tensor, the result is returned directly.
- If
- Currently, only the scenario where the value and key are the same is supported.
- Handling of scenarios where the input parameter is empty:
Mask
[object Object]Specification Restrictions
[object Object]
The following example is for reference only (using [object Object]Atlas A2 training products/Atlas A2 inference products[object Object] as examples). For details, see .