[object Object]

[object Object][object Object]undefined
[object Object]
  • Description: Applies rotary positional encoding (RoPE) to a single input tensor [object Object].

  • Formulas:

    q=reshape(x,[B,N,S,D//2,2])transpose(1,2)reshape([B,N,S,D])q = \text{reshape}(x, [B, N, S, D//2, 2]) \cdot \text{transpose}(-1, -2) \cdot \text{reshape}([B, N, S, D]) qembed=qcos+RotateHalf(q)sinq_{\text{embed}} = q \cdot \text{cos} + \text{RotateHalf}(q) \cdot \sin

    RotateHalf(q) indicates that the elements in the second half of the D dimension of q are moved to the first half and multiplied by –1, and the second half is replaced by the values of the first half.

    RotateHalf(q)i={qi+D//2if i<D//2qi+D//2otherwise\text{RotateHalf}(q)_{\text{i}} = \begin{cases} -q_{i+D//2} & \text{if } i < D//2 \\ q_{i+D//2} & \text{otherwise} \end{cases}
[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 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:
    • [object Object] defaults to a deterministic implementation.
  • This API can be used in inference scenarios.
  • The x, cos, sin, and out must be 4D tensors with the shape of (B, N, S, D).
  • The S dimension of cos and sin can be 1 or the same as that of x. The N dimension must be 1.
  • The D dimension of x, cos, and sin must be 64.
[object Object]

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

[object Object]