[object Object][object Object][object Object]undefined
[object Object]
  • Adapts to the [object Object] operator in the incremental ([object Object]) and full ([object Object]) inference scenarios. When [object Object] of the [object Object] matrix is [object Object], the [object Object] branch is executed. In other scenarios, the [object Object] branch is executed. Compared with [object Object], this API introduces new parameters: [object Object], [object Object], and [object Object].

  • Formula:

    Self-attention constructs an attention model by leveraging the relationships within the input samples. The principle assumes there is an input sample sequence xx of length nn, where each element of xx is a dd-dimensional vector. Each dd-dimensional vector can be regarded as a token embedding. Such a sequence is transformed by three weight matrices to obtain three n×dn × d matrices.

    The computation formula for self-attention is generally defined as follows, where QQ, KK, and VV are key attribute elements of the input sample, obtained through spatial transformation and unified into a single feature space. "Attention" in the formula and operator name is an abbreviation for "self-attention."

    Attention(Q,K,V)=Score(Q,K)VAttention(Q,K,V)=Score(Q,K)V

    In this operator, the [object Object] function is used, instead of the [object Object] function. The self-attention computation formula is as follows:

    Attention(Q,K,V)=Softmax(QKTd)VAttention(Q,K,V)=Softmax(\frac{QK^T}{\sqrt{d}})V

    The product of QQ and KTK^T represents the attention to the input xx. To prevent this value from becoming excessively large, it is typically scaled by dividing by the square root of dd, followed by row-wise softmax normalization. The result is then multiplied by VV to produce an n×dn × d matrix.

[object Object]

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.

[object Object]
[object Object]
[object Object]
  • 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]
[object Object]
  • Parameters

    [object Object]
  • Returns

    [object Object]: status code. For details, see .

