FilesLast commitLast update
13 days ago
4 months ago
24 days ago
2 months ago
23 days ago
1 month ago
2 months ago
23 days ago
13 days ago
13 days ago
README

Softshrink

English | 简体中文

Applicable Products

Product Support
Ascend 950PR&950DT products √
Atlas A3 products √
Atlas A2 products √
Atlas 200I/500 A2 inference products ×
Atlas inference products √
Atlas training products √

Notes:

  • Ascend 950PR/950DT is provided by the Ascend C implementation in this repository; Atlas A3/A2 and Atlas inference/training products are provided by the canndev TBE implementation. Atlas 200I/500 A2 has no corresponding binary configuration and is not supported.
  • Ascend 950PR/950DT, Atlas A3, and Atlas A2 support FLOAT, FLOAT16, and BFLOAT16. Atlas inference/training products support only FLOAT and FLOAT16, not BFLOAT16.

Function

  • Operator function: Apply the Softshrink activation function to the input tensor.

  • Formula:

Softshrink(x)={x−λ,ifx>λx+λ,ifx<−λ0,otherwiseSoftshrink(x)=\begin{cases} x-λ, if x > λ \\ x+λ, if x < -λ \\ 0, otherwise \\ \end{cases}

Parameters

Parameter name Input/Output/Attribute Description Data type Data format
input_x Input Input tensor for the Softshrink computation, x in the formula. fp16, fp32, bf16 ND
output_y Output Output tensor of the Softshrink computation. Its shape is the same as that of input_x. fp16, fp32, bf16 ND
lambd Attribute Threshold parameter of Softshrink, λ in the formula. Default value: 0.5. NaN and negative values are rejected as invalid parameters; +Inf is allowed. FLOAT -

Constraints

  • Only the ND data format is supported.
  • The dtype of input_x is fp16/fp32/bf16, and output_y has the same dtype as input_x. Atlas inference/training products do not support BF16 and support only FLOAT and FLOAT16.
  • Inputs of any rank are supported (0D to 8D). A 0D scalar input is processed as a 1D tensor with shape (1,).
  • lambd must be a FLOAT scalar in the range [0, +∞): 0, positive values, and +Inf are allowed; negative values and NaN return an invalid-parameter error.
  • In the Ascend C implementation in this repository, when input_x is NaN, the output is 0. NaN is not propagated; callers that rely on NaN propagation should note this difference.
  • Empty tensors (with 0 elements) are supported, and an empty output of the same shape is directly returned.
  • Dynamic shapes (including -1 dimensions) are supported: tiling computes the split based on the actual shape at runtime, without recompilation.
  • Deterministic implementation by default: the same input always produces the same output.

Invocation Description

Invocation method Sample code Description
aclnn API test_aclnn_softshrink.cpp Invoke the Softshrink operator through the aclnnSoftshrink API.
GE graph mode softshrink_proto.h Invoke the Softshrink operator by constructing a graph with the operator IR.

For sample compilation and execution, see the aclnnSoftshrink sample and the CANN sample compilation and execution guide.