PrefixEncoder
You can connect PyTorch by calling the C API to replace affinity operators on the entire network.
Definition
atb::Status AtbSelfAttentionPrefixEncoderGetWorkspaceSize(const aclTensor *query, const aclTensor *key,
const aclTensor *value, const aclTensor *blockTables,
const aclTensor *mask, const aclTensor *seqLen,
const aclTensor *kvSeqLen, const aclTensor *slopes,
int maskType, int32_t headNum, int32_t kvHeadNum,
float qkScale, aclTensor *attnOut, uint64_t *workspaceSize,
atb::Operation **op, atb::Context *context);
atb::Status AtbSelfAttentionPrefixEncoder(void *workspace, uint64_t workspaceSize, atb::Operation *op,
atb::Context *context);
AtbSelfAttentionPrefixEncoderGetWorkspaceSize Members
Parameter |
Scalar/Tensor |
Dimension |
Data Type |
Format |
Default Value |
Mandatory |
Description |
|---|---|---|---|---|---|---|---|
query |
Tensor |
|
float16/bf16 |
ND |
- |
Yes |
Query matrix. |
key |
Tensor |
|
float16/bf16 |
ND |
- |
Yes |
Key matrix. |
value |
Tensor |
|
float16/bf16 |
ND |
- |
Yes |
Value matrix. |
blockTables |
Tensor |
[batch, maxBlockNum] |
int32 |
ND |
- |
Yes |
Block table of kvCache of each query. The first dimension is the token index, and the second dimension indicates the block index. |
mask |
Tensor |
|
float16/bf16 |
ND |
- |
No |
alibiMask. Set it to a nullptr if maskType is not MASK_TYPE_ALIBI_COMPRESS or MASK_TYPE_ALIBI_COMPRESS_SQRT. |
seqLen |
Tensor |
[batch] |
int32/uint32 |
ND |
- |
Yes |
Sequence length of each batch corresponding to query. Used on the host. |
kvSeqLen |
Tensor |
[batch] |
int32/uint32 |
ND |
- |
Yes |
Sequence length of each batch corresponding to key and value. Tensor on the host. |
slopes |
Tensor |
[head] |
fp32 |
ND |
- |
No |
ALiBi coefficient. When alibiMask is used and a tensor is passed, the value is the coefficient of each head of alibiMask. Set it to a nullptr if maskType is set to MASK_TYPE_CAUSAL_MASK. |
maskType |
Scalar |
- |
int |
- |
0 |
Yes |
Mask type. Options: 3: MASK_TYPE_ALIBI_COMPRESS, ALiBi-compressed mask. 4: MASK_TYPE_ALIBI_COMPRESS_SQRT, ALiBi-compressed mask with square root. 5: MASK_TYPE_ALIBI_COMPRESS_LEFT_ALIGN, ALiBi-compressed left-aligned mask. Supported only for 9: MASK_TYPE_CAUSAL_MASK, internally generated mask. |
headNum |
Scalar |
- |
int32_t |
- |
0 |
Yes |
Query head size, which must be greater than 0. |
kvHeadNum |
Scalar |
- |
int32_t |
- |
0 |
Yes |
Number of KV heads, depending on the model in use. |
qkScale |
Scalar |
- |
float |
- |
1 |
Yes |
Scale post-multiplied by Q*K^T. |
attnOut |
Tensor |
|
float16/bf16 |
ND |
- |
Yes |
Attention output. |