API function: The TransformBiasRescaleQkv operator is an interface used to process the query, key, and value vectors in the multi-head attention mechanism. It is used to adjust the bias and rescale factors of these vectors to optimize the attention computation process.
Formulas: The element-wise computation process is as follows:
In the formula:
[object Object]indicates the dimension of each attention head.- q[object Object]o[object Object], k[object Object]o[object Object], and v[object Object]o[object Object] are the output elements of the query, key, and value vectors, respectively.
- q[object Object]i[object Object], k[object Object]i[object Object], and v[object Object]i[object Object] are the input elements of the query, key, and value vectors, respectively.
- q[object Object]bias[object Object], k[object Object]bias[object Object], and v[object Object]bias[object Object] are the input element offsets of the query, key, and value vectors, respectively.
Each operator has calls. First, [object Object] is called to obtain the input parameters and compute the required workspace size based on the process. Then, [object Object] is called to perform computation.
Parameters
[object Object]Returns
[object Object]: status code. For details, see .The first-phase API implements input parameter validation. The following error codes may be returned.
[object Object]
Deterministic computation:
[object Object]defaults to a deterministic implementation.
The data types of the inputs
[object Object]and[object Object], and outputs[object Object],[object Object], and[object Object]must be the same.If the input is NaN, the output is also NaN. If the input is Inf, the output is also Inf.
If the input is
[object Object], the output is[object Object].
The following example is for reference only. For details, see .