[object Object]

[object Object][object Object]undefined
[object Object]
  • Description: Perform the backward pass of the single-path rotary position encoding .

  • Formula:

    In the forward pass of rotary position encoding, the axis list for broadcasting is [object Object], and the computation formula can be expressed as follows:

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

    (1) Half mode (mode equals 0):

    dy1,dy2=chunk(dy,chunks=2,dim=1)dy1, dy2 = chunk(dy, chunks=2, dim=-1) cos1,cos2=chunk(cos,chunks=2,dim=1)cos1, cos2 = chunk(cos, chunks=2, dim=-1) sin1,sin2=chunk(sin,chunks=2,dim=1)sin1, sin2 = chunk(sin, chunks=2, dim=-1) x1,x2=chunk(x,chunks=2,dim=1)x1, x2 = chunk(x, chunks=2, dim=-1) dx=cat((cos1dy1+sin2dy2,cos2dy2sin1dy1),dim=1)dx = cat((cos1 * dy1 + sin2 * dy2, cos2 * dy2 - sin1 * dy1), dim=-1) dcos=sum(dyx,dims)dcos = sum(dy * x, dims) dsin=sum(dycat((x2,x1),dim=1),dims)dsin = sum(dy * cat((-x2, x1), dim=-1), dims)

    (2) Interleave mode (mode equals 1):

    dy1,dy2=dy[...,::2],dy[...,1::2]dy1, dy2 = dy[..., :: 2], dy[..., 1 :: 2] cos1,cos2=cos[...,::2],cos[...,1::2]cos1, cos2 = cos[..., :: 2], cos[..., 1 :: 2] sin1,sin2=sin[...,::2],sin[...,1::2]sin1, sin2 = sin[..., :: 2], sin[..., 1 :: 2] x1,x2=x[...,::2],x[...,1::2]x1, x2 = x[..., :: 2], x[..., 1 :: 2] dx=stack((cos1dy1+sin2dy2,cos2dy2sin1dy1),dim=1).reshape(dy.shape)dx = stack((cos1 * dy1 + sin2 * dy2, cos2 * dy2 - sin1 * dy1), dim=-1).reshape(dy.shape) dcos=sum(dyx,dims)dcos = sum(dy * x, dims) dsin=sum(dystack((x2,x1),dim=1).reshape(dy.shape),dims)dsin = sum(dy * stack((-x2, x1), dim=-1).reshape(dy.shape), dims)

    (3) Quarter mode (mode equals 2):

    dy1,dy2,dy3,dy4=chunk(dy,chunks=4,dim=1)dy1, dy2, dy3, dy4 = chunk(dy, chunks=4, dim=-1) cos1,cos2,cos3,cos4=chunk(cos,chunks=4,dim=1)cos1, cos2, cos3, cos4 = chunk(cos, chunks=4, dim=-1) sin1,sin2,sin3,sin4=chunk(sin,chunks=4,dim=1)sin1, sin2, sin3, sin4 = chunk(sin, chunks=4, dim=-1) x1,x2,x3,x4=chunk(x,chunks=4,dim=1)x1, x2, x3, x4 = chunk(x, chunks=4, dim=-1) dx=cat((cos1dy1+sin2dy2,cos2dy2sin1dy1,cos3dy3+sin4dy4,cos4dy4sin3dy3),dim=1)dx = cat((cos1 * dy1 + sin2 * dy2, cos2 * dy2 - sin1 * dy1, cos3 * dy3 + sin4 * dy4, cos4 * dy4 - sin3 * dy3), dim=-1) dcos=sum(dyx,dims)dcos = sum(dy * x, dims) dsin=sum(dycat((x2,x1,x4,x3),dim=1),dims)dsin = sum(dy * cat((-x2, x1, -x4, x3), dim=-1), dims)

    (4) Interleave-half mode (mode equals 3):

    dy1,dy2=chunk(dy,chunks=2,dim=1)dy1, dy2 = chunk(dy, chunks=2, dim=-1) cos1,cos2=chunk(cos,chunks=2,dim=1)cos1, cos2 = chunk(cos, chunks=2, dim=-1) sin1,sin2=chunk(sin,chunks=2,dim=1)sin1, sin2 = chunk(sin, chunks=2, dim=-1) x1,x2=x[...,::2],x[...,1::2]x1, x2 = x[..., :: 2], x[..., 1 :: 2] dx=stack((cos1dy1+sin2dy2,cos2dy2sin1dy1),dim=1).reshape(dy.shape)dx = stack((cos1 * dy1 + sin2 * dy2, cos2 * dy2 - sin1 * dy1), dim=-1).reshape(dy.shape) dcos=sum(dycat((x1,x2),dim=1),dims)dcos = sum(dy * cat((x1, x2), dim=-1), dims) dsin=sum(dycat((x2,x1),dim=1),dims)dsin = sum(dy * cat((-x2, x1), dim=-1), dims)
[object Object]

Each operator has calls. First call [object Object] to obtain the input parameters and calculate the required workspace size according to the process, and then call [object Object] to perform the computation.

[object Object]
[object Object]
[object Object]
  • Parameters

    [object Object]
    • Parameter mode constraints:
      • [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]: 0=half, 1=interleave.
  • 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 deterministic implementation.

    • [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 [object Object] supports BNSD, BSND, SBND, and TND layouts.
      • The D dimensions of the input tensors [object Object], [object Object], [object Object], [object Object], and the output tensors [object Object], [object Object], [object Object] must be the same, satisfy D < 896, and must be a multiple of 2.
      • The shapes of the input tensors [object Object], [object Object], and the output tensor [object Object] must be exactly the same.
      • The shapes of the input tensors [object Object], [object Object] and the output tensors [object Object], [object Object] must be exactly the same, and the shapes of [object Object] and [object Object] must also be exactly the same.
      • Half mode:
        • B, N < 1000; When calculating [object Object] and [object Object], B * N <= 1024.
        • When [object Object] is BNSD, [object Object] and [object Object] support 11SD, B1SD, and BNSD; when [object Object] and [object Object] are B1SD, the condition B < S must be satisfied.
        • When [object Object] is BSND, [object Object] and [object Object] support 1S1D, BS1D, BSND; when [object Object] and [object Object] are BS1D, B < S must be satisfied.
        • When [object Object] is SBND, [object Object] and [object Object] support S11D, SB1D, SBND.
        • When [object Object] is TND, [object Object] and [object Object] support T1D and TND.
      • Interleave mode:
        • B * N < 1000 (N < 1000 when [object Object] is TND).
        • When [object Object] is BNSD, [object Object] and [object Object] support 11SD.
        • When [object Object] is BSND, [object Object] and [object Object] support 1S1D.
        • When [object Object] is SBND, [object Object] and [object Object] support S11D.
        • When [object Object] is TND, [object Object] and [object Object] support T1D.
[object Object]

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

[object Object]