FilesLast commitLast update
5 months ago
3 months ago
17 days ago
17 days ago
17 days ago
17 days ago
18 days ago
1 month ago
11 days ago
README

AtanGrad

English | 简体中文

Product Support Status

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

Function Description

  • Operator function: computes the input gradient of the arctangent function (atan), which is used for gradient passing in the backpropagation of neural networks.

  • Computation formula (the naming is consistent with op_graph/atan_grad_proto.h):

    zi=dyi×11+yi2z_i = dy_i \times \frac{1}{1 + y_i^2}

    where yy is the input tensor of the forward computation (the independent variable of the atan function), dydy is the gradient tensor passed from upstream, and zz is the output input-gradient tensor.

  • Equivalent step-by-step computation (the NPU implementation uses Div instead of Reciprocal+Mul to avoid insufficient precision in INTRINSIC mode):

    1. ti=yi×yit_i = y_i \times y_i (computes y2y^2)
    2. gi=ti+1.0g_i = t_i + 1.0 (computes 1+y21 + y^2)
    3. zi=dyi/giz_i = dy_i / g_i (direct division, which is equivalent to dyi×(1/(1+y2))dy_i \times (1 / (1+y^2)))

Parameter Description

Parameter Name Input/Output Description Data Type Data Format
y Input The input tensor of the forward computation, which corresponds to y in the formula and is the independent variable of the atan function. FLOAT16, FLOAT, BFLOAT16 ND
dy Input The gradient tensor passed from upstream, which corresponds to dy in the formula. The data type must be exactly the same as that of y. FLOAT16, FLOAT, BFLOAT16 ND
z Output The output input-gradient tensor, which corresponds to z in the formula. The data type must be exactly the same as that of y. FLOAT16, FLOAT, BFLOAT16 ND

Constraint Description

  • The data types of y, dy, and z must be exactly the same. Implicit type conversion is not supported.
  • The shapes of y, dy, and z must be exactly the same. Broadcasting is not supported.
  • Supports empty Tensors (with 0 elements).
  • Supports Tensors of 0 to 8 dimensions. Dimension 0 indicates a scalar, and in this case dy and z must also be 0-dimensional.
  • When the value of y is extremely large (for example, the maximum value of fp16), y2y^2 may overflow to inf. In this case, 1/inf=01/\text{inf}=0, z=0, which is normal numerical behavior.
  • For FP16/BF16 inputs: the NPU kernel uses the Cast mode of FP16/BF16 → FP32 intermediate computation → FP16/BF16 (the default implementation convention of CANN kernels). For FP32 inputs: the computation is directly performed in FP32.

Invocation Description

Invocation Method Sample Code Description
Graph mode test_geir_atan_grad.cpp Invokes the AtanGrad operator through the graph mode.