[object Object][object Object][object Object]undefined
[object Object]
  • Operator function: performs backpropagation of the remaining computation after matmul in the four gates of LSTMCell, and calculates the gradients of the input cx and bias b and the values of the four gates before activation (gates) in the forward output.
  • Formula:

Variable definition

  • Input gradients: δht\delta h_t ([object Object]) and δct\delta c_t ([object Object])
  • Forward cache: i,f,g,oi, f, g, o (activation values of each gate [object Object]), ct1c_{t-1} ([object Object]), and ctc_t ([object Object])
  • Output gradients: δai,δaf,δag,δao\delta a_i, \delta a_f, \delta a_g, \delta a_o (stored in [object Object]) and δct1\delta c_{t-1} ([object Object])

Phase 1: Intermediate gradient and status backpropagation

First, the contribution of the hidden state to the cell state is calculated, and the total gradient of the cell state at the current time point is obtained as follows: grad_ctotal\text{grad\_}c_{total}.

gcx=tanh(ct)grad_ctotal=δhto(1gcx2)+δctδct1=grad_ctotalf\begin{aligned} gcx &= \tanh(c_t) \\ \text{grad\_}c_{total} &= \delta h_t \cdot o \cdot (1 - gcx^2) + \delta c_t \\ \delta c_{t-1} &= \text{grad\_}c_{total} \cdot f \end{aligned}

Phase 2: Gating component gradient (pre-activation)

According to the code logic, the gradient δa\delta a of each gate before entering the activation function is calculated as follows:

δao=(δhtgcx)o(1o)δai=(grad_ctotalg)i(1i)δaf=(grad_ctotalct1)f(1f)δag=(grad_ctotali)(1g2)\begin{aligned} \delta a_o &= (\delta h_t \cdot gcx) \cdot o \cdot (1 - o) \\ \delta a_i &= (\text{grad\_}c_{total} \cdot g) \cdot i \cdot (1 - i) \\ \delta a_f &= (\text{grad\_}c_{total} \cdot c_{t-1}) \cdot f \cdot (1 - f) \\ \delta a_g &= (\text{grad\_}c_{total} \cdot i) \cdot (1 - g^2) \end{aligned}

Phase 3: Parameter gradient (db)

1. Bias gradient (db): Sum up the values in the batch dimension (NN).

δb=n=1N[δaiδafδagδao]n\delta b = \sum_{n=1}^{N} \begin{bmatrix} \delta a_i \\ \delta a_f \\ \delta a_g \\ \delta a_o \end{bmatrix}_n [object Object]

Each operator has calls. First, [object Object] is called to obtain the workspace size required for computation and the executor that contains the operator computation 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:
    • The aclnnThnnFusedLstmCellBackward is implemented in deterministic mode by default.
  • Boundary value scenarios:
    • If the input is Inf, the output is NAN.
    • When the input is [object Object], the output is [object Object].
[object Object]

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

[object Object]