FastSoftMaxOperation
Applicable Products
|
Product |
Supported |
|---|---|
|
Atlas 350 accelerator cards |
x |
|
|
√ |
|
|
√ |
|
|
x |
|
|
x |
|
|
x |
Description
Training operator, which is used together with unpadOperation to perform high-performance SoftMax processing on the result of multiplying matrix Q and matrix K after unpadding.
SoftMax formula:

Use Cases
The Multi-Head Attention calculation process is shown in Figure 1. After unpad processing, the result of multiplying matrix Q and matrix K is actually concatenated by batchSize matrices whose sizes are (seqLen[i], seqLen[i]) (as shown in Figure 2). The SoftMax operation needs to be performed on the last axis of the result. The FastSoftMax operator is used to receive the seqLen and headNum information and implement the SoftMax operation on the data in this arrangement mode.
Definition
1 2 3 4 5 |
struct FastSoftMaxParam { int32_t headNum = 0; std::vector<int32_t> qSeqLen; uint8_t rsv[8] = {0}; }; |
Parameters
|
Member |
Type |
Default Value |
Description |
|---|---|---|---|
|
headNum |
int32_t |
0 |
Number of attention heads. The value must be greater than 0. |
|
qSeqLen |
std::vector<int32_t> |
- |
Actual input length of each batch. The number of elements is batchSize. The maximum value is 32. |
|
rsv[8] |
uint8_t |
{0} |
Reserved |
Input
|
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
|
inTensor |
[nSquareTokens] |
float16 |
ND |
Input tensor, which is the 1D result of batch (headNum, qSeqLen[i], qSeqLen[i]) matrices in ND format. |
Output
|
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
|
outTensor |
[nSquareTokens] |
float16 |
ND |
Output tensor. The data range is [0, 1]. |
Constraints
Functions
When the parameter list contains
,
the shape size of the corresponding input tensor is
.
For example,

In this case, the shape size of the input tensor is

The shape of the input and output tensors is [5528144].



