xLSTM: Extended Long Short-Term Memory β part 28/30
Cleaned-text code points [407558, 423526). Bibliography omitted here; source.md includes it.
Ξ΄ π ~ t \displaystyle\delta_{\tilde{\bm{h}}_{t}} = π¨ t β Ξ΄ π t ext \displaystyle=\mathbf{o}_{t}\odot\delta_{\bm{h}_{t}}^{\text{ext}} (59) Ξ΄ πͺ t β 1 β€ \displaystyle\delta_{\bm{C}_{t-1}}^{\top} = f t β Ξ΄ πͺ t β€ + π t β 1 β Ξ΄ π ~ t β 1 β€ max β‘ { | π t β 1 β€ β π t β 1 | , 1 } \displaystyle=\mathrm{f}_{t}\delta_{\bm{C}_{t}}^{\top}+\frac{\bm{q}_{t-1}\delta_{\tilde{\bm{h}}_{t-1}}^{\top}}{\max\left\{{{\left|\bm{n}_{t-1}^{\top}\bm{q}_{t-1}\right|}},1\right\}} (60) Ξ΄ π t β 1 \displaystyle\delta_{\bm{n}_{t-1}} = f t β Ξ΄ π t β π t β 1 β€ β πͺ t β 1 β€ β Ξ΄ π‘ ~ t β 1 max β‘ { | π t β 1 β€ β π t β 1 | , 1 } 2 β Ξ© β ( π t β 1 β€ β π t β 1 ) β π t β 1 \displaystyle=\mathrm{f}_{t}\delta_{\bm{n}_{t}}-\frac{\bm{q}_{t-1}^{\top}\bm{C}_{t-1}^{\top}\delta_{\tilde{\mathbf{h}}_{t-1}}}{\max\left\{{{\left|\bm{n}_{t-1}^{\top}\bm{q}_{t-1}\right|}},1\right\}^{2}}\Omega\left(\bm{n}_{t-1}^{\top}\bm{q}_{t-1}\right)\bm{q}_{t-1} (61) Ξ΄ π t β€ \displaystyle\delta_{\bm{v}_{t}}^{\top} = i t β π t β€ β Ξ΄ πͺ t β€ \displaystyle=\mathrm{i}_{t}\bm{k}_{t}^{\top}\delta_{\bm{C}_{t}}^{\top} (62) Ξ΄ π t β€ \displaystyle\delta_{\bm{k}_{t}}^{\top} = i t β ( π t β€ β Ξ΄ πͺ t + Ξ΄ π t β€ ) \displaystyle=\mathrm{i}_{t}\left(\bm{v}_{t}^{\top}\delta_{\bm{C}_{t}}+\delta_{\bm{n}_{t}}^{\top}\right) (63) Ξ΄ π t \displaystyle\delta_{\bm{q}_{t}} = πͺ t β€ β Ξ΄ π ~ t max β‘ { | π t β€ β π t | , 1 } β π t β€ β πͺ t β€ β Ξ΄ π ~ t max β‘ { | π t β€ β π t | , 1 } 2 β Ξ© β ( π t β€ β π t ) β π t \displaystyle=\frac{\bm{C}_{t}^{\top}\delta_{\tilde{\bm{h}}_{t}}}{\max\left\{{{\left|\bm{n}_{t}^{\top}\bm{q}_{t}\right|}},1\right\}}-\frac{\bm{q}_{t}^{\top}\bm{C}_{t}^{\top}\delta_{\tilde{\bm{h}}_{t}}}{\max\left\{{{\left|\bm{n}_{t}^{\top}\bm{q}_{t}\right|}},1\right\}^{2}}\Omega\left(\bm{n}_{t}^{\top}\bm{q}_{t}\right)\bm{n}_{t} (64) Ξ΄ π t \displaystyle\delta_{\bm{x}_{t}} = β g β { q , k , v } πΎ g β€ β Ξ΄ π t \displaystyle=\sum_{g\in\{q,k,v\}}\bm{W}^{\top}_{g}\delta_{\bm{g}_{t}} (65) Ξ΄ πΎ g β€ \displaystyle\delta_{\bm{W}_{g}}^{\top} = β t π t β Ξ΄ π t β€ , \displaystyle=\sum_{t}\bm{x}_{t}\delta_{\bm{g}_{t}}^{\top}\ , g β { q , k , v } \displaystyle g\in\{q,k,v\} (66) Ξ΄ π g \displaystyle\delta_{\bm{b}_{g}} = β t Ξ΄ π t , \displaystyle=\sum_{t}\delta_{\bm{g}_{t}}\ , g β { q , k , v } \displaystyle g\in\{q,k,v\} (67) Ξ΄ f ~ t \displaystyle\delta_{\tilde{\mathrm{f}}_{t}} = ( π β€ β ( πͺ t β 1 β Ξ΄ πͺ t ) β π + π β€ β ( π t β 1 β Ξ΄ π t ) ) β Ξ³ β ( f ~ t ) \displaystyle=\left(\bm{1}^{\top}\left(\bm{C}_{t-1}\odot\delta_{\bm{C}_{t}}\right)\bm{1}+\bm{1}^{\top}\left(\bm{n}_{t-1}\odot\delta_{\bm{n}_{t}}\right)\right)\gamma\left(\tilde{\mathrm{f}}_{t}\right) (68) Ξ΄ π’ ~ t \displaystyle\delta_{\tilde{\mathbf{i}}_{t}} = ( π β€ β ( ( π t β π t β€ ) β Ξ΄ πͺ t ) β π + π β€ β ( π t β Ξ΄ π t ) ) β exp β‘ ( i ~ t ) \displaystyle=\left(\bm{1}^{\top}\left(\left(\bm{v}_{t}\bm{k}^{\top}_{t}\right)\odot\delta_{\bm{C}_{t}}\right)\bm{1}+\bm{1}^{\top}\left(\bm{k}_{t}\odot\delta_{\bm{n}_{t}}\right)\right)\exp\left(\tilde{\mathrm{i}}_{t}\right) (69) Ξ΄ π¨ ~ t \displaystyle\delta_{\tilde{\mathbf{o}}_{t}} = π ~ t β Ο β² β ( o ~ t ) β Ξ΄ π t \displaystyle=\tilde{\bm{h}}_{t}\odot\sigma^{\prime}\left(\tilde{\mathrm{o}}_{t}\right)\odot\delta_{\bm{h}_{t}} (70)
and Ξ© β‘ ( z ) = Ξ β‘ ( z β 1 ) β Ξ β‘ ( β z β 1 ) \Omega\left(z\right)=\Theta\left(z-1\right)-\Theta\left(-z-1\right) , Ξ β‘ ( z ) \Theta\left(z\right) being the Heaviside step function. Ξ³ β‘ ( z ) \gamma\left(z\right) is either Ο β² β ( z ) \sigma^{\prime}\left(z\right) or exp β‘ ( z ) \exp\left(z\right) , depending on the forget gate activation.
##### Parallel mLSTM Forward Pass.
The mLSTM recurrence in Equations ( 19 - 27 ) can be reformulated in a parallel form, which is used to speed up training. After training we can still use the recurrent formulation for fast text generation.
Instead of processing each input π t β β d \bm{x}_{t}\in\mathbb{R}^{d} at time step t t sequentially, the parallel version processes all timesteps of a full sequence πΏ β β T Γ d \bm{X}\in\mathbb{R}^{T\times d} at once, where T T is the sequence length and d d is the head dimension. We present the forward pass of the mLSTM for a single head and drop the head dimension for simplicity.
Let π ~ β β T \tilde{\bm{\mathrm{f}}}\in\mathbb{R}^{T} be the forget gate pre-activations and π’ ~ β β T \tilde{\bm{\mathrm{i}}}\in\mathbb{R}^{T} be the input gate pre-activations for a full sequence. We construct the forget gate activation matrix π
β β T Γ T \bm{\mathrm{F}}\in\mathbb{R}^{T\times T} by π
i β j = { 0 for β i < j 1 for β i = j β k = j + 1 i Ο β‘ ( f ~ k ) for β i > j , \bm{\mathrm{F}}_{ij}=\begin{cases}0&\text{for}\;i<j\\ 1&\text{for}\;i=j\\ \prod_{k=j+1}^{i}\sigma\left(\tilde{\mathrm{f}}_{k}\right)&\text{for}\;i>j\end{cases}\ , (71) and the input gate pre-activation matrix π ~ β β T Γ T \tilde{\bm{\mathrm{I}}}\in\mathbb{R}^{T\times T} by π ~ i β j = { 0 for β i < j i ~ j for β i β©Ύ j . \tilde{\bm{\mathrm{I}}}_{ij}=\begin{cases}0&\text{for}\;i<j\\ \tilde{\mathrm{i}}_{j}&\text{for}\;i\geqslant j\end{cases}\ . (72)
By applying the elementwise exponential input gate activation function naively, we obtain the unstabilized gate activation matrix π β β T Γ T \bm{\mathrm{D}}\in\mathbb{R}^{T\times T} as π = π
β exp β‘ ( π ~ ) . \bm{\mathrm{D}}=\bm{\mathrm{F}}\odot\exp(\tilde{\bm{\mathrm{I}}})\ . (73)
In order to avoid overflow due to the exponential function we apply the same stabilization as in the recurrent sLSTM, see Equation 15 . In the parallel formulation of the mLSTM we get a numerically stable gate activation matrix π β² β β T Γ T \bm{\mathrm{D}}^{\prime}\in\mathbb{R}^{T\times T} by taking the logarithm of π \bm{\mathrm{D}} element-wise and subtracting the row-wise maximum value of π \bm{\mathrm{D}} from each element: π ~ \displaystyle\widetilde{\bm{\mathrm{D}}} = log β‘ π = log β‘ ( π
β exp β‘ ( π ~ ) ) = log β‘ π
+ π ~ \displaystyle=\log\bm{\mathrm{D}}=\log\left(\bm{\mathrm{F}}\odot\exp(\tilde{\bm{\mathrm{I}}})\right)=\log\bm{\mathrm{F}}+\tilde{\bm{\mathrm{I}}} (74) π β² \displaystyle\bm{\mathrm{D}}^{\prime} = exp β‘ ( π ~ β max β‘ π ~ ) \displaystyle=\exp(\widetilde{\bm{\mathrm{D}}}-\max\widetilde{\bm{\mathrm{D}}}) (75)
Given the queries, keys and values πΈ , π² , π½ β β T Γ d \bm{Q},\bm{K},\bm{V}\in\mathbb{R}^{T\times d} , for a full sequence we can compute all hidden pre-activation states π ~ β β T Γ d \widetilde{\bm{\mathrm{H}}}\in\mathbb{R}^{T\times d} in parallel for the un-stabilized version by π ~ = πͺ β π½ , with β πͺ = πͺ ~ max β‘ ( | β j = 1 T πͺ ~ i β j | , 1 ) , and β πͺ ~ = πΈ β π² β€ d β π . \widetilde{\bm{\mathrm{H}}}=\bm{C}\,\bm{V}\ ,\quad\text{with}\,\,\,\bm{C}=\frac{\widetilde{\bm{C}}}{\max\left(|\sum_{j=1}^{T}\widetilde{\bm{C}}_{ij}|,1\right)}\ ,\quad\text{and}\,\,\,\widetilde{\bm{C}}=\frac{\bm{Q}\bm{K}^{\top}}{\sqrt{d}}\odot\bm{\mathrm{D}}\ . (76) Note that we extract the 1 d \frac{1}{\sqrt{d}} factor for π² \bm{K} explicitly here and further on. For the stabilized version this yields π ~ = πͺ β π½ , with β πͺ = πͺ ~ β² max β‘ ( | β j = 1 T πͺ ~ i β j β² | , exp β‘ ( β max β‘ π ~ ) ) , and β πͺ ~ β² = πΈ β π² β€ d β π β² , \widetilde{\bm{\mathrm{H}}}=\bm{C}\,\bm{V}\ ,\quad\text{with}\,\,\,\bm{C}=\frac{\widetilde{\bm{C}}^{\prime}}{\max\left(|\sum_{j=1}^{T}\widetilde{\bm{C}}^{\prime}_{ij}|,\exp(-\max\widetilde{\bm{\mathrm{D}}})\right)}\ ,\quad\text{and}\,\,\,\widetilde{\bm{C}}^{\prime}=\frac{\bm{Q}\bm{K}^{\top}}{\sqrt{d}}\odot\bm{\mathrm{D}}^{\prime}\ , (77) where for both versions the hidden pre-activation states π ~ \widetilde{\bm{\mathrm{H}}} are identical.
With the output gate pre-activations π ~ β β T Γ d \widetilde{\bm{\mathrm{O}}}\in\mathbb{R}^{T\times d} we can compute the hidden states π― β β T Γ d \bm{H}\in\mathbb{R}^{T\times d} for all timesteps by applying the output gate in parallel for each timestep element-wise: π = Ο β‘ ( π ~ ) β π ~ . \bm{\mathrm{H}}=\sigma(\widetilde{\bm{\mathrm{O}}})\odot\widetilde{\bm{\mathrm{H}}}\ . (78)
This gives the parallel forward pass of the mLSTM for a full input sequence πΏ β β T Γ d \bm{X}\in\mathbb{R}^{T\times d} .
##### Parallel mLSTM Backward Pass.
We present the backward pass of the mLSTM for the stabilized version only. For completeness we summarize the forward pass in the stabilized version before we present the backward pass.
Given the forget gate matrix π
β β T Γ T \bm{\mathrm{F}}\in\mathbb{R}^{T\times T} , the logarithm of the forget gate matrix π
Β― = log β‘ π
β β T Γ T \overline{\bm{\mathrm{F}}}=\log\bm{\mathrm{F}}\in\mathbb{R}^{T\times T} , and the input gate matrix π β β T Γ T \bm{\mathrm{I}}\in\mathbb{R}^{T\times T} as introduced above, together with the queries, keys and values πΈ , π² , π½ β β T Γ d \bm{Q},\bm{K},\bm{V}\in\mathbb{R}^{T\times d} , we can write the forward pass of the mLSTM in the stabilized version as: π ~ \displaystyle\widetilde{\bm{\mathrm{D}}} = π
Β― + π ~ \displaystyle=\overline{\bm{\mathrm{F}}}+\tilde{\bm{\mathrm{I}}} (79) π \displaystyle\bm{m} = max j β‘ π ~ i β j , \displaystyle=\max_{j}\widetilde{\bm{\mathrm{D}}}_{ij}\ ,\quad row-wise maximum (80) π β² \displaystyle\bm{\mathrm{D}}^{\prime} = exp β‘ ( π ~ β π β 1 β€ ) \displaystyle=\exp(\widetilde{\bm{\mathrm{D}}}-\bm{m}\,\bm{1}^{\top}) (81) πͺ ~ β² \displaystyle\widetilde{\bm{C}}^{\prime} = πΈ β π² β€ d β π β² \displaystyle=\frac{\bm{Q}\bm{K}^{\top}}{\sqrt{d}}\odot\bm{\mathrm{D}}^{\prime} (82) π \displaystyle\bm{b} = β j = 1 T πͺ ~ i β j β² = πͺ ~ β² β 1 , \displaystyle=\sum_{j=1}^{T}\widetilde{\bm{C}}^{\prime}_{ij}=\widetilde{\bm{C}}^{\prime}\ \bm{1}\ ,\quad row-wise sum (83) π \displaystyle\bm{n} = max β‘ ( | π | , exp β‘ ( β π ) ) \displaystyle=\max\left(|\bm{b}|,\exp(-\bm{m})\right) (84) πͺ \displaystyle\bm{C} = πͺ ~ β² β ( π β 1 β 1 β€ ) \displaystyle=\widetilde{\bm{C}}^{\prime}\odot\left(\bm{n}^{-1}\ \bm{1}^{\top}\right) (85) π ~ \displaystyle\widetilde{\bm{\mathrm{H}}} = πͺ β π½ \displaystyle=\bm{C}\ \bm{V} (86)
With this forward pass we can compute the gradients Ξ΄ a \delta_{a} for all intermediate and input variables to the mLSTM forward pass in the backward pass. We denote the gradient with respect to variable a a as Ξ΄ a \delta_{a} .
Given the output gradient Ξ΄ π ~ β β T Γ d \delta_{\widetilde{\bm{\mathrm{H}}}}\in\mathbb{R}^{T\times d} we can compute the backward pass for the intermediate gradients as: Ξ΄ πͺ β€ \displaystyle\delta_{\bm{C}}^{\top} = π½ β Ξ΄ π ~ β€ \displaystyle=\bm{V}\delta_{\widetilde{\bm{\mathrm{H}}}}^{\top} (87) Ξ΄ π \displaystyle\delta_{\bm{n}} = β ( πͺ ~ β² β ( π β 2 β 1 β€ ) β Ξ΄ πͺ ) β 1 \displaystyle=-\left(\widetilde{\bm{C}}^{\prime}\odot\left(\bm{n}^{-2}\ \bm{1}^{\top}\right)\odot\delta_{\bm{C}}\right)\ \bm{1} (88) = β ( ( πͺ ~ β² β Ξ΄ πͺ ) π ) β π β 2 \displaystyle=-\left(\left(\widetilde{\bm{C}}^{\prime}\odot\delta_{\bm{C}}\right)\bm{1}\right)\odot\bm{n}^{-2} (89) Ξ΄ π \displaystyle\delta_{\bm{b}} = sign β ( π ) β Ξ΄ π β { 1 if β | π | > exp β‘ ( β π¦ ) 0 otherwise \displaystyle=\mbox{sign}\left(\bm{n}\right)\odot\delta_{\bm{n}}\odot\begin{cases}1&\text{if}\;|\bm{b}|>\exp(-\bm{\mathrm{m}})\\ 0&\text{otherwise}\end{cases} (90) Ξ΄ πͺ ~ β² , πͺ \displaystyle\delta_{\widetilde{\bm{C}}^{\prime},\bm{C}} = ( π β 1 β 1 β€ ) β Ξ΄ πͺ , \displaystyle=\left(\bm{n}^{-1}\ \bm{1}^{\top}\right)\odot\delta_{\bm{C}}\ ,\quad column-wise broadcast (91) Ξ΄ πͺ ~ β² , π β€ \displaystyle\delta_{\widetilde{\bm{C}}^{\prime},\bm{b}}^{\top} = π β Ξ΄ π β€ , \displaystyle=\bm{1}\ \delta_{\bm{b}}^{\top}\ ,\quad column-wise broadcast (92) Ξ΄ πͺ ~ β² \displaystyle\delta_{\widetilde{\bm{C}}^{\prime}} = Ξ΄ πͺ ~ β² , πͺ + Ξ΄ πͺ ~ β² , π© \displaystyle=\delta_{\widetilde{\bm{C}}^{\prime},\bm{C}}+\delta_{\widetilde{\bm{C}}^{\prime},\bm{B}} (93) Ξ΄ π β² \displaystyle\delta_{\bm{\mathrm{D}}^{\prime}} = πΈ β π² β€ d β Ξ΄ πͺ ~ β² \displaystyle=\frac{\bm{Q}\bm{K}^{\top}}{\sqrt{d}}\odot\delta_{\widetilde{\bm{C}}^{\prime}} (94) Ξ΄ π ~ \displaystyle\delta_{\widetilde{\bm{\mathrm{D}}}} = exp β‘ ( π ~ β π ) β Ξ΄ π β² = π β² β Ξ΄ π β² \displaystyle=\exp(\widetilde{\bm{\mathrm{D}}}-\bm{m})\odot\delta_{\bm{\mathrm{D}}^{\prime}}=\bm{\mathrm{D}}^{\prime}\odot\delta_{\bm{\mathrm{D}}^{\prime}} (95) We do not compute the gradients for π \bm{m} as they cancel out (see the proof in the recurrent sLSTM).
With these intermediate gradients the gradients for the logarithmic forget gate matrix Ξ΄ π
Β― β β T Γ T \delta_{\overline{\bm{\mathrm{F}}}}\in\mathbb{R}^{T\times T} , the input gate matrix Ξ΄ π β β T Γ T \delta_{\bm{\mathrm{I}}}\in\mathbb{R}^{T\times T} , and the queries, keys and values Ξ΄ πΈ , Ξ΄ π² , Ξ΄ π½ β β T Γ d \delta_{\bm{Q}},\delta_{\bm{K}},\delta_{\bm{V}}\in\mathbb{R}^{T\times d} are given by Ξ΄ π
Β― \displaystyle\delta_{\overline{\bm{\mathrm{F}}}} = Ξ΄ π ~ \displaystyle=\delta_{\widetilde{\bm{\mathrm{D}}}} (96) Ξ΄ π \displaystyle\delta_{\bm{\mathrm{I}}} = Ξ΄ π ~ \displaystyle=\delta_{\widetilde{\bm{\mathrm{D}}}} (97) Ξ΄ πΈ \displaystyle\delta_{\bm{Q}} = ( π β² β Ξ΄ πͺ ~ β² ) β π² d \displaystyle=\left(\bm{\mathrm{D}}^{\prime}\odot\delta_{\widetilde{\bm{C}}^{\prime}}\right)\frac{\bm{K}}{\sqrt{d}} (98) Ξ΄ π² \displaystyle\delta_{\bm{K}} = ( π β² β Ξ΄ πͺ ~ β² ) β€ β πΈ d \displaystyle=\left(\bm{\mathrm{D}}^{\prime}\odot\delta_{\widetilde{\bm{C}}^{\prime}}\right)^{\top}\frac{\bm{Q}}{\sqrt{d}} (99) Ξ΄ π½ \displaystyle\delta_{\bm{V}} = πͺ β€ β Ξ΄ π ~ \displaystyle=\bm{C}^{\top}\delta_{\widetilde{\bm{\mathrm{H}}}} (100)
Having computed the gradients for the logarithmic forget gate matrix Ξ΄ π
Β― \delta_{\overline{\bm{\mathrm{F}}}} , we can compute the gradients for the forget gate pre-activations Ξ΄ π ~ = [ Ξ΄ f ~ 1 , Ξ΄ f ~ 2 , β¦ , Ξ΄ f ~ T ] β€ β β T \delta_{\tilde{\bm{\mathrm{f}}}}=\left[\delta_{\tilde{\mathrm{f}}_{1}},\delta_{\tilde{\mathrm{f}}_{2}},...,\delta_{\tilde{\mathrm{f}}_{T}}\right]^{\top}\in\mathbb{R}^{T} .
Recall the logarithmic forget gate matrix π
Β― = log β‘ π
\overline{\bm{\mathrm{F}}}=\log\bm{\mathrm{F}} is computed by π
Β― i β j = log π
i β j = { β β for β i < j 0 for β i = j β k = j + 1 i log β‘ Ο β‘ ( f ~ k ) β = : f Β― k = β k = j + 1 i f Β― k for β i > j . \overline{\bm{\mathrm{F}}}_{ij}=\log\bm{\mathrm{F}}_{ij}=\begin{cases}-\infty&\text{for}\;i<j\\ 0&\text{for}\;i=j\\ \sum_{k=j+1}^{i}\underbrace{\log\sigma\left(\tilde{\mathrm{f}}_{k}\right)}_{=:\overline{\mathrm{f}}_{k}}=\sum_{k=j+1}^{i}\overline{\mathrm{f}}_{k}&\text{for}\;i>j\end{cases}\ . (101)
With the substitution π Β― = log β‘ Ο β‘ ( π ~ ) \overline{\bm{\mathrm{f}}}=\log\sigma(\tilde{\bm{\mathrm{f}}}) we compute the gradients for the logarithmic forget gate activations Ξ΄ π Β― = [ Ξ΄ f Β― 1 , Ξ΄ f Β― 2 , β¦ , Ξ΄ f Β― T ] β€ β β T \delta_{\overline{\bm{\mathrm{f}}}}=\left[\delta_{\overline{\mathrm{f}}_{1}},\delta_{\overline{\mathrm{f}}_{2}},...,\delta_{\overline{\mathrm{f}}_{T}}\right]^{\top}\in\mathbb{R}^{T} as Ξ΄ f Β― k \displaystyle\delta_{\overline{\mathrm{f}}_{k}} = β j = 1 k β 1 β i = k T ( Ξ΄ π
Β― ) i β j , \displaystyle=\sum_{j=1}^{k-1}\sum_{i=k}^{T}\left(\delta_{\overline{\bm{\mathrm{F}}}}\right)_{ij}\ , (102) Ξ΄ f ~ k \displaystyle\delta_{\tilde{\mathrm{f}}_{k}} = Ο β‘ ( β f ~ k ) β
Ξ΄ f Β― k , \displaystyle=\sigma(-\ \tilde{\mathrm{f}}_{k})\cdot\delta_{\overline{\mathrm{f}}_{k}}\ , (103)
where the last equation makes use of the following: d d β x β ( log β‘ Ο β ( x ) ) = β ( 1 + exp ( β x ) ) β 1 β
exp ( β x ) β
( β 1 ) = exp β‘ ( β x ) 1 + exp β‘ ( β x ) = 1 1 + exp β‘ ( x ) = Ο β‘ ( β x ) \displaystyle\begin{split}\frac{\mathrm{d}}{\mathrm{d}x}\left(\log\sigma(x)\right)&=-\left(1+\exp(-x)\right)^{-1}\cdot\exp(-x)\cdot(-1)\\ &=\frac{\exp(-x)}{1+\exp(-x)}=\frac{1}{1+\exp(x)}\\ &=\sigma(-x)\end{split} (104)
Finally, we compute the input gate pre-activationsβ gradients Ξ΄ π’ ~ = [ Ξ΄ i ~ 1 , Ξ΄ i ~ 2 , β¦ , Ξ΄ i ~ S ] β€ β β T \delta_{\tilde{\bm{\mathrm{i}}}}=\left[\delta_{\tilde{\mathrm{i}}_{1}},\delta_{\tilde{\mathrm{i}}_{2}},...,\delta_{\tilde{\mathrm{i}}_{S}}\right]^{\top}\in\mathbb{R}^{T} as the column-wise sum over the rows of the input gate matrix Ξ΄ π \delta_{\bm{\mathrm{I}}} : Ξ΄ i ~ k \displaystyle\delta_{\tilde{\mathrm{i}}_{k}} = β i = k T ( Ξ΄ π ) i β k \displaystyle=\sum_{i=k}^{T}\left(\delta_{\bm{\mathrm{I}}}\right)_{ik} (105)
This completes the backward pass of the parallel mLSTM for a full input sequence πΏ β β T Γ d \bm{X}\in\mathbb{R}^{T\times d} .