[object Object]

[object Object][object Object]undefined
[object Object]
  • API function: Performs single-channel rotary positional encoding calculation.

  • Formulas:

    • [object Object]Atlas A3 training products/Atlas A3 inference products[object Object] and [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:

    (1) half mode (mode = 0):

    x1=x[...,:x.shape[1]//2]x1 = x[..., : x.shape[-1] // 2] x2=x[...,x.shape[1]//2:]x2 = x[..., x.shape[-1] // 2 :] x_rotate=torch.cat((x2,x1),dim=1)x\_rotate = torch.cat((-x2, x1), dim=-1) y=xcos+x_rotatesiny = x * cos + x\_rotate * sin

    (2) interleave mode (mode = 1):

    x1=x[...,::2].view(1,1)x1 = x[..., ::2].view(-1, 1) x2=x[...,1::2].view(1,1)x2 = x[..., 1::2].view(-1, 1) x_rotate=torch.cat((x2,x1),dim=1).view(x.shape[0],x.shape[1],x.shape[2],x.shape[3])x\_rotate = torch.cat((-x2, x1), dim=-1).view(x.shape[0], x.shape[1], x.shape[2], x.shape[3]) y=xcos+x_rotatesiny = x * cos + x\_rotate * sin

    (3) quarter mode (mode = 2):

    x1=x[...,:x.shape[1]//4]x1 = x[..., : x.shape[-1] // 4] x2=x[...,x.shape[1]//4:x.shape[1]//2]x2 = x[..., x.shape[-1] // 4 : x.shape[-1] // 2] x3=x[...,x.shape[1]//2:x.shape[1]//43]x3 = x[..., x.shape[-1] // 2 : x.shape[-1] // 4 * 3] x4=x[...,x.shape[1]//43:]x4 = x[..., x.shape[-1] // 4 * 3 :] x_rotate=torch.cat((x2,x1,x4,x3),dim=1)x\_rotate = torch.cat((-x2, x1, -x4, x3), dim=-1) y=xcos+x_rotatesiny = x * cos + x\_rotate * sin

    (4) In interleave-half mode (mode=3), the input of odd bits is extracted to the first half, the input of even bits is extracted to the second half, and then half processing is performed.

    x1=x[...,::2]x1 = x[..., ::2] x2=x[...,1::2]x2 = x[..., 1::2] x_part1=torch.cat((x1,x2),dim=1)x\_part1 = torch.cat((x1, x2), dim=-1) x_part2=torch.cat((x2,x1),dim=1)x\_part2 = torch.cat((-x2, x1), dim=-1) y=x_part1cos+x_part2siny = x\_part1 * cos + x\_part2 * sin
[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]
    • [object Object]Atlas inference products[object Object]: The data type cannot be BFLOAT16.

    • Restrictions on the mode parameter:

      • [object Object]Atlas A3 training products/Atlas A3 inference products[object Object], [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]: 0 (half) and 1 (interleave)
      • Ascend 950PR/Ascend 950DT: 2=quarter, 3=interleave-half.
      • [object Object]Atlas inference products[object Object]: 0 (half)
  • 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]
[object Object]
  • Parameters:

    [object Object]
  • Returns

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

[object Object]
  • Deterministic computation:

    • The default deterministic implementation of aclnnRotaryPositionEmbedding is used.
  • Ascend 950PR/Ascend 950DT:

    The input tensor x has four dimensions. The shape constraints of each parameter are described as follows:

    • The last dimension of the input tensor x, cos, sin, and output tensor y must be the same and less than or equal to 1024. In half, interleave, and interleave-half modes, the last dimension must be exactly divisible by 2. In quarter mode, the last dimension must be exactly divisible by 4.
    • The shape of the input tensor x must be the same as that of the output tensor y.
    • The shapes of the input tensors cos and sin must be the same. The shapes of cos and sin must meet the with x, and the shape after broadcasting must be the same as the shape of x.
  • [object Object]Atlas A3 training products/Atlas A3 inference products[object Object] and [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:

    The input tensor x supports BNSD, BSND, SBND, and TND formats. The input tensor x, cos, sin, and the D dimension size of the output tensor y must be the same, and the value of D must be less than 896 and a multiple of 2. The input tensor x and the output tensor y must have the same shape. The input tensors cos and sin must have the same shape.

    • When [object Object] is [object Object]:
      • B, N < 1000;
      • When x is in BNSD format, cos and sin support 11SD, B1SD, and BNSD.
        • When (D/2) % (32/inputDtypeSize) == 0, B N <= S 8 must be met.
        • When (D/2) % (32/inputDtypeSize)!= 0, B N 2 <= (S + coreNum - 1) / coreNum or D >= 80 must be met.
      • When x is in BSND format, cos and sin support 1S1D, BS1D, and BSND.
      • When x is in SBND format, cos and sin support S11D, SB1D, and SBND.
      • When x is in TND format, cos and sin support T1D and TND.
    • When [object Object] is [object Object]:
      • B * N < 1000 (N < 1000 when x is in TND format)
      • When x is in BNSD format, cos and sin support 11SD.
      • When x is in BSND format, cos and sin support 1S1D.
      • When x is in SBND format, cos and sin support S11D.
      • When x is in TND format, cos and sin support T1D.
  • [object Object]Atlas inference products[object Object]

    The input tensor x supports BNSD, BSND, SBND, and TND formats. The input tensor x, cos, sin, and the D dimension size of the output tensor y must be the same, and the value of D must be less than or equal to 128 and a multiple of 32. The input tensor x and the output tensor y must have the same shape. The input tensors cos and sin must have the same shape.

    • Only the half mode is supported.
      • B, N < 1000
      • When x is in BNSD format, cos and sin support 11SD, B1SD, and BNSD.
        • B * N <= S * 8
      • When x is BSND, cos and sin support 1S1D, BS1D, and BSND.
        • (N - 1) * D * BytePerData / 32 < UINT16_MAX. When the input data type is FLOAT16, the value is 2. When the input data type is FLOAT32, the value is 4.
      • When x is SBND, cos and sin support S11D, SB1D, and SBND.
        • (B * N - 1) * D * BytePerData / 32 < UINT16_MAX. When the input data type is FLOAT16, the value is 2. When the input data type is FLOAT32, the value is 4.
      • When x is TND, cos and sin support T1D and TND.
[object Object]

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

[object Object]