[object Object]

[object Object][object Object]undefined
[object Object]
  • Description: Serves as a clipped Swish-gated linear unit (SwiGLU) activation function that computes the clipped SwiGLU of input tensor x. Compared with aclnnSwiGlu, this API introduces additional parameters — groupIndex, alpha, limit, bias, and interleaved — to support the SwiGLU variant used in GPT-OSS models and grouped scenarios in MoE models.

  • Formula:

    For a given input tensor x with shape [a,b,c,d,e,f,g…], aclnnClippedSwiglu performs the following operations:

    1. The x is combined along the axis specified by the input parameter dim. The dimension after combination is [pre, cut, after]. The [object Object] axis represents the axis that needs to be split into two tensors, following either front-back splitting or odd-even splitting. The dimensions of [object Object] and [object Object] can equal 1. For example, when dim is 3, the dimension of x after combination is [abc, d, efg*...]. Since elements along the after axis are contiguous and operations are element-wise, the cut and after axes are further merged, resulting in a final shape of [pre,cut].

    2. Filter the pre axis of x based on the input parameter group_index using the following formula:

      sum=Sum(group_index)sum = \text{Sum}(group\_index) x=x[:sum,:]x = x[ : sum, : ]

      Where sum is the sum of all elements in group_index. This step is skipped when group_index is not provided.

    3. Split x based on the input parameter interleaved using the following formula:

      When interleaved is set to true, it indicates odd-even split:

      A=x[:,::2]A = x[ : , : : 2] B=x[:,1::2]B = x[ : , 1 : : 2]

      When interleaved is set to false, it indicates front-back split:

      h=x.shape[1]//2h = x.shape[1] // 2 A=x[:,:h]A = x[ : , : h] B=x[:,h:]B = x[ : , h : ]
    4. Compute the clipped SwiGLU variant based on the input parameters alpha, limit, and bias using the following formula:

      A=A.clamp(min=None,max=limit)A = A.clamp(min=None, max=limit) B=B.clamp(min=limit,max=limit)B = B.clamp(min=-limit, max=limit) y_glu=Asigmoid(alphaA)y\_glu = A * sigmoid(alpha * A) y=y_glu(B+bias)y = y\_glu * (B + bias)
    5. Reshape the output tensor y to match the original number of dimensions of x. The size along the dim axis is half that of x, while all other dimensions remain the same as x.

[object Object]

Each operator has calls. First, aclnnClippedSwigluGetWorkspaceSize is called to obtain the workspace size required for computation and the executor that contains the operator computation flow. Then, aclnnClippedSwiglu 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: aclnnClippedSwiglu defaults to a deterministic implementation. The non-deterministic implementation is not supported, and configuration changes via deterministic computation settings will not take effect.

[object Object]

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

[object Object]