Function: performs LSTM backpropagation and calculates the gradients of the forward input, weight parameters, and initial state hx.
Formula:
[object Object][object Object][object Object]undefined
Where:
- is the sigmoid function.
- indicates element-wise multiplication (Hadamard product).
- is a learnable weight matrix.
- is a learnable bias term.[object Object]
- Total loss:
- Gradient of the hidden state:
- Gradient of the cell state: [object Object]
- Initialization
Loop from to
- Gradient of the current hidden state
- Gradient of the current cell state
- Calculation of the gating gradient
- Parameter gradient accumulation
- Propagation to the previous moment
- Update communication variables
Derivation of cell state gradient
Where:
Derivation of the forget gate gradient
Derivation of the parameter gradient
Gradient flow characteristics of LSTM
Long-range dependency handling
- : hidden state of layer (, where is the total number of layers)
- : loss function
- : gradient of the loss function with respect to the hidden state of layer
Core propagation formula
The gradient is propagated from the top layer () to the bottom layer (), and the inter-layer relationship is given by the chain rule:
Where:
- : gradient of the current layer l (obtained from the previous layer through backpropagation)
- : Jacobian matrix of the hidden state of layer l with respect to the hidden state of layer l-1
- : matrix multiplication (gradient propagation is essentially vector-matrix multiplication)
That is, the gradient dx of the output of each layer is the gradient dy of the input of the previous layer.
[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.
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]
Deterministic computation:
- The aclnnLstmBackward function 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].
The following example is for reference only. For details, see .