[object Object]
  • Deterministic computation:

    • [object Object] defaults to a deterministic implementation.
  • When this API is used together with PyTorch, ensure that the CANN package versions match the PyTorch package versions.

  • Processing logic for a null input parameter: The operator checks whether [object Object] is a null pointer. If so, an error is reported. If [object Object] is not an empty tensor but [object Object] and [object Object] are empty tensors (that is, [object Object] is [object Object]), [object Object] is filled with all zeros. If [object Object] is an empty tensor, the framework will process it. For other input parameters which support the passing of [object Object] as described in the preceding parameter description, no processing is performed when they are null pointers.

  • The shapes of the tensors corresponding to [object Object] and [object Object] must be identical. In non-contiguous scenarios, the batch size in the tensor lists of [object Object] and [object Object] can only be [object Object], the number of elements must be equal to the batch size ([object Object]) of [object Object], and the [object Object] and [object Object] dimensions must be the same. Due to the tensor list restrictions, [object Object] cannot be greater than [object Object] in non-contiguous scenarios.

  • When the data type of [object Object] is INT8 or UINT8, the value in the tensor must be [object Object] or [object Object].

  • [object Object][object Object]Restrictions on the number of input parameters and input and output data formats related to INT8 quantization:

    • If both the input and output are of the INT8 type, the input parameters [object Object], [object Object], [object Object], and [object Object] must exist at the same time. [object Object] is optional and defaults to [object Object] if not passed.
    • If the input is of the INT8 type and the output is of the FLOAT16 type, the input parameters [object Object], [object Object], and [object Object] must exist at the same time. If the input parameter [object Object] or [object Object] exists (not [object Object]), an error is reported and returned.
    • If the input is of the FLOAT16 or BFLOAT16 type and the output is of the INT8 type, the input parameter [object Object] must exist, and [object Object] is optional ([object Object] is used if no value is passed). If the input parameter [object Object], [object Object], or [object Object] exists (not [object Object]), an error is reported and returned.
    • The input parameters [object Object] and [object Object] support both the per-tensor and per-channel data formats and the FLOAT32 and BFLOAT16 data types. If [object Object] is passed, ensure that its type and shape are consistent with those of [object Object]. If the input is of the BFLOAT16 type, both FLOAT32 and BFLOAT16 are supported. Otherwise, only FLOAT32 is supported. In per-channel format, when the output layout is [object Object], the product of all dimensions of [object Object] must be equal to [object Object]. For other layouts, the product must be equal to [object Object] × [object Object]. (When the output layout is [object Object], it is recommended that the shape of [object Object] be set to [object Object] or [object Object]. When the output layout is [object Object], it is recommended that the shape of [object Object] be set to [object Object] or [object Object]. When the output layout is [object Object], it is recommended that the shape of [object Object] be set to [object Object] or [object Object].)
  • [object Object][object Object]Constraints on the fake-quantization parameters [object Object] and [object Object]:

    • Only the fake-quantization scenario where [object Object] is INT8 is supported.
    • Per-channel mode: The shapes of the two parameters can be [object Object], [object Object], or [object Object], where [object Object] is [object Object]. The data type is the same as that of [object Object], and [object Object] is set to [object Object].
    • Per-tensor mode: The shapes of the two parameters are [object Object], the data type is the same as that of [object Object], and [object Object] is set to [object Object].
    • Per-token mode: The shapes of the two parameters are [object Object], the data type is fixed at FLOAT32, and [object Object] is set to [object Object].
    • In asymmetric quantization mode, both [object Object] and [object Object] must be present.
    • In symmetric quantization mode, [object Object] can be [object Object]. If [object Object] is [object Object], symmetric quantization is performed. Otherwise, asymmetric quantization is performed.
  • Restrictions on the input parameters [object Object], [object Object], and [object Object] when the layout is [object Object], [object Object], or [object Object]:

    • Both [object Object] and [object Object] must be passed, and the number of elements in these input parameters is used as the batch size. The value of each element in these parameters indicates the sum of sequence lengths of the current batch and all previous batches. Therefore, the value of the next element must be greater than or equal to the value of the previous element.
    • [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
      • The sparse mode can only be [object Object] without a mask, [object Object] with a mask, or [object Object] with a mask.
      • When dimension [object Object] of [object Object] is [object Object]:
        • The layout can be [object Object] or [object Object].
        • Page attention must be enabled. In this case, the length of [object Object] is equal to the batch size of [object Object]/[object Object], indicating the actual length of each batch. The value must be less than or equal to [object Object].
        • Dimension [object Object] for each batch of [object Object] can be set to a value from [object Object] to [object Object].
        • Dimension [object Object] for [object Object] must be set to [object Object]/[object Object]/[object Object], and dimension [object Object] for [object Object] and [object Object] must be [object Object].
        • [object Object] and [object Object] must not be empty, and dimension [object Object] for both [object Object] and [object Object] must be set to [object Object].
        • Left padding, tensor list, PSE, prefix, fake-quantization, full quantization, and post-quantization are not supported.
        • When the layout is [object Object], [object Object] cannot be enabled.
      • When dimension [object Object] of [object Object] is not [object Object]:
        • When [object Object] and [object Object] are empty, if the layout is [object Object], [object Object], [object Object], and [object Object] must be equal and less than or equal to [object Object], or [object Object] and [object Object] must be equal to [object Object] and [object Object] must be equal to [object Object]/[object Object]; if the layout is [object Object], [object Object] and [object Object] must be equal to [object Object]/[object Object], and [object Object] must be equal to [object Object]. When [object Object] and [object Object] are not null, [object Object], [object Object], and [object Object] must be equal to [object Object].
        • The layout can be [object Object] or [object Object].
        • If the layout is [object Object], the data type can only be FLOAT16 or BFLOAT16. If the layout is [object Object], the data type can only be BFLOAT16.
        • If the layout is [object Object], when the head configuration is GQA/MQA (that is, the [object Object] and [object Object] parameters must be completely passed, [object Object] must be an integer multiple of [object Object], and the two values must be different), the following constraints apply:
          • When the data type is FLOAT16, the sparse mode can be [object Object] without a mask or [object Object] with optimized [object Object].
          • When the data type is BFLOAT16, the sparse mode can be [object Object] without a mask, [object Object] with optimized [object Object], or [object Object] with optimized [object Object].
          • [object Object] can only be [object Object], indicating the high-precision mode without invalid row correction.
          • Page attention is supported. The KV cache layout supports BnBsH [object Object], where [object Object] is less than or equal to [object Object] and [object Object] can only be [object Object].
        • If the layout is [object Object], when the head configuration is MHA, the following constraints apply:
          • When the data type is FLOAT16, the sparse mode can only be [object Object] without a mask.
          • When the data type is FLOAT16, [object Object] can only be [object Object].
          • When the data type is FLOAT16, page attention is not supported.
          • When the data type is BFLOAT16, the sparse mode can be [object Object] without a mask, [object Object] with optimized [object Object], or [object Object] with optimized [object Object].
        • If the layout is [object Object], page attention is not supported.
        • When the sparse mode is [object Object], [object Object] must be less than [object Object] for each batch.
        • The sparse mode can be [object Object] with a mask. When the sparse mode is [object Object], [object Object] must be greater than or equal to negative [object Object], [object Object] must be greater than or equal to negative [object Object], and the sum of [object Object] and [object Object] must be greater than or equal to [object Object].
        • Left padding, tensor list, PSE, page attention, prefix, fake-quantization, full quantization, and post-quantization are not supported.
        • The number of elements in [object Object] and [object Object] must be less than or equal to [object Object].
  • Constraints on [object Object] and [object Object] in the MLA structure:

    • The data type and format of [object Object] must be the same as those of [object Object].
    • The data type and format of [object Object] must be the same as those of [object Object].
    • Both [object Object] and [object Object] are configured, or neither of them is configured. Configuring only one of the parameters is not supported.
    • When [object Object] and [object Object] are input, only the following features are supported:
      • [object Object] can only be FP16 or BF16.
      • Dimension [object Object] in [object Object] can only be [object Object]/[object Object].
      • [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
        • When [object Object] is greater than [object Object] (that is, in the MTP mode), the [object Object] parameter can be configured only when [object Object] is [object Object]. Other layouts are not supported.
        • When dimension [object Object] of [object Object] is [object Object]:
          • When configuring [object Object], ensure that dimension [object Object] in [object Object] is set to a value from [object Object] to [object Object] and dimension [object Object] is [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], or [object Object]. In the shape of [object Object], dimension [object Object] is [object Object], and the values of other dimensions are the same as those of [object Object].
          • When configuring [object Object], ensure that dimension [object Object] in [object Object] is [object Object] and dimension [object Object] is [object Object]. In the shape of [object Object], dimension [object Object] is [object Object], and the values of other dimensions are the same as those of [object Object].
          • When [object Object] is [object Object], the sparse mode can only be [object Object] without a mask. When [object Object] is greater than [object Object], the sparse mode can only be [object Object] with a mask.
          • The ND and NZ inputs are supported for [object Object], [object Object], and [object Object]. The input format for NZ is [object Object].
          • [object Object] can be [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], or [object Object]. In the NZ input format, [object Object] cannot be [object Object] or [object Object].
          • When page attention must be enabled, [object Object] can be [object Object] or [object Object]. In the NZ input format, [object Object] cannot be set to [object Object].
          • Left padding, tensor list, PSE, prefix, fake-quantization, full quantization, and post-quantization are not supported.
        • When dimension [object Object] of [object Object] is [object Object]:
          • [object Object] can be [object Object] or [object Object].
          • When configuring [object Object], ensure that dimension [object Object] in the shape of [object Object] is [object Object], and the values of other dimensions are the same as those of [object Object].
          • When configuring [object Object], ensure that dimension [object Object] in the shape of [object Object] is [object Object], and the values of other dimensions are the same as those of [object Object].
          • Other restrictions are the same as those when the layout is [object Object] or [object Object].
          • Left padding, tensor list, PSE, page attention, prefix, fake-quantization, full quantization, and post-quantization are not supported.
  • Restrictions on [object Object]: [object Object] must be exactly divided by [object Object]. When the layout is [object Object], [object Object], or [object Object], the value must be the same as the N-axis value of [object Object]/[object Object] in the shape. Otherwise, an exception occurs.

  • Restrictions on [object Object]:

    [object Object]
  • Restrictions on [object Object]:

    • There are four modes ([object Object]0[object Object], [object Object]1[object Object], [object Object]2[object Object], and [object Object]3[object Object]) in total, represented by 2-bit combinations. Bit 0 indicates whether to use the high-precision or high-performance mode, and bit 1 indicates whether to perform invalid row correction.

      [object Object]
    • Note: The high-precision and high-performance modes are applicable to both BFLOAT16 and INT8. Invalid row correction takes effect for FLOAT16, BFLOAT16, and INT8. The values [object Object] and [object Object] are reserved. If the masks involved in the computation are all 1s, the precision may be affected. In this case, you can set this parameter to [object Object] or [object Object] to enable invalid row correction to improve the precision. However, this configuration deteriorates the performance. If the operator can determine that invalid rows exist, invalid row correction is automatically enabled, such as in scenarios where [object Object] is set to [object Object] and [object Object] is greater than [object Object].

  • Restrictions on [object Object]:

    [object Object]
    • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], if [object Object] is [object Object], passing a value other than [object Object], [object Object], [object Object], [object Object], [object Object], or [object Object] will result in an execution error. If [object Object] is greater than or equal to [object Object], only the values [object Object] and [object Object] are supported. Other values will result in an execution error.
  • Restrictions on [object Object]:

    • Except for the scenario where [object Object] is [object Object] and [object Object] is [object Object], the value must be the same as that of [object Object].
    • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], if [object Object] is [object Object], passing a value other than [object Object], [object Object], [object Object], [object Object], [object Object], or [object Object] will result in an execution error. If [object Object] is greater than or equal to [object Object], only the values [object Object] and [object Object] are supported. Other values will result in an execution error.
  • Restrictions on [object Object]:

    • In the ring attention algorithm, the product of [object Object] and [object Object] is first processed to obtain [object Object]. This max value is subtracted from the product before calculating the exponential, which is then summed to yield [object Object]. Finally, the log of [object Object] is added back to [object Object] to obtain the final result.
    • When [object Object] is [object Object], the shape must be [object Object] in general. When [object Object] is [object Object] or [object Object], the shape must be [object Object].
    • When [object Object] is [object Object], if the [object Object] tensor is not [object Object], the tensor data is returned directly. If [object Object] is [object Object], a tensor of shape [object Object] filled with zeros is returned.
  • When [object Object] is greater than [object Object]:

    • Restrictions on [object Object], [object Object], and [object Object]:

      • The B axis must be less than or equal to [object Object].

      • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], if the input type is INT8 and the D axis is not 32-byte aligned, the maximum value of the B axis is [object Object]. If the input type is FLOAT16 or BFLOAT16 and the D axis is not 16-byte aligned, the maximum value of the B axis is also [object Object].

      • The N axis can be less than or equal to [object Object], and the D axis can be less than or equal to [object Object]. If [object Object] is [object Object] or [object Object], it is recommended that N × D be less than [object Object].

      • The S axis must be less than or equal to [object Object] (20M). In some long sequence scenarios, if the computation load is too large, the PFA operator execution may time out (an AI Core error is reported, and [object Object] is [object Object]). In this case, S axis splitting is recommended. Note: The computation load is affected by parameters such as [object Object], [object Object], [object Object], and [object Object]. Larger values indicate larger computation loads. The following lists some typical scenarios with long sequences (that is, the product of [object Object], [object Object], [object Object], and [object Object] is large).

        [object Object]
      • Restrictions on the D axis: For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], if [object Object], [object Object], [object Object], or [object Object] is of the INT8 type, the D axis must be 32-byte aligned. If [object Object], [object Object], [object Object], or [object Object] is of the INT4 type, the D axis must be 64-byte aligned. If they are all of the FLOAT16 or BFLOAT16 type, the D axis must be 16-byte aligned.

    • For the input parameter [object Object], the value must be a non-negative number.

      • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], the valid sequence length of each batch in this input parameter must be less than or equal to the sequence length of the corresponding batch in [object Object]. If the input length of [object Object] is [object Object], all batches use the same [object Object]. If the input length is greater than or equal to the batch size, the first N elements (where N equals the batch size) of [object Object] are used. Other lengths are not supported.
    • For the input parameter [object Object], the value must be a non-negative number.

      • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], the valid sequence length of each batch in this input parameter must be less than or equal to the sequence length of the corresponding batch in [object Object] or [object Object]. If the input length of [object Object] is [object Object], all batches use the same [object Object]. If the input length is greater than or equal to the batch size, the first N elements (where N equals the batch size) of [object Object] are used. Other lengths are not supported.
    • Currently, [object Object] can only be set to [object Object], [object Object], [object Object], [object Object], or [object Object]. An error will be reported if it is set to other values.

      • When [object Object] is set to [object Object], if [object Object] is a null pointer or is passed in the left padding scenario, the input parameters [object Object] and [object Object] are ignored.
      • When [object Object] is set to [object Object], [object Object], or [object Object], the shape of [object Object] must be [object Object], [object Object], or [object Object], where [object Object] must be fixed at [object Object]. Additionally, the input[object Object] must be a lower triangular matrix. If [object Object] is not passed or the passed shape is incorrect, an error will be reported.
      • When [object Object] is set to [object Object], [object Object], or [object Object], the input parameters [object Object] and [object Object] are ignored, and their values are assigned based on related rules.
    • In the synthesis parameter scenario of KV cache dequantization, only when [object Object] is of the FLOAT16 type can [object Object] and [object Object] of the INT8 type be dequantized to FLOAT16. If the product of the data ranges of the input parameters [object Object] and [object Object] and the data range of the input parameter [object Object] must be within the range of (–1, 1), the high-performance mode can ensure precision. Otherwise, the high-precision mode needs to be enabled to ensure precision.

    • Page attention scenario:

      • The prerequisite for enabling page attention is that [object Object] exists and is valid, and [object Object] and [object Object] are arranged in a continuous memory based on the indexes in [object Object]. In this scenario, [object Object] of [object Object] and [object Object] is invalid. [object Object] is filled with block IDs. Currently, the validity of block IDs is not verified. You need to ensure the validity of block IDs.
        • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], the data types of [object Object] and [object Object] can be FLOAT16, BFLOAT16, or INT8.
      • [object Object] is a user-defined parameter. Its value affects the page attention performance. When page attention is enabled, the value of [object Object] must be a multiple of [object Object], ranging from [object Object] to [object Object]. Generally, page attention can improve the throughput but deteriorate the performance.
      • In the page attention scenario, if the input KV cache layout is BnBsH [object Object] and the product of [object Object] multiplied by [object Object] exceeds [object Object], an error will be reported due to hardware instruction constraints. This problem can be solved by enabling GQA (decreasing [object Object]) or adjusting the KV cache layout to BnNBsD [object Object]. When [object Object] of [object Object] is [object Object] or [object Object], the KV cache layout can be BnBsH or BnNBsD. When [object Object] of [object Object] is [object Object] or [object Object], the KV cache layout can only be BnBsH. The value of [object Object] cannot be less than the sum of blocks in each batch calculated based on [object Object] and [object Object]. The shapes of [object Object] and [object Object] must be the same.
      • Page attention fake-quantization scenario
        • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], the data type of [object Object] can be FLOAT16 or BFLOAT16, and the data types of [object Object] and [object Object] can be INT8.
      • Page attention full-quantization scenario
        • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], the data type of [object Object] cannot be INT8.
      • Page attention does not support the tensor list or left padding.
      • In the page attention scenario, [object Object] must be passed.
      • In the page attention scenario, [object Object] must be two-dimensional. The length of the first dimension must be equal to [object Object], and the length of the second dimension must be greater than or equal to [object Object] (the maximum number of blocks corresponding to [object Object] in different batches).
      • When page attention is enabled, the input [object Object] must be greater than or equal to [object Object] × [object Object] in the following scenarios:
        • [object Object] is passed, for example, when the mask shape is [object Object].
        • [object Object] is passed, for example, when the [object Object] shape is [object Object].
    • Left padding for [object Object]:

      • The transfer start point of [object Object] is calculated as follows: [object Object][object Object][object Object]. The transfer end point of [object Object] is calculated as follows: [object Object][object Object]. The transfer start point of [object Object] cannot be less than [object Object], while the end point cannot be greater than [object Object]. Otherwise, the result will not meet the expectation.
      • If [object Object] is less than [object Object], it will be set to [object Object].
      • It must be enabled together with [object Object]. Otherwise, the default scenario is right padding for [object Object].
      • It does not support page attention and cannot be enabled together with [object Object].
      • It is not supported when [object Object] is of type BF16/FP16 and [object Object] is of type INT4.
    • Left padding for [object Object]:

      • The transfer start point of [object Object] and [object Object] is calculated as follows: [object Object][object Object][object Object]. The transfer end point of [object Object] and [object Object] is calculated as follows: [object Object][object Object]. The transfer start point of [object Object] and [object Object] cannot be less than [object Object], while the end point cannot be greater than [object Object]. Otherwise, the result will not meet the expectation.
      • If [object Object] is less than [object Object], it will be set to [object Object].
      • It must be enabled together with [object Object]. Otherwise, the default scenario is right padding for [object Object].
      • It does not support page attention and cannot be enabled together with [object Object].
      • It is not supported when [object Object] is of type BF16/FP16 and [object Object] is of type INT4.
    • When the output is of type INT8 and [object Object] and [object Object] are per-channel, left padding, ring attention, or non-32-byte alignment of the D axis is not supported.

    • When the output is of type INT8, [object Object] cannot be [object Object] and [object Object] or [object Object] cannot be negative.

    • Restrictions on [object Object]:

      • This function is supported when the data type of [object Object] is FLOAT16, BFLOAT16, or INT8.
      • When the data type of [object Object] is FLOAT16 and [object Object] exists, the high-precision mode is forcibly used. The corresponding restrictions are the same as those of the high-precision mode.
      • [object Object] must be greater than or equal to [object Object] of [object Object], and [object Object] must be greater than or equal to [object Object] of [object Object]. In the prefix scenario, [object Object] must be greater than or equal to the sum of [object Object] and [object Object] of [object Object].
    • When the output is of type INT8, if the input parameter[object Object] is a non-null pointer and a non-null tensor, and [object Object], [object Object], and [object Object] meet the following conditions, certain rows of the matrix will not be involved in computation, resulting in a computation result error. In this scenario, the computation will be intercepted. (Solution: To prevent interception, perform post-quantization outside the FIA interface.)

      • When [object Object] is [object Object] and [object Object] is a non-null pointer, interception occurs if for any batch: [object Object][object Object][object Object][object Object] > [object Object], or [object Object] < [object Object].
      • When [object Object] is [object Object] or [object Object], interception does not occur.
      • When [object Object] is [object Object], interception occurs if for any batch: [object Object] + [object Object][object Object] < [object Object].
      • When [object Object] is [object Object], interception occurs if for any batch: [object Object] < [object Object], or [object Object] + [object Object] + [object Object][object Object] < [object Object].
    • Restrictions on prefix parameters:

      • Both [object Object] and [object Object] must be either null or non-null.
      • If neither [object Object] nor [object Object] is null, the dimensions and data types of [object Object], [object Object], [object Object], and [object Object] must be the same.
      • If neither [object Object] nor [object Object] is null, the first dimension (batch) of the shape of [object Object] must be [object Object]. When the layout is [object Object] or [object Object], the N and D axes must be the same as those of [object Object]. When the layout is [object Object], the H axis must be the same as that of [object Object]. The same rules apply to [object Object]. [object Object] of [object Object] and [object Object] must be the same.
      • When [object Object] exists, its shape must be [object Object], and its value cannot be greater than [object Object] of [object Object] and [object Object].
      • The sum of [object Object] of the public prefix and [object Object] of [object Object] or [object Object] must meet the original restriction on [object Object] of [object Object] or [object Object].
      • The prefix does not support page attention, left padding, or tensor list.
      • In the prefix scenario, when [object Object] is [object Object] or [object Object] and [object Object] is passed, [object Object] must be greater than or equal to the sum of [object Object] and [object Object] of [object Object].
      • In the prefix scenario, the input [object Object] cannot be all INT8.
    • KV fake-quantization parameter separation:

      • [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
        • [object Object] and [object Object] must be the same.
        • Both [object Object] and [object Object] must be either null or non-null. Both [object Object] and [object Object] must be either null or non-null.
        • If neither [object Object] nor [object Object] is null, their shapes must be the same. If neither [object Object] nor [object Object] is null, their shapes must be the same.
        • Only the per-token and per-channel modes are supported. In per-token mode, the shapes of the two parameters must be both [object Object], and the data type is fixed at FLOAT32. In per-channel mode, the shapes of the two parameters must be [object Object], [object Object], or [object Object], and the data type is fixed at BF16.
        • When both fake-quantization parameters and KV separation quantization parameters are passed, the KV separation quantization parameters take effect.
        • When [object Object] and [object Object] are non-null, [object Object] of [object Object] must be less than or equal to [object Object].
        • When [object Object] and [object Object] are non-null, the data type of [object Object] must be BFLOAT16, the data types of [object Object] and [object Object] must be INT8, and the data type of the output must be BFLOAT16.
        • When [object Object] and [object Object] are non-null, the tensor list, left padding, and page attention functions are not supported.
  • When [object Object] is equal to [object Object]:

    • Restrictions on [object Object], [object Object], and [object Object]:
      • The B axis can be less than or equal to [object Object], the N axis can be less than or equal to [object Object], and the D axis can be less than or equal to [object Object].
      • The input types of [object Object], [object Object], and [object Object] cannot be all INT8.
      • In INT4 (INT32) fake-quantization scenarios, the aclnn single-operator call supports KV inputs in either INT4 format or INT4-packed INT32 format. Using [object Object] to generate INT4 data is recommended, which stores eight INT4 elements within one INT32.
      • In INT4 (INT32) fake-quantization scenarios, if KV INT4 values are packed into INT32 inputs, the [object Object], [object Object], or [object Object] dimensions of KV must be 1/8 of their actual values (the same applies to prefix).
      • Restrictions on the D axis for [object Object] and [object Object] in specific data types
        • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], when the input type of [object Object] and [object Object] is INT4 (INT32), the D axis must be 64-byte aligned (or 8-byte aligned for INT32).
    • For the input parameter [object Object], the value must be a non-negative number.
      • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], when [object Object] of [object Object] is not [object Object], this parameter is invalid if [object Object] is [object Object].
    • For the input parameter [object Object], the value must be a non-negative number.
      • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], the valid sequence length of each batch in this input parameter must be less than or equal to the sequence length of the corresponding batch in [object Object] or [object Object]. If the input length of [object Object] is [object Object], all batches use the same [object Object]. If the input length is greater than or equal to the batch size, the first N elements (where N equals the batch size) of [object Object] are used. Other lengths are not supported.
    • Page attention scenario:
      • The prerequisite for enabling page attention is that [object Object] exists and is valid, and [object Object] and [object Object] are arranged in a continuous memory based on the indexes in [object Object]. In this scenario, [object Object] of [object Object] and [object Object] is invalid.
        • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], the data types of [object Object] and [object Object] can be FLOAT16, BFLOAT16, or INT8.
      • [object Object] is a user-defined parameter. Its value affects the page attention performance. When page attention is enabled, [object Object] must be set to a non-zero value, and the maximum value of [object Object] cannot exceed [object Object]. Generally, page attention can improve the throughput but deteriorate the performance.
        • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], if the input type of [object Object] and [object Object] is FLOAT16 or BFLOAT16, 16-byte alignment is required. If the input type of [object Object] and [object Object] is INT8, 32-byte alignment is required (128-byte alignment is recommended).
      • In the page attention scenario, when [object Object] of [object Object] is [object Object] or [object Object], the KV cache layout can be BnBsH [object Object] or BnNBsD [object Object]. When [object Object] of [object Object] is [object Object] or [object Object], the KV cache layout can only be BnBsH. The value of [object Object] cannot be less than the sum of blocks in each batch calculated based on [object Object] and [object Object]. The shapes of [object Object] and [object Object] must be the same.
      • In the page attention scenario, the performance is generally better when the KV cache layout is BnNBsD than when it is BnBsH. Therefore, BnNBsD is recommended.
      • In the page attention scenario, if the input KV cache layout is BnBsH and [object Object] × [object Object] exceeds 64 KB, an error will be reported due to hardware instruction constraints. This problem can be solved by enabling GQA (decreasing [object Object]) or adjusting the KV cache layout to BnNBsD.
      • Page attention does not support the tensor list or left padding:
        • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], scenarios where [object Object] is of type BF16/FP16 and [object Object] is of type INT4 (INT32) are not supported.
      • In the page attention scenario, [object Object] must be passed.
      • In the page attention scenario, [object Object] must be two-dimensional. The length of the first dimension must be equal to [object Object], and the length of the second dimension must be greater than or equal to [object Object] (the maximum number of blocks corresponding to [object Object] in each batch).
      • When page attention is enabled, the input [object Object] must be greater than or equal to [object Object] second dimension × [object Object] in the following scenarios:
        • [object Object] is enabled, for example, when the mask shape is [object Object].
        • [object Object] is enabled, for example, when the [object Object] shape is [object Object].
        • When the fake-quantization per-token mode is enabled, the shape of the input parameters [object Object] and [object Object] is both [object Object].
        • Per-token + per-head mode: The shapes of the two parameters are both [object Object], their data type is fixed at FLOAT32, and the data types of [object Object] and [object Object] are INT8 or INT4 (INT32).
        • Per-token-group mode: The shape of [object Object] is [object Object], and its data type is fixed at FLOAT8_E8M0. [object Object] is not supported. The data types of [object Object] and [object Object] are FLOAT4_E1M2 or FLOAT4_E2M1.
      • Left padding for [object Object]:
        • For [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], scenarios where [object Object] is of type BF16/FP16 and [object Object] is of type INT4 (INT32) are not supported.
        • The transfer start point of [object Object] is calculated as follows: [object Object][object Object][object Object]. The transfer end point of [object Object] is calculated as follows: [object Object][object Object]. If the transfer start point or end point is less than [object Object], the returned data is all 0s.
        • If [object Object] is less than [object Object], it will be set to [object Object].
        • It must be enabled together with [object Object]. Otherwise, the default scenario is right padding for [object Object].
        • Page attention and tensor list are not supported. Otherwise, the default scenario is right padding for [object Object].
        • When it is enabled together with [object Object], ensure that the meaning of [object Object] is correct, that is, invalid data can be correctly masked. Otherwise, precision issues may occur.
      • Restrictions on [object Object]:
        • The data types of [object Object] and [object Object] must be the same.
      • KV fake-quantization parameter separation:
        • Except when [object Object] is [object Object] and [object Object] is [object Object], the values of [object Object] and [object Object] must be the same.
        • Both [object Object] and [object Object] must be either null or non-null. Both [object Object] and [object Object] must be either null or non-null.
        • If neither [object Object] nor [object Object] is null, their shapes must be the same, except when [object Object] is [object Object] and [object Object] is [object Object]. If neither [object Object] nor [object Object] is null, their shapes must be the same, except when [object Object] is [object Object] and [object Object] is [object Object].
        • [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]: The following eight modes are supported: per-channel, per-tensor, per-token, per-tensor + per-head, per-token + per-head, per-token + page attention to manage scale/offset, per-token + per-head + page attention to manage scale/offset, and per-channel for [object Object] + per-token for [object Object]. In the following description, [object Object] indicates [object Object].
          • Per-channel mode: The shapes of the two parameters can be [object Object], [object Object], or [object Object], their data type is the same as that of [object Object], and the data types of [object Object] and [object Object] are INT8 or INT4 (INT32).
          • Per-tensor mode: The shapes of the two parameters are both [object Object], their data type is the same as that of [object Object], and the data types of [object Object] and [object Object] are INT8.
          • Per-token mode: The shapes of the two parameters are both [object Object], their data type is fixed at FLOAT32, and the data types of [object Object] and [object Object] are INT8 or INT4 (INT32).
          • Per-tensor + per-head mode: The shapes of the two parameters are both [object Object], their data type is the same as that of [object Object], and the data types of [object Object] and [object Object] are INT8.
          • Per-channel for [object Object] + per-token for [object Object] mode: In per-channel for [object Object], the shapes of the two parameters can be [object Object], [object Object], or [object Object], and their data type is the same as that of [object Object]. In per-token for [object Object], the shapes of the two parameters are both [object Object], and their data type is fixed at FLOAT32. The data types of [object Object] and [object Object] are INT8 or INT4 (INT32). When the data types of [object Object] and [object Object] are INT8, only the data types of [object Object] and [object Object] can be FLOAT16.
        • Per-token + per-head mode: The shapes of the two parameters are both [object Object], their data type is fixed at FLOAT32, and the data types of [object Object] and [object Object] are INT8 or INT4 (INT32).
        • Per-token + page attention to manage scale/offset: The shapes of the two parameters are both [object Object], their data type is fixed at FLOAT32, and the data types of [object Object] and [object Object] are INT8.
        • Per-token + per-head + page attention to manage scale/offset: The shapes of the two parameters are both [object Object], their data type is fixed at FLOAT32, and the data types of [object Object] and [object Object] are INT8.
        • When both fake-quantization parameters and KV separation quantization parameters are passed, the KV separation quantization parameters take effect.
        • In the INT4 (INT32) fake-quantization scenario where only KV fake-quantization parameter separation is supported, the following modes are supported:
          • Per-channel
          • Per-token
          • Per-token + per-head
          • Per-channel for [object Object] + per-token for [object Object]
        • Post-quantization is not supported in INT4 (INT32) fake-quantization scenarios.
      • Restrictions on prefix parameters:
        • Both [object Object] and [object Object] must be either null or non-null.
        • If neither [object Object] nor [object Object] is null, the dimensions and data types of [object Object], [object Object], [object Object], and [object Object] must be the same.
        • If neither [object Object] nor [object Object] is null, the first dimension (batch) of the shape of [object Object] must be [object Object]. When the layout is [object Object] or [object Object], the N and D axes must be the same as those of [object Object]. When the layout is [object Object], the H axis must be the same as that of [object Object]. The same rules apply to [object Object]. [object Object] of [object Object] and [object Object] must be the same.
        • When [object Object] exists, its shape must be [object Object], and its value cannot be greater than [object Object] of [object Object] and [object Object].
        • The sum of [object Object] of the public prefix and [object Object] of [object Object] or [object Object] must meet the original restriction on [object Object] of [object Object] or [object Object].
[object Object]

The following example is for reference only. For details, see .

[object Object]