Learning online the parameters of a Recurrent Neural Network (RNN) holds the promise of offering better sample complexity when compared to offline algorithms such as Backpropagation Through Time. We benefit from the stable parametrization of the Linear Recurrent Unit, to study the training dynamics of the Real Time Recurrent Learning (RTRL) algorithm in the class of linear RNNs. We show empirically and justify theoretically that RTRL benefits from highly stochastic online updates. From the insights we develop in the linear setting, we then study it’s implications in highly sparse Continuous Time Recurrent Neural Networks were we observe similar results. Overall, our findings allow us to offer a possible explanation for the phenomena observed by other researchers when training highly sparse RNNs with RTRL.

1 Online vs Offline

Let’s start by introducing the notation we’ll use throughout this post. We define the transition function as f ⁣:Θ×S×X→Sf \colon \Theta \times \mathcal{S} \times \mathcal{X} \to \mathcal{S}, where Θ\Theta denotes a finite dimensional vector space where the parameters live, S\mathcal{S} denotes the same for the hidden states and X\mathcal{X} as well for the inputs to the RNN. A single sequence of inputs will be defined as x1:T≔(x1,x2,⋯ ,xT)\mathbf{x}_{1:T} \coloneqq (x_1, x_2, \cdots, x_T) where TT denotes the end of the sequence. For when needed we define fθ≔f(θ,⋅,⋅)f_{\theta} \coloneqq f(\theta, \cdot, \cdot) and to further declutter notation given a fixed input xtx_t we define ft≔(⋅,⋅,xt)f_{t} \coloneqq (\cdot, \cdot, x_t). For a fixed parameter θ\theta, given an initial condition h0h_0, the sequence of hidden states produced by the network can be recursively defined as:

ht=f(θ,ht−1,xt)(1)\begin{aligned} h_t &=f\left(\theta, h_{t-1}, x_t\right) \end{aligned} \tag{1}

Under this formalism an RNN can be considered a non-autonomous discrete dynamical system.

In what follows we focus on gradient-based learning where the objective is to minimize at each time step tt, a cost function Lt ⁣:Θ→R\mathcal{L}_t \colon \Theta \to \mathbb{R} that measures the network's performance on a given task, as a function of the parameters θ\theta. Note that tt can be unbounded, but in this post we focus on the case where t≤Tt\leq T. This allows us to define a cumulative loss function:

L(θ)≔∑t=1TLt(θ)(2)\mathcal{L}\left(\theta\right) \coloneqq \sum_{t=1}^{T} \mathcal{L}_t\left(\theta\right) \tag{2}

that will measure the overall performance of the network.

In the Sparse Jacobians post, we introduced two different algorithms to compute the gradient dθL\mathrm{d}_{\theta}\mathcal{L}. Backpropagation Through Time (BPTT) and Real Time Recurrent Learning (RTRL). Both algorithms are equivalent, in the sense that they compute the same gradient dθL\mathrm{d}_{\theta}{\mathcal{L}}, the difference however relies on how this gradient is computed. BPTT computes the cumulative loss gradient in two passes, a first forward pass where the inputs xtx_t are processed, and a second backward pass where the gradients are computed. In contrast RTRL allows for comuting both in just a single pass, however this comes at a significant computational and memory cost as explained in the Sparse Jacobians post. More specifically RTRL computes each dθLt\mathrm{d}_{\theta}\mathcal{L}_t explicitly as the network runs, whereas BPTT will only compute them implicitly. To better illustrate this difference we can derive the gradient equations for both methods:

In RTRL: ∑t=1TdLtdθ=∑t=1TdLtdhtdhtdθ=∑t=1TdLtdht(∂ht∂ht−1dht−1dθ+∂ht∂θ)(RTRL)(3)\begin{aligned} \text{In RTRL: } \\ \sum_{t=1}^{T} \frac{\mathrm{d} \mathcal{L}_t}{\mathrm{d} \theta} &= \sum_{t=1}^{T} \frac{\mathrm{d} \mathcal{L}_t}{\mathrm{d} h_t}\frac{\mathrm{d} h_t}{\mathrm{d} \theta} \\ &= \sum_{t=1}^{T} \frac{\mathrm{d} \mathcal{L}_t}{\mathrm{d} h_t} \left(\frac{\partial h_t}{\partial h_{t-1}}\frac{\mathrm{d} h_{t-1}}{\mathrm{d} \theta} + \frac{\partial h_t}{\partial \theta}\right) && \text{(RTRL)} \end{aligned} \tag{3}
In BPTT: ∑t=1TdLtdθ=∑t=1T∑s=1t∂Lt∂hs∂hs∂θ(Paramater sharing)=∑s=1T(∑t≥sT∂Lt∂hs)∂hs∂θ(Exchange of summation)=∑s=1TdLdhs∂hs∂θ(Total derivative)=∑s=1T−1(dLdhs+1∂hs+1∂hs+dLsdhs)∂hs∂θ(BPTT)(4)\begin{aligned} \text{In BPTT: } \\ \sum_{t=1}^{T} \frac{\mathrm{d} \mathcal{L}_t}{\mathrm{d} \theta} & = \sum_{t=1}^{T} \sum_{s=1}^{t} \frac{\partial \mathcal{L}_t}{\partial h_s}\frac{\partial h_s}{\partial \theta} && \text{(Paramater sharing)} \\ &= \sum_{s=1}^{T} \left(\sum_{t\geq s}^{T}\frac{\partial \mathcal{L}_t}{\partial h_s}\right)\frac{\partial h_s}{\partial \theta} && \text{(Exchange of summation)} \\ &= \sum_{s=1}^{T} \frac{\mathrm{d} \mathcal{L}}{\mathrm{d} h_s}\frac{\partial h_s}{\partial \theta} && \text{(Total derivative)} \\ &= \sum_{s=1}^{T-1} \left(\frac{\mathrm{d} \mathcal{L}}{\mathrm{d} h_{s+1}} \frac{\partial h_{s+1}}{\partial h_s} + \frac{\mathrm{d} \mathcal{L}_s}{\mathrm{d} h_s}\right)\frac{\partial h_s}{\partial \theta} && \text{(BPTT)} \end{aligned} \tag{4}

after the exchange of summations in BPTT we are not computing dθL\mathrm{d}_{\theta}\mathcal{L} by adding each dθLt\mathrm{d}_{\theta}{\mathcal{L}_t}, but rather different terms. RTRL computes dθL\mathrm{d}_{\theta}\mathcal{L} by adding each dθLt\mathrm{d}_{\theta}\mathcal{L}_t explicitly as we process the inputs.

Being able to obtain the gradient of the instantenous loss dθLt\mathrm{d}_{\theta}\mathcal{L}_t as we process the inputs xtx_t is the core feature of RTRL. It allows the update of the parameters θ\theta in an online fashion, without having to neither accumulate the gradients nor wait until the sequence has been fully processed. This is what we refer as the online training setting, where numerous updates of the parameters θ\theta are performed as we process the inputs, in contrast to the offline training setting in which only one update of the parameters its performed at the end. Throughout the rest of this post to remove unnecessary wording we will refer to RTRL with online updates as the online algorithm, and to BPTT as the offline algorithm. A single online update of the parameters while processing an input will be refered as an in-sequence update, to better emphasize its nature.

To make the difference more clear between both training settings, we can make explicit the dependence of the parameters θ\theta on tt. In the offline setting we are not performing any update as we run the network, therefore we have θt=θ1\theta_t = \theta_1 for 1≤t≤T1 \leq t \leq T, whereas in the online setting in general we have θi≠θj\theta_i \neq \theta_j for 1≤i<j≤T1\leq i < j \leq T. We remark that this change of parameters as the network runs only happens while training, and when doing inference on a new input sequence the parameters are fixed for both methods1.

Online updates of the network parameters can exhibit different training dynamics when compared to their counterpart. This difference arises by noting that while in the offline setting:

dhtdθ(θ1)=∂ft∂h(ht−1)dht−1dθ(θ1)+∂ft∂θ(θ1)\frac{\mathrm{d} h_t}{\mathrm{d} \theta}\left(\theta_1\right) = \frac{\partial f_t}{\partial h}\left(h_{t-1}\right) \frac{\mathrm{d} h_{t-1}}{\mathrm{d} \theta}\left(\theta_1\right) + \frac{\partial f_t}{\partial \theta}\left(\theta_1\right)

in online setting we have:

dhtdθ(θt)=∂ft∂h(ht−1)dht−1dθ(θt−1)+∂ft∂θ(θt)\frac{\mathrm{d} h_t}{\mathrm{d} \theta}\left(\theta_t\right) = \frac{\partial f_t}{\partial h}\left(h_{t-1}\right) \frac{\mathrm{d} h_{t-1}}{\mathrm{d} \theta}\left(\theta_{t-1}\right) + \frac{\partial f_t}{\partial \theta}\left(\theta_{t}\right)

therefore, except for the first time step, in the online setting we are no longer computing the real Jacobian dθht\mathrm{d}_{\theta}h_t but a biased one, that will a priori better reflect the influence of the most recently used parameters {θt,θt−1,θt−2,… }\{\theta_t, \theta_{t-1}, \theta_{t-2}, \dots \} in comparison to the initial ones {θ1,θ2 … }\{\theta_1, \theta_2\, \dots\}. If we use gradient descent, this bias will imply that we are no longer following the precise negative gradient direction. The difference at each step is nevertheless O(ηt)\mathcal{O}(\eta_t), so one can mitigate this bias by reducing the learning rate. The bias of the dθht\mathrm{d}_{\theta}h_t when using online updates, was indeed noted by the original authors of RTRL [1]:

While the resulting algorithm is no longer guaranteed to follow the gradient of total error, the practical differences are often slight, with the two versions becoming more nearly identical as the learning rate is made smaller.

By making ηt\eta_t small we are potentially aligning more closely to BPTT training dynamics. Even in this small learning rate regime formally analyzing the online algorithm becomes substantially challenging since standard stochastic gradient descent theory does not apply directly, and to this date we could only find one work where they proved local converge of RTRL when the network parameters start within a radius close enough to a local minima [2].

Local converge itself will not really tell us much about the qualitative differences on the training dynamics when the network has just been initialized with random parameters. It is the purpose of this post to try elucidate the qualitative differences, if any, that arise when using RTRL with online updates in comparison to BPTT. To the best of our knowledge no prior work has been done in this regard, and even though numerous studies have been done in either improving, or analyzing the performance of RTRL in different scenarios, as well as reducing its computational cost, we could not find any prior work in trying to uncover the qualitative differences that could potentially arise.

2 Teacher Student Analysis

2.1 Online EVGP

As argued in [3] if there is any hope of understanding Recurrent Neural Networks we first need to understand them in the special case where we remove the non-linearities. Albeit in principle this simplifies the analysis, removing the non-linearities however makes the online algorithm more prone to the exploding-vanishing gradient problem [4], when compared to the offline one. To see this, lets first define Jt≔dθht(θt)J_t \coloneqq \mathrm{d}_{\theta}h_t\left(\theta_{t}\right), Dt≔δftδh(ht−1)D_t \coloneqq \frac{\delta f_t}{\delta h}\left(h_{t-1}\right), and It≔δftδθ(θt)I_t \coloneqq \frac{\delta f_t}{\delta \theta}\left(\theta_{t}\right). Equation 3 can then be rewritten as:

∑t=1TdLtdhtdhtdθ=∑t=1TdLtdhtJt=∑t=1TdLtdht(DtJt−1+It)\begin{aligned} \sum_{t=1}^{T} \frac{\mathrm{d} \mathcal{L}_t}{\mathrm{d} h_t}\frac{\mathrm{d} h_t}{\mathrm{d} \theta} &= \sum_{t=1}^{T} \frac{\mathrm{d} \mathcal{L}_t}{\mathrm{d} h_t} J_t \\ &= \sum_{t=1}^{T} \frac{\mathrm{d} \mathcal{L}_t}{\mathrm{d} h_t} \left(D_t J_{t-1} + I_t\right) \end{aligned}

unrolling the recurrence and starting with J0=0J_0 = \mathbf{0}, we can see that:

Jt=DtDt−1⋯D2I1+∑k=2t−1DtDt−1⋯Dk+1Ik+It\begin{aligned} J_t &= D_t D_{t-1} \cdots D_2 I_1 + \sum_{k=2}^{t-1}D_t D_{t-1} \cdots D_{k+1} I_{k} + I_t \end{aligned}

In the class of linear RNNs2 and when using the offline algorithm the state-transition Jacobian becomes constant Dt=WD_t = W, therefore by computing JtJ_t we are also computing Wt−1W^{t-1}. This becomes an issue if the spectral radius3 ρ(W)\rho(W) is strictly bigger than 11 since the gradients are computed using JtJ_t and therefore as tt grows we enter the exploding gradient regime. This can be partially mitigated by ensuring that at initilization the randomly sampled WW satisfies the condition ρ(W)≤1\rho(W) \leq 1, however an update of the weights could easily break this inequality.

Even though this is a big concern in both algorithms, note that in the online setting the state-transition Jacobian DtD_t is not constant anymore, since we are updating WW at every time step tt. With no non-linearity regulating the matrix products in JtJ_t, a single bad in-sequence update could already set the RNN in the unstable regime. Therefore even in the linear setting, studying the dynamics of the online algorithm becomes more difficult. Recall that reducing the learning rate to smaller values in order to control the perturbation of an in-sequence update is ideally not what we are aiming for, since as mentioned before this will lead to training dynamics similar to BPPT. To further make progress in our study, we are going to take advantage of the Linear Recurrent Unit, recently introduced by [5].

2.2 Linear Recurrent Unit

Let W∈Rk×kW \in \mathbb{R}^{k\times k} be the connectivity matrix of a linear RNN, U∈Rk×kU \in \mathbb{R}^{k \times k} the input matrix, and C∈Rd×kC\in \mathbb{R}^{d\times k} the readout matrix. Given h0h_0, and a sequence x\mathbf{x} the output yty_t is computed as:

ht=Wht−1+Uxt,yt=Chth_t = W h_{t-1} + U x_{t}, \quad y_t = C h_t

this in fact is equivalent to computing the convolution:

ht=∑j=0t−1WjUxt−j(5)\begin{aligned} h_t &= \sum_{j=0}^{t-1}W^{j} U x_{t - j} \end{aligned} \tag{5}
yt=Cht\begin{aligned} y_t &= C h_t \end{aligned}

note that diagonalizable matrices are dense in Rk×k\mathbb{R}^{k\times k} [6], therefore under a small perturbation of WW we can decompose it as W=PΛP−1W = P \Lambda P^{-1}, where Λ=diag(λ1,...,λk)∈Ck×k\Lambda = \text{diag}(\lambda_1, ..., \lambda_k) \in \mathbb{C}^{k \times k}, and P∈Ck×kP \in \mathbb{C}^{k \times k} is an invertible matrix. Left multiplying equation 5 by P−1P^{-1} on both sides, and letting C~≔CP\tilde{C} \coloneqq CP, B~≔P−1B\tilde{B} \coloneqq P^{-1}B, we obtain:

yt=C~∑j=0t−1ΛjB~xt−j(6)y_t = \tilde{C} \sum_{j=0}^{t-1}\Lambda^{j} \tilde{B} x_{t - j} \tag{6}

If the purpose of our study is to first understand the training dynamics of RTRL in the class of linear RNNs, we might as well train linear RNNs where instead of learning θ=(W,U,C)\theta=(W, U, C), we learn θ=(Λ,B~,C~)\theta=(\Lambda, \tilde{B}, \tilde{C})4 and work with complex matrices. Expressiveness will not be lost in this parametrization, but it still does not ensure stable training dynamics and the EVGP remains a concern in both online and offline training settings.

Recently [5] took the previous approach one step further, and propose parametrizing the elements of Λ\Lambda as:

λj≔exp⁡(−νj+iθj)\lambda_j \coloneqq \exp(-\nu_j + i\theta_j)

where it is the vectors ν∈Rk\mathbf{\nu} \in \mathbb{R}^{k} and θ∈Rk\mathbf{\theta} \in \mathbb{R}^{k} that will be learned during training. It is easy to see that under this parametrization starting with νj≥0\nu_j \geq 0 for all jj guarantees ρ(Λ)<1\rho(\Lambda) < 1 at initialization. However post-update stability cannot be guaranteed since a νj\nu_j can become negative. To address this, they introduced an additional positive non-linearity leaving the final parametrization as:

λj≔exp⁡(−exp⁡(νj)+iθj)(7)\lambda_j \coloneqq \exp(-\exp(\nu_j) + i\theta_j) \tag{7}

and now stability is ensured post-update. For learning long-range sequences where λj→1\lambda_j \to 1, the authors still noted a explosion in the forward pass. To see why5, assume a one dimensional network λ∈C\lambda \in \mathbb{C}, and let B~=1\tilde{B}=1. Then under white-noise input xtx_t we can see that:

∣ht~∣=∣∑j=0t−1λjxt−j∣ (Absolute value in C)  ⟹  ∣ht~∣2=(∑j=0t−1λjxt−j)(∑i=0t−1λixt−i)∗ (For i≠j, E[xt−jxt−i]=0)  ⟹  E[∣ht~2∣]=E[(∑j,i=0t−1λjxt−j(λi)∗(xt−i))]=(∑j=0t−1∣λ∣2jE[xj2]) (Geometric series with r=∣λ∣2<1)  ⟹  lim⁡t→∞E[∣ht~2∣]=11−∣λ∣2\begin{aligned} &|\tilde{h_t}| = \bigg|\sum_{j=0}^{t-1}\lambda^{j} x_{t - j}\bigg| && \\ &\text{ (Absolute value in $\mathbb{C}$)} && \\ &\implies |\tilde{h_t}|^{2} = \bigg(\sum_{j=0}^{t-1}\lambda^{j} x_{t-j}\bigg)\bigg(\sum_{i=0}^{t-1}\lambda^{i} x_{t - i}\bigg)^{*} && \\ &\text{ (For $i \neq j, \, \mathbb{E}[x_{t-j}x_{t-i}] = 0$)} && \\ &\implies \mathbb{E}\big[|\tilde{h_t}^2|\big] = \mathbb{E}\left[\bigg(\sum_{j, i=0}^{t-1}\lambda^{j}x_{t - j}(\lambda^{i})^{*}(x_{t - i})\bigg)\right] = \bigg(\sum_{j=0}^{t-1}|\lambda|^{2j}\mathbb{E}[x_{j}^2]\bigg) && \\ &\text{ (Geometric series with $r=|\lambda|^{2} < 1$)} && \\ &\implies \lim_{t\to\infty}\mathbb{E}\big[|\tilde{h_t}^2|\big] = \frac{1}{1 - |\lambda|^{2}} \end{aligned}

therefore as λ→1\lambda \to 1 the forward pass explodes since the contribution from xjx_j takes longer to decay. In order to address this issue they propose to normalize B~xt\tilde{B}x_{t} by an element-wise factor γ\gamma defined at initialization as γ≔1−∣λ∣2\gamma \coloneqq\sqrt{1 - \left|\lambda\right|^{2}}.

Given the preceding normalization and the exponential parametrization of λ\lambda (7) the Linear Recurrent Unit (LRU) is formally defined by [5] as:

ht=λht−1+γ⊙(Bxt)(8)\begin{aligned} h_t &= \lambda h_{t-1} + \gamma \odot \left(B x_{t}\right) \end{aligned} \tag{8}
yt=ℜ[Cht]+Dxt(9)\begin{aligned} y_t &= \Re \left[C h_t\right] + D x_{t} \end{aligned} \tag{9}

where θ=(λ,B,C,D,γ)\theta = (\lambda, B, C, D, \gamma). The LRU plays a significant role for our next studies as in-sequence updates will no longer break the stability of the linear RNNs. Furthermore as shown by [7], the diagonal nature of the connectivity matrix in the LRU allows for drastically reducing the computational and memory requirements induced by RTRL. This is due to the fact that complex neurons in the LRU do not affect each other and therefore tracking the sensitivities requires only O(∣θ∣)\mathcal{O}(|\theta|) storage, while updating the Jacobian dθht\mathrm{d}_{\theta}h_t gets reduced from a matrix multiplication to a dot product. For more details about the properties of the LRU and its online training algorithm the reader is encouraged to check the excellent work done by [5] and [7].

Having introduced the LRU and its benefits when used in combination with the RTRL algorithm, in the next section we will start studying its dynamics empirically in a teacher-student setting.

2.3 Sample Complexity Study

Our investigation begins with the question: Does the substantially higher update frequency of RTRL compared to BPTT provide any benefits in a Linear System Identification (LSI) task? Specifically, we aim to determine whether it results in improved performance or faster convergence.

Following [8], we will work under a teacher-student setting where the teacher is formally defined as:

ht+1=Aht+Bxt+1andyt=Cht+Dxt.(10)h_{t+1} = Ah_t + Bx_{t+1} \quad\text{and}\quad y_t = Ch_t + Dx_t. \tag{10}

with ht∈Rnh_t \in \mathbb{R}^n, xt∈Rx_t \in \mathbb{R} drawn i.i.d. from N(0,1)\mathcal{N}(0,1), A∈Rn×nA \in \mathbb{R}^{n \times n}, B∈Rn×1B \in \mathbb{R}^{n \times 1}, C∈R1×nC \in \mathbb{R}^{1 \times n} and D∈R1×1D \in \mathbb{R}^{1 \times 1}. The difficulty of the task its determined by the spectral radius of AA, since given an input xt−jx_{t-j} its contribution to yty_t is modulated by ρ(A)j\rho(A)^{j} as can be seen from equation 6. Thus bigger values of ρ(A)\rho(A) will force the student to remember inputs from further back in time. Since this ρ(A)\rho(A) is a parameter we want to control in our experiments, after sampling Ai,j∼iidN(0,1/n)A_{i,j} \overset{\mathrm{iid}}{\sim} \mathcal{N}(0, 1/n), we complex diagonalize it6, and then we apply the following transformation [8] to its spectrum:

λi←(νmin⁡+(νmax⁡−νmin⁡)tanh⁡(∣λi∣))exp⁡(iangle(λi)πθ0)\lambda_i \gets \left(\nu_{\min} + \left(\nu_{\max} -\nu_{\min}\right)\tanh\left(\left|\lambda_i\right|\right)\right) \exp\left(i\frac{\text{angle}\left(\lambda_i\right)}{\pi}\theta_{0}\right)

note that this transformation ensures that νmin⁡≤∣λi∣≤νmax⁡\nu_{\min} \leq |\lambda_i| \leq \nu_{\max}. In case AA contained complex eigenvalues they must come in conjugate pairs. By using exp⁡(⋅)\exp(\cdot) in the transformation and noting that exp⁡(iθ)∗=exp⁡(−iθ)\exp(i\theta) ^{*} = \exp(-i\theta), the resulting matrix after the transformation is also real.

Controling νmin\nu_{min} and νmax\nu_{max} in the teacher is not enough for our purposes as we also need to control the spectrum of the student. The student will be a LRU, where its spectrum is controled by sampling λ\lambda using lemma 3.2 from [5]:

Let u1,u2u_1, u_2 be independent uniform random variables on the interval [0,1][0, 1]. Let 0≤rmin≤rmax≤10 \leq r_{\text{min}} \leq r_{\text{max}} \leq 1. Compute ν=−12log⁡(u1ρ+rmin2)\nu = -\frac{1}{2} \log \left( u_1\rho + r_{\text{min}}^2 \right), where ρ=rmax2−rmin2\rho = r_{\text{max}}^2 - r_{\text{min}}^2 and θ=2πu2\theta = 2 \pi u_2. Then exp⁡(−ν+iθ)\exp(-\nu + i \theta) is uniformly distributed on the ring in C\mathbb{C} between circles of radii rminr_{\text{min}} and rmaxr_{\text{max}}.

For the experiments the hidden size of the teacher is fixed to 10 and for the student 64. We will gradually increase [rmin⁡,1)[r_{\min}, 1) and [νmin⁡,1)[\nu_{\min}, 1) for the student and the teacher respectively. We choose a sequence size of T=300T=300 to ensure that the input sequence is longer than the characteristic timescale we want to learn7. For every value νmin⁡\nu_{\min}, we train the student LRU with BPTT and RTRL under the same conditions with the same budget of samples, which varies from {1000,5000,20000,500000}\{1000, 5000, 20000, 500000\}. We work under the purest version of SGD with batch size 11. The loss L\mathcal{L} is the mean squared error over the prediction and the target sequence. To be fair with both algorithms and since gradient descent optimization is highly dependent on the learning rate, we sweep over 15 learning rates starting from 0.010.01 and decreasing logarithmically. For the optimization algorithm we use Adam [9] with its default hyperparameters in combination with cosine annealing without warm restarts8. When the best evaluation loss is found at one of the extremes of the allocated learning rates, we manually finetune it until the best learning rate does not live in the extremes. We repeat everything for 44 different seeds. The grid search is done using Ray Tune [10], and we use the framework introduced in the Sparse Jacobians post for implementing RTRL, where we conducted unit tests in all the optimization algorithms to ensure their correctness. Details of all the hyperparameters that we sweep over can be found in table 1.

Intuitively to correctly explore the parameter space Θ\Theta for learning long-range dependencies, we want the dθht\mathrm{d}_{\theta}h_t to not be biased. This is ensured in BPPT, as there are no in-sequence updates. However for RTRL this term does not actually reflect the influence of the parameters at the beginning of the sequence. Since θ0\theta_0 has had an influence in ht−kh_{t-k} and ht−kh_{t-k} in turn influences hth_t as well, if the loss L\mathcal{L} at time step tt is highly dependent in the state of ht−kh_{t-k}, we should take into account the θ0\theta_0 that leads h0h_0 to ht−kh_{t-k} as well.

By allowing online updates we are not really tracking the real influence over all time steps. For tasks with short-time scale as measured by the spectral radius of the teacher, we should expect that the significantly higher number of updates of RTRL help converging faster towards a smaller loss. This advantage however should be lost as we give more sample budget both BPTT and RTRL, and the spectral radius of the teacher increases as well.

Results of the empirical sample complexity experiment for LSI can be seen in figure 1. The results align with our intuition as the performance of RTRL outperforms BPPT only on small values of νmin⁡\nu_{\min} and when the budget of samples is small. Eventually the differences vanish and BPTT catches up in performance. For bigger values of νmin⁡\nu_{\min}, RTRL does not present any advantage and when the budget is increased towards 5000050000 performs an order of magnitude worse than BPTT.

Grid Search

Algorithms {RTRL, BPTT}
Samples {1000,5000,20000,50000}\{1000, 5000, 20000, 50000\}
Seeds {7,14,21,28}\{7, 14, 21, 28\}
Teacher hdimh_\text{dim} 10
Student hdimh_\text{dim} 64
Batch Size 1
η\eta 0.01×2−1 ∗ [0,1,…,15]0.01 \times 2^{-1 \,*\, [0, 1, \dots, 15]}
rmin⁡r_{\min} {0.32,0.42,0.78,0.92,0.99}\{0.32,0.42, 0.78, 0.92, 0.99\}
rmax⁡r_{\max} 1
Scheduler Cosine Annealing (No warm restarts)
β1\beta_1 0.9
β2\beta_2 0.99

Table 1: Experimental details of the grid search performed for the empirical sample complexity study.

Sample complexity at four teacher spectral radii, comparing RTRL and BPTT

Figure 1: Sample complexity study for different values of (νmin⁡,1](\nu_{\min}, 1]. We report the mean over all the seeds, where the error bars denote the min and max over the seeds. Both BPTT and RTRL are in their best performing setting, found with grid search.

3 Benefits of Noisy In-Sequence Updates

Recall that in the previous experiment we used Adam with its default hyperparameters as our optimizer. Lets take a closer look at the update function defined by Adam9:

gt←dθft(θt−1)mt←β1⋅mt−1+(1−β1)⋅gtvt←β2⋅vt−1+(1−β2)⋅gt2θt←θt−1−η⋅mtvt+εθt≕U(β1,β2,η,dθft(θt−1))\begin{aligned} g_t &\gets \mathrm{d}_{\theta}f_{t}(\theta_{t-1}) \\ m_t &\gets \beta_1 \cdot m_{t-1} + ( 1 - \beta_1)\cdot g_{t} \\ v_t &\gets \beta_2 \cdot v_{t-1} + ( 1 - \beta_2)\cdot g_{t}^{2} \\ \theta_{t} &\gets \theta_{t-1} - \eta \cdot \frac{m_t}{\sqrt{v_t} + \varepsilon} \\ \theta_{t} &\eqqcolon \mathcal{U}(\beta_1, \beta_2, \eta, \mathrm{d}_{\theta} f_{t}(\theta_{t-1})) \end{aligned}

Adam defines three10 hyperparameters β1\beta_1, β2\beta_2 and η\eta that are left for the experimenter to tune. Intuitively β1\beta_1 controls the exponential moving average of the gradients, since as β1→1\beta_1 \to 1 greater smoothing is performing and more weight is given to the average gradient mtm_t. One will expect that for learning a long-range task, if we are performing in-sequence updates, we want to give more importance to the average gradient mtm_t, the intuition for this is that since in the online setting the parameters now define a in-sequence trajectory θ1:T\theta_{1:T}, the update directions from the instantaneous loss gradients dθLt\mathrm{d}_{\theta}{\mathcal{L}_t} do not necessarily need to be aligned11. This leads the trajectory to fluctuate significantly, which we control using β1\beta_1 with Adam. The interpretation that β1\beta_1 controls these fluctuations of the gradients, can be easily checked by tracking the updates U(β1,η,dλLt)\mathcal{U}(\beta_1, \eta, \mathrm{d}_{\lambda}\mathcal{L}_t)12 given by Adam to the eigenvalues, as we do in Figure 2.

Real and imaginary in-sequence Adam updates for different momentum settings

Figure 2: Toy example to confirm our intuition regarding the role of the β1\beta_1 in Adam for in-sequence updates. One dimensional teacher in [0.99,1)[0.99, 1), one dimensional student dimensional student in [0,1)[0, 1). One single iteration of RTRL over an input sequence.

Whether reducing this fluctuations is beneficial for RTRL, as we presuppose, is what we discuss next.

Contrary to our intuition the closer β1→0\beta_1 \to 0 the better RTRL performs, even in the harder task of our previous experiment where νmin⁡=0.99\nu_{\min} = 0.99. In figure 3, we can see a sweep over different values of β1\beta_1, where for each β1\beta_1, we follow a similar grid search procedure as in the previous study, ensuring that for every β1\beta_1 we find the best configuration, ensuring a fair comparison. The best mean performance its achieved with β1=0.0\beta_1 = 0.0 i.e no smoothing at all over the in-sequence gradients, and even more surprising, it is achieved with the maximum initial learning rate η\eta when compared to best performant learning rates in the other β1\beta_1 scenarios.

Adam beta-one sweep on the linear system identification task

Figure 3: Performance of Adam in the LSI task for different values of β1\beta_1. The colorbar reflects the value of the initial learning rate η\eta. Cosine Annealing is applied for every run. Mean of 4 different seeds, errors bars indicating the min and max evaluation loss.

In order to get more insights we start by analyzing the backward sensitivity of the system, which we define as:

t↦∥dhTdht∥(11)t \mapsto \left\lVert \frac{\mathrm{d} h_T}{\mathrm{d} h_t}\right\rVert \tag{11}

where the norm is the spectral norm i.e the largest singular value. Intuitively this term measures how sensitive the final hidden state hTh_T is to a perturbation of a hidden state in a distant past tt. For tasks with long-range dependencies we want this term to increase during training in case it is small at time steps the task cares about.

Note that in the LRU, the state-transition Jacobian is constant dht−1ht=diag⁡(λ)\mathrm{d}_{h_{t-1}}h_{t} = \operatorname{diag}(\lambda), and because the spectral norm of a diagonal matrix its equal to its spectral radius we have that t↦∣λmax⁡∣T−tt \mapsto \left|\lambda_{\max}\right|^{T-t}. So function 11 its completely characterized by the spectral radius of diag(λ)\text{diag}(\lambda), which allows us to study it with just a single scalar. Therefore we track the max⁡\max eigenvalue after every iteration of both RTRL and BPTT, as well as tracking the min⁡\min eigenvalue and then mean of ∣λj∣\left|\lambda_j\right|. We do this in a setup where the student starts with a spectrum in [0,1)[0, 1), so that we recover Glorot initialization [11]. The teacher will be set to the hardest difficulty where νmin⁡=0.99\nu_{\min} = 0.99, in addition to ∣λmax⁡∣\left|\lambda_{\max}\right|. For both algorithms we follow the same grid search procedure as in the previous study in order to compare them in their best performing settings. Since we want to better understand the observation from figure 3, in RTRL we check for β1=0\beta_1=0 and β1=0.9\beta_1 = 0.9, whereas in BPTT we only check for β1=0.9\beta_1=0.9. Note that in the class of Liner RNNs, as mentioned before, the state-transition Jacobian is constant13 and is equal to the connectivity matrix, therefore we should expect in both settings that the spectral radius of diag(λ)\text{diag}(\lambda) increases towards higher values, closer to where the spectral radius of the teacher is. Otherwise they could not learn the long-range dependencies.

Evolution of the maximum, minimum, and mean eigenvalue magnitude

Figure 4: Evolution of the norm of max, min and average eigenvalue during the first 10K iterations. Student initialized in [0.0,1)[0.0, 1). Teacher initialized with in [0.99,1)[0.99, 1). Shaded areas indicate the standard error of the mean over the different seeds.

In figure 4 we can see the evolution of the quantities just described. From the plots we note three qualitative differences when considering noisy in-sequence updates (β1=0.0\beta_1 = 0.0) in comparison to BPTT and smoother in-sequence updates (β1=0.9\beta_1 = 0.9) in RTRL:

  1. The spectral radius converges faster towards its theoretical limit14.

  2. The norm of the minimum eigenvalue converges faster towards 0.

  3. Overall the norm of the eigenvalues of the state-transition Jacobian tend to converge faster towards higher values.

in order to better comprenhend this empirical observations, in the next subsection we will argue for a simple toy model that we believe explains the previous qualitative differences.

3.1 RTRL Toy Model

To understand the qualitative phenomena of the previous study we start by recalling the LRU parametrization15:

λ≔exp⁡(−exp⁡(ν)+iθ)\lambda \coloneqq \exp(-\exp(\nu) + i\theta)

where ν∈Rn\mathbf{\nu} \in R^{n} and θ∈Rn\mathbf{\theta} \in R^{n}. Since the quantity we are interested is the norm of λj\lambda_j, to simplify the analysis we set θ=0⃗\theta = \vec{0} as it does not contribute16 to the norm. Therefore the parametrization we study is left as:

λ≔exp⁡(−exp⁡(ν))(12)\lambda \coloneqq \exp(-\exp(\nu)) \tag{12}

and the in-sequence update equations17 when performing gradient descent follow:

νt+1=νt−ηdLtdhtdhtdλdλdν(13)\begin{aligned} \nu_{t+1} &= \nu_{t} - \eta \frac{\mathrm{d} L_t}{\mathrm{d} h_t} \frac{\mathrm{d} h_t}{\mathrm{d} \lambda} \frac{\mathrm{d} \lambda}{\mathrm{d} \nu} \end{aligned} \tag{13}
λt+1=exp⁡(−exp⁡(νt+1))(14)\begin{aligned} \lambda_{t+1} &= \exp\left(-\exp\left(\nu_{t+1}\right)\right) \end{aligned} \tag{14}

Define et≔ηdLtdhtdhtdλe_t \coloneqq \eta \frac{\mathrm{d} L_t}{\mathrm{d} h_t} \frac{\mathrm{d} h_t}{\mathrm{d} \lambda}, and note that −dλdν=exp⁡(νt−exp⁡(νt))-\frac{\mathrm{d} \lambda}{\mathrm{d} \nu} = \exp(\nu_{t} - \exp(\nu_{t})), hereby equation 13 becomes:

νt+1=νt+etexp⁡(νt−exp⁡(νt))νt+1≕g(νt,et)(15)\begin{aligned} \nu_{t+1} &= \nu_{t} + e_t \exp\left(\nu_{t} - \exp\left(\nu_{t}\right)\right) \\ \nu_{t+1} & \eqqcolon g\left(\nu_{t}, e_t\right) \end{aligned} \tag{15}

we can treat 15 as a non-autonomous discrete dynamical system, since ete_t will be varying at each time step tt. Even though an oversimplification, is still worth assuming constant ete_t, so that we can treat 15 as an autonomous dynamical system, where the analysis becomes easier. In the one-dimensional setting the direction of ete_t is either a positive one (+1)(+1) or negative (−1)(-1), so assuming ∣ek∣=1\left|e_k\right| = 1, we can plot the dynamics of the system in a Cobweb diagram (Figure 5) together with the LRU parametrization. From the plots it is clear that:

lim⁡t→∞g(νt,+1)=+∞  ⟹  lim⁡t→∞λt=0lim⁡t→∞g(νt,−1)=−∞  ⟹  lim⁡t→∞λt=1\begin{aligned} \lim_{t\to\infty} g(\nu_{t}, +1) &= +\infty \implies \lim_{t\to\infty} \lambda_t = 0 \\ \lim_{t\to\infty} g(\nu_{t}, -1) &= -\infty \implies \lim_{t\to\infty} \lambda_t = 1 \end{aligned}

Of course during optimization neither ete_t will be constant nor ∣et∣≠1|e_t| \neq 1. The term ete_t will be regulated by the learning rate η\eta, and the directions will differ during the in-sequence updates. In RTRL ete_t fluctuates significantly during the forward pass (Figure 2), and this fluctuation can be controlled by β1\beta_1 when using Adam.

Assuming, as previously argued, that ete_t fluctuates significantly, let's replace ete_t by a random variable εt∼N(0,σ2)\varepsilon_t \sim \mathcal{N}(0, \sigma^{2}). The fluctuation is now governed by σ\sigma. Consider a Markovian random walk in R\mathbb{R}. With sufficient iterations, the larger the σ\sigma the quicker the random walk reaches its first-passage time for a given threshold. Recalling that in RTRL we perform TT additional updates to λ\lambda compared to BPTT, the previous analysis suggests that under in-sequence updates, convergence towards either 0 or 1 occurs more rapidly in the LRU, even if these updates exhibit considerable fluctuation. In fact larger fluctuations, as in the random walk, imply earlier first-passage times over values of νt\nu_t that result in closer values of λt\lambda_t to the two poles. We can see now that as β1→0\beta_1 \to 0, the effective σ\sigma increases, leading to a faster increase in the spectral radius while training, thereby enhancing performance in the harder task where νmin⁡=0.99\nu_{\min}=0.99, which is what we see in figure 4.

LRU parametrization and its cobweb diagram

Figure 5: Left: Parametrization of the LRU for real eigenvalues. Right: Cobweb Diagram assuming constant backpropagated errors, (+1)(+1) or (−1)(-1)

In figure 6 we confirm our analysis, where we sample a white noise sequence from N(0,σ2)\mathcal{N}(0, \sigma^2) to play the role of ete_t and we track the evolution of g(νt,et)g(\nu_{t}, e_{t}), where λ0=0.5\lambda_0 = 0.5, for different values of σ\sigma. As we can appreciate from the figure, the largest value of σ\sigma results in faster convergence towards the two poles, 0 and 1, but eventually for every value of σ\sigma convergence to the poles should occur given enough iterations. We repeat the analysis for 10310^3 white noise sequences, each of them of length T=104T=10^4, and in figure 6 we show their distribution at different time steps, for different values of σ\sigma. The higher density around 0 in the histogram at 10K can be explained by noting that:

∣dνλ(ν)dνλ(−ν)∣=exp⁡(ν−exp⁡(ν))exp⁡(−ν−exp⁡(−ν))=Ω(exp⁡(−ν))\left|\frac{\mathrm{d}_{\nu}\lambda(\nu)}{\mathrm{d}_{\nu}\lambda(-\nu)}\right| = \frac{\exp(\nu - \exp(\nu))}{\exp(-\nu - \exp(-\nu))} = \Omega(\exp(-\nu))

which implies that converge happens in fewer iterations towards 0 than towards 1, biasing the distribution in this simplified RTRL toy model for the LRU.

Toy RTRL trajectories and distributions under different noise levels

Figure 6: Top: Sampled trajectories of the toy RTRL model, for different standard deviations for T∈{500,104}T \in \{500, 10^4\} steps.Bottom: Distribution at T∈{500,104}T \in \{500, 10^4\} of N=1000N=1000 sampled trajectories for different standard deviations

Eigenvalue trajectories during RTRL and BPTT training

Figure 7: Trajectories of the ∣λj∣\left|\lambda_j\right| during training in RTRL for different values of β1\beta_1 and in BPTT. Coloring reflects the order of ∣λj∣\left|\lambda_j\right|, darker being the highest, lighter being the lowest. Only one seed is showed for easier visualization

Complementary cumulative eigenvalue distributions after training

Figure 8: Pr⁡(∣λ∣>x)\Pr (|\lambda| > x) after 50K Iterations of training. Computed over 4 different seeds for different values of β1\beta_1 and for BPTT.

From the previous analysis we can already start to understand the qualitative differences we observed in the LSI study between the different β1\beta_1 scenarios and BPTT. If β1→0\beta_1 \to 0 the ∣λj∣\left|\lambda_j\right| of the LRU should show convergence towards a bimodal distribution in 0 and 1, which in turn will increase the spectral radius. This is what we indeed observe in figure 7, when we track the trajectories of the ∣λj∣\left|\lambda_j\right| during training of the LSI task. Only one seed is displayed for making the visualization easier, nevertheless to strengthen our hypothesis about the qualitative differences between RTRL and BPTT, in figure 8 we plot the complementary cumulative distribution function 18 Pr⁡(∣λ∣>x)\Pr(|\lambda| > x) (CCDF) at the end of training, now computed among the different seeds for both RTRL and BPTT.

Note that the 1−F(x)1 - F(x) displayed in figure 8 is computed at the last iteration of training, nevertheless given the big gap between BPTT in RTRL it suggests the following. For sufficiently big NN, there exists a threshold α\alpha such that for all n≥Nn \geq N:

1−FnB(x)≤1−FnR(x)for α≤x≤1.(16)1 - F_{n}^{B}(x) \leq 1 - F_{n}^{R}(x) \quad \text{for $\alpha\leq x \leq 1$.} \tag{16}

where with BB we denote BPTT and with RR we denote RTRL. We cannot offer a proof for this, but nevertheless, we give support for this claim in figure 9, where we show CCDF for both methods while training from the first iteration until iteration 1000, the upper bound on 1 its given by the stable parametrization of the LRU. How small can this NN be, we believe will become relevant when we study non-linear RNN's in the next section.

Evolution of the complementary cumulative eigenvalue distributions

Figure 9: In Red: 1−FnR1 - F_{n}^{R} for n≤1000n\leq 1000. In Blue: 1−FnB1 - F_{n}^{B} for n≤1000n\leq 1000. R≔RTRLR \coloneqq \text{RTRL} and B≔BPTTB\coloneqq \text{BPTT}. Runs over 4 seeds. Lighter color indicates earlier iterations, darker color indicates iterations at the end.

Interpreting ete_t as εt\varepsilon_t wast partly motivated by figure 2, where we verified, albeit in a simplistic setting, that the updates provided by Adam i.e U(β1,η,dνLt)\mathcal{U}(\beta_1, \eta, \mathrm{d}_{\nu}\mathcal{L}_t), were highly stochastic in nature. The cautious reader must have noted that our definition of ete_t in the toy model, doest not equate exactly to our LSI experiments are being performed. To see why note that when using Adam, the actual update equations for ν\nu follow νt+1=νt+U(β1,β2,η,dθLt)\nu_{t+1} = \nu_{t} + \mathcal{U} (\beta_1, \beta_2, \eta, \mathrm{d}_{\theta}\mathcal{L}_t) therefore:

νt+U(β1,β2,η,dθLt)≠νt−ηdLtdhtdhtdλdλdν=νt−etdλdν(17)\nu_{t} + \mathcal{U}\left(\beta_1, \beta_2, \eta, \mathrm{d}_{\theta}\mathcal{L}_t\right) \neq \nu_{t} - \eta \frac{\mathrm{d} L_t}{\mathrm{d} h_t} \frac{\mathrm{d} h_t}{\mathrm{d} \lambda} \frac{\mathrm{d} \lambda}{\mathrm{d} \nu} = \nu_{t} - e_t\frac{\mathrm{d} \lambda}{\mathrm{d} \nu} \tag{17}

to further strength our observations and justify our interpretation of ete_t we need to decompose U(⋅)\mathcal{U}(\cdot) into the two terms, et′e'_t and dνλ\mathrm{d}_{\nu}\lambda so that:

U(β1,β2,η,dνLt)=et′dλdν(18)\mathcal{U}\left(\beta_1, \beta_2, \eta, \mathrm{d}_{\nu}\mathcal{L}_t\right) = e'_t\frac{\mathrm{d} \lambda}{\mathrm{d} \nu} \tag{18}

which matches the same equation as in 15, note that in the LRU ν\nu is a vector in Ck\mathbb{C}^{k} and λ\lambda as well, therefore to solve for et′e'_t, we could right multiply both sides by the inverse matrix (dνλ)−1(\mathrm{d}_{\nu}\lambda)^{-1}. The inverse is guaranteed to exist since the matrix dνλ\mathrm{d}_{\nu}\lambda is diagonal19. If our interpretation of RTRL and the influence of β1\beta_1 is a valid one, then we must see as well that when computing the element-wise Var⁡[e′]n\operatorname{Var}[e']_n (using as observations all the time steps during an input sequence x\mathbf{x} given at iteration nn) 20, for different values of β1\beta_1 the variances must satisfy21:

Var⁡0.99[e′]n≤Var⁡0.9[e′]n≤Var⁡0.8[e′]n⋯≤Var⁡0.0[e′]n\operatorname{Var}_{0.99}[e']_{n} \leq \operatorname{Var}_{0.9}[e']_{n} \leq \operatorname{Var}_{0.8}[e']_{n} \dots \leq \operatorname{Var}_{0.0}[e']_{n}

Recall that et′e'_t is a vector with elements in C\mathbb{C} therefore we use the following definition of variance for a complex random variable:

Var⁡[X]=Var⁡[ℜ(X)]+Var⁡[ℑ(X)](19)\operatorname{Var}\left[X\right] = \operatorname{Var}\left[\Re\left(X\right)\right] + \operatorname{Var}\left[\Im\left(X\right)\right] \tag{19}

In figure 10 we can see these values computed using 4 different seeds where we used the same initial learning rate η\eta. Note that they closely match our interpretation of ete_t.

Overall the previous experiments further validate the use of our toy model for RTRL, when trying to study its dynamics. Though it may sound simple, to the best of our knowledge we have not seen any study in the literature following our approach. This might partially be because of timing, since the LRU which is a key component in our study has only been introduced recently. We conclude this section by reminding the reader that we started studying RTRL in class of linear RNNs, with the hope of giving us a better understanding of its training dynamics in the non-linear setting. In the next section we start to study RTRL in non-linear RNNs.

Variance of in-sequence updates across eigenvalues

Figure 10: Mean of the vector Var⁡[e′]n\sqrt{\operatorname{Var}[e']_n} during training for different values of β1\beta_1.

4 Implications In Sparse Networks

Eigenvalue distributions of random matrices at different sparsity levels

Figure 11: Distribution of the eigenvalues for a random matrix with i.i.d entries from N(0,1/256)\mathcal{N}(0, 1/256), when applying masks of different levels of sparsity.

Recently [12] showed the advantage of imposing sparsity in the parameters of the network by proposing a biased approximation to dθht\mathrm{d}_{\theta}{h_t} which reduces the memory and computational complexity of RTRL, as explained in the Sparse Jacobians post. Their experiments conclude that training highly sparse RNNs (GRU and LSTM) with RTRL outperforms BPTT when learning a curricular copy task. Studying RTRL in RNNs with gated mechanisms to understand this phenomena. Is out of the scope of this thesis and left for future work, here instead we focus on Continuous Time Recurrent Neural Networks (CTRNN), using some of the insights derived from the previous section in Linear RNNs.

Following [13] the class of CTRNN considered here are derived from the discretization of the following continuous-time dynamical system:

h˙(t)=−h(t)+Wφ(h(t))+N∑i=1Ninuixi(t).(20)\dot{h}\left(t\right) = -h\left(t\right) + W \mathbf{\varphi}\left(h\left(t\right)\right) + \sqrt{N} \sum_{i=1}^{N_{\text{in}}} \mathbf{u}_i x_i(t). \tag{20}

where φ≔tanh⁡\varphi \coloneqq \tanh, NN represents the number of hidden units, NinN_{\text{in}} the number of input channels, W∈RN×NW \in \mathbb{R}^{N \times N}, and U=[u1,⋯ ,uNin]∈RN×NinU = [\mathbf{u}_1, \cdots, \mathbf{u}_{N_{\text{in}}}] \in \mathbb{R}^{N \times N_{\text{in}}}. The readouts of the network are computed by:

yi(t)=ciTφ(h(t))NFor i in {1,…,Nout}(21)y_i\left(t\right) = \frac{\mathbf{c}_{i}^{T}\varphi\left(h\left(t\right)\right)}{\sqrt{N}} \quad \text{For $i$ in $\{1, \dots, N_{\text{out}}\}$} \tag{21}

where NoutN_{\text{out}} represents the number of output channels and ci∈RN\mathbf{c}_i \in \mathbb{R}^{N}. Similar to [13] we are interested in the training dynamics of networks where N≫1N \gg 1 and the dimensions of NinN_{\text{in}}, and NoutN_{\text{out}} are small. However we depart from their setup by forcing sparsity in the connectivity matrix WW in an attempt to understand the results from [12]. We do this by sampling a random binary matrix MsM_{s} with i.i.d\mathrm{i.i.d} entries Mi,j∼Bernoulli(1−s)M_{i,j}\sim \mathrm{Bernoulli}\left(1 - s\right), where ss will control the amount of sparsity imposed in the connectivity matrix. The transformation to WW is simply:

W↦Ms⊙W(22)W \mapsto M_{s}\odot W \tag{22}

The first insight to understand [12] comes from the following fact. Define W′≔Ms⊙WW' \coloneqq M_{s} \odot W, if the entries Wi,j∼iidN(0,1/N)W_{i,j} \overset{\mathrm{iid}}{\sim} \mathcal{N}(0, 1/N) then:

E[W′]=E[(Mi,jWi,j)2]=E[(Mi,j)2]E[(Wi,j)2]=(1−s)N\begin{aligned} \mathbb{E}\left[W'\right] = \mathbb{E}\left[\left(M_{i,j}W_{i,j}\right)^2\right] &= \mathbb{E}\left[\left(M_{i,j}\right)^2\right]\mathbb{E}\left[\left(W_{i,j}\right)^{2}\right] = \frac{\left(1 - s\right)}{N} \end{aligned}

since E[W′]=0\mathbb{E}[W'] = 0 and E[∣W′∣4]≤CE[|W'|^4] \leq C, then22 by Bai and Yin [14], we have that:

Pr⁡(lim sup⁡N→∞ρ(W′)≤(1−s))=1  ⟹  E[lim sup⁡N→∞ρ(W′)]≤1−s\Pr\left(\limsup_{N\to\infty}\rho\left(W'\right) \leq \sqrt{\left(1-s\right)}\right) = 1 \implies \mathbb{E}\left[\limsup_{N\to\infty}\rho\left(W'\right)\right] \leq \sqrt{1 - s}

and by reverse Fatou's Lemma:

lim sup⁡N→∞E[ρ(W′)]≤1−s(23)\limsup_{N\to\infty}\mathbb{E}\left[\rho\left(W'\right)\right] \leq \sqrt{1-s} \tag{23}

which basically tells us that for N≫1N\gg 1 (as in our setting and the one in [12]), under Glorot initialization of the connectivity matrix WW, imposing a random mask on the weights to induce sparsity, effectively decreases its spectral radius. This behavior is illustrated in Figure 11. In the regime of linear RNNs, as discussed in the previous section, RTRL should escape this small spectral radius faster than BPTT. As a result, this could potentially enhance performance when the objective is to learn long-range dependencies, which is what [12] observed in their experiments although in highly sparse gated RNN's.

RTRL and BPTT evaluation loss on the Romo task

Figure 12: Mean Squared Loss curves RTRL and BPTT in the evaluation distribution. Average over 4 different seeds. Both RTRL and BPTT in their best performing setting after running a comprehensive grid search. Shaded regions represent the standard error of the mean of the quantity of interest.

To test the hypothesis that RTRL outperforms BPTT when training highly sparse CTRNN we will follow a similar approach as in the preceding section were now we substitute the LSI task, with the Romo [15] task. The task is a delayed-discrimination task, where the network is presented with two positive pulses of different amplitudes separated by a delay. Following an additional delay, the network is required to remember which of the two pulses had greater amplitude. We choose this task as it is a simple one to start studying RTRL and we can easily control the specific time steps tt at which the network has received its inputs and has to start recalling the largest pulse.

As in all of our previous experiments to compare BPTT and RTRL in their best performing settings, we follow a similar grid search as in the sample complexity study. For RTRL we set β1=0\beta_1 = 0 in light of the previous section and for BPTT we set β1=0.9\beta_1 = 0.9. The sparsity of the network is imposed by sampling a random binary mask as explained before were we set ss to 0.98. For the size of the hidden units we choose N=256N=256 following [13] and also to obtain the upper bound in 23. For discretizing 20 we choose as dt=0.3\mathrm{d}t = 0.3. The evaluation loss is the mean squared error over the readouts of the network. The number of iterations for both RTRL and BPTT is set 50K. Similar to the LSI task we set the batch size to 1. In figure 12 we can see the evaluation loss curves for both methods in their best performint setting. Clearly RTRL outperforms BPTT. This partial result strengthen our hypothesis about the advantages of RTRL in highly sparse CTRNNs. In figure 13 we can also see how the spectral radius converges substantially faster to a bigger value in RTRL23. We have run control experiments where after sampling the random sparse connectivity matrix, we scale it so that we start in both algorithms with ρ(W′)=1\rho(W') = 1, and the result in terms of performance were almost the same, with RTRL clearly outperforming BPTT. Therefore there has to be some other qualitative phenomena explaining the gap in performance.

Spectral radius during early and full Romo training

Figure 13: Evolution of the spectral radius ρ(W′)\rho(W'). Average over 4 different seeds. Both RTRL and BPTT in their best performing setting after running a comprehensive grid search. Shaded regions represent the standard error of the mean of the quantity of interest. Top: Evolution during the first 200 iterations. Bottom: Evolution for the full training loop.

Note that in the non-linear regime, the spectral radius is not a good indicative anymore of how the network is learning, in the case of the LRU we studied that term since as commented before, the backward sensitivity function can be fully characterized by a single scalar. This is not true in the case of non-linear RNN's. The state-transition Jacobian of CTRNN after discretization is not constant anymore and follows:

J(t)=∂ht∂ht−1=diag⁡(1−dt)+dtWdiag⁡((1−φ(ht−1)2))(24)J\left(t\right) = \frac{\partial h_t}{\partial h_{t-1}} = \operatorname{diag}(1 - \mathrm{d}t) + \mathrm{d}t W \operatorname{diag}\left(\left(1 - \varphi\left(h_{t-1}\right)^2\right)\right) \tag{24}

In an attempt to understand the difference in performance between both methods we recall the following standard result in the theory of continuous-time dynamical systems. Assume we have an ODE, defined as:

h˙(t)=f(h(t))(25)\dot{h}\left(t\right) = f\left(h\left(t\right)\right) \tag{25}

where h∈RNh \in R^{N} and represents the hidden states of a non-linear RNN. We can differentiate equation 25 from both sides with respect to h0h_0 and after an exchange of derivatives24 we get the following equation:

ddt(∂ht∂h0)=J(t)∂ht∂h0(26)\frac{\mathrm{d}}{\mathrm{d} t}\left(\frac{\partial h_t}{\partial h_0}\right) = J\left(t\right) \frac{\partial h_t}{\partial h_0} \tag{26}

note that δhtδh0\frac{\delta h_t}{\delta h_0} its closely related to the function 11 we were studying in the previous section, were instead the role of the time variable tt is inverted. Intuitively δhtδh0\frac{\delta h_t}{\delta h_0} measures how sensitive is hth_t with respect to a perturbation to the initial condition h0h_0. Following [16] lets define as well A(t)≔δhtδh0A(t) \coloneqq \frac{\delta h_t}{\delta h_0}, equation 26, can be rewritten then as an ODE following:

dA(t)dt=J(t)A(t)(27)\frac{\mathrm{d} A\left(t\right)}{\mathrm{d} t} = J\left(t\right) A\left(t\right) \tag{27}

where A(0)=IA(0) = I. Similar to [16] we are going to make the assumption that J(t)J(t) is constant, although a strong assumption its going to help us understand the qualitative differences of RTRL when compared to BPTT, at least in the Romo task. The strong assumption, thus allows us to get the solution for the ODE at 27:

A(t)=eJt(28)A\left(t\right) = e^{J t} \tag{28}

assuming that JJ is diagonalizable we then get:

A(t)=eJt=PeΛ(J)tP−1(29)A\left(t\right) = e^{J t} = P e^{\Lambda\left(J\right)t} P^{-1} \tag{29}

where Λ(J)\Lambda(J) denotes the eigenvalues of JJ. Using the fact that the trace bounds the spectral norm, we have then:

∣tr⁡(eΛ(J)t)∣≤N∥A(t)∥(30)\left|\operatorname{tr}\left(e^{\Lambda\left(J\right)t}\right)\right| \leq N \left\lVert A\left(t\right)\right\rVert \tag{30}

combining this lower bound, with the results from figure 9 (where we showed empirically that early in training of a LRU, RTRL has much higher probability than BPTT of P(∣λ∣>x)P(\left|\lambda\right| > x) for bigger values of xx), we can see that RTRL also early in training will increase the trace in 30 since:

∣tr⁡(eΛ(J)t)∣=∣∑i=0Neλit∣(31)\left|\operatorname{tr}\left(e^{\Lambda\left(J\right)t}\right)\right| = \left|\sum_{i=0}^{N} e^{\lambda_i t}\right| \tag{31}

and as tt grows this term will be dominated by the λj\lambda_j with highest absolute value, which is precisely what RTRL increases from what we observed in the previous experiments. Therefore RTRL will push the lower bound in 30 to higher values, biasing as well the spectral norm of the forward sensitivity towards higher values when compared to BPTT early in training, which is needed to in order to start learning distant dependencies in a sequence [4]. Note that we have made strong assumptions in the previous derivation, which don't necessarily have to match the real experimental setting. In what follows we study what we have just argued.

In light of the previous experiments and from 23 we hypothesize that RTRL bias Highly Sparse CTRNNs to two regimes during training, the first one, suggested by 30, where the network tries to memorize as much as possible, and then learns to forget the irrelevant inputs for the task at hand. Actually we hypothesize that both BPTT and RTRL use the same strategy since the spectral radius of the network at initialization its quite small, but RTRL will enter the regime of memorizing much faster.

To study this hypothesis we follow a similar approach as in the previous section. As a reminder, we want to analyze:

t↦∥dhTdht∥(32)t \mapsto \left\lVert \frac{\mathrm{d} h_T}{\mathrm{d} h_t}\right\rVert \tag{32}

For every new input sequence this function changes, therefore we are not interested in the absolute magnitudes of 32 within a sequence, we are interested in their relative values within a sequence. For example, we could be interested in comparing the value at a fixed time step tt but at different iterations of the training algorithm say n1<n2n_1 < n_2. At iteration n1n_1 the dhthTn1\mathrm{d}_{h_{t}}h_{T}^{n_1} could be much smaller in norm than dhthTn2\mathrm{d}_{h_{t}}h_{T}^{n_2} at n2n_2. However that does not indicate that network its less sensitive to a perturbation in hth_t at iteration n1n_1, as it could be that the dhthTn1\mathrm{d}_{h_{t}}h_{T}^{n_1} its the biggest value in norm within its sequence indicating the contrary. Therefore if not normalizing this quantity we cannot compare them in fair manner during training at different iterations. For this reason the actual term we track is the following one. Define cn≔max⁡0≤t≤T∥∂hTn∂ht∥c_n \coloneqq \max_{0\leq t \leq T} \left\lVert \frac{\partial h_{T}^{n}}{\partial h_{t}}\right\rVert for iteration nn of the algorithm, the quantity we track can be defined then as:

t↦∥∂hTn∂ht∥cn−1(33)t \mapsto \left\lVert \frac{\partial h_{T}^{n}}{\partial h_t}\right\rVert c_{n}^{-1} \tag{33}

this quantity is bounded in [0,1][0, 1] therefore we could also integrate it, and track as well:

n↦∫0T∥∂hTn∂ht∥cn−1dt(34)n \mapsto \int_{0}^{T}\left\lVert \frac{\partial h_{T}^{n}}{\partial h_t}\right\rVert c_{n}^{-1} \mathrm{d}t \tag{34}

so that we can display in a simple way the evolution of the overall backward sensitivity of the algorithms. In figure 14 we can see 33 for a single seed and for only one input sequence at different number of iterations during training, already supporting our intuition about RTRL increasing norm of the backward sensitivity faster early in training. In figure 15 we can see 34, which gives even more support to the hypothesis that RTRL converges faster to a bigger value of 34, and then decreases this term faster as well compared to BPTT. We find interesting that even though their respective evaluation losses follow similar trends at the beginning of training, there exists a qualitative difference hidden in the dynamics of 34.

Normalized backward sensitivity during early and later training

Figure 14: Left: Normalized δhTδht\frac{\delta h_T}{\delta h_t} for the first 100 iterations of the algorithm. Right: Normalized δhTδht\frac{\delta h_T}{\delta h_t} for the first 10000 iterations of the algorithm. Ligher color indicate ealier iterations, darker colors indicate iterations close to the end. Only one sample, and only seed is displayed for easier visualization.

Evaluation loss and integrated normalized backward sensitivity during Romo training

Figure 15: Top Row: Evaluation loss curves. For 200 and 50K Iterations. Bottom Row: Integral of the normalized backward sensitivity for 200 and 50K Iterations. Shaded areas indicate the standard error of the mean for the quantity of interested. Average over 4 different seeds. Both RTRL and BPTT in their best performing settings, found by a comprehensive grid search.

We conclude this short section and the post by remarking that our study although small in nature, offers an possible explanation for the results obtained in [12]. RTRL benefits from highly stochastic in-sequence updates, and it benefits even more when the network is highly sparse, as we showed experimentally and motivated theoretically. We also posit a potential negative consequence: the tendency of RTRL to push the spectral norm of the backward sensitivity towards higher values may impair its performance in denoising tasks. Gated RNNs mitigate this issue through their gating mechanisms. Future work will explore this potential phenomenon in greater detail and attempt to generalize our findings to other tasks inspired by the neuroscience literature. The research in [12] play a significant role in the development of this post as we were quite intrigued by their results in networks where we the sparsity was close to 98%

References

[1]
R. J. Williams and D. Zipser, “A Learning Algorithm for Continually Running Fully Recurrent Neural Networks,” Neural Computation, vol. 1, no. 2, pp. 270–280, 1989, doi: 10.1162/neco.1989.1.2.270.
[2]
P.-Y. Massé and Y. Ollivier, “Convergence of online adaptive and recurrent optimization algorithms,” arXiv preprint arXiv:2005.05645, 2020.
[3]
M. Hardt, T. Ma, and B. Recht, “Gradient descent learns linear dynamical systems,” Journal of Machine Learning Research, vol. 19, no. 29, pp. 1–44, 2018.
[4]
R. Pascanu, T. Mikolov, and Y. Bengio, “On the difficulty of training recurrent neural networks,” in International conference on machine learning, Pmlr, 2013, pp. 1310–1318.
[5]
A. Orvieto et al., “Resurrecting recurrent neural networks for long sequences,” in International Conference on Machine Learning, PMLR, 2023, pp. 26670–26698.
[6]
Z. Zhang, “The Jordan Canonical Form of a Rational Random Matrix,” Science Direct, Working Paper S1574-0358(04)70392–5, Nov. 2002.
[7]
N. Zucchet, R. Meier, S. Schug, A. Mujika, and J. Sacramento, “Online learning of long-range dependencies,” in Thirty-seventh Conference on Neural Information Processing Systems, 2023. [Online]. Available: https://openreview.net/forum?id=Wa1GGPqjUn
[8]
N. Zucchet and A. Orvieto, “Recurrent neural networks: vanishing and exploding gradients are not the end of the story,” arXiv preprint arXiv:2405.21064, 2024.
[9]
D. P. Kingma and J. Ba, “Adam: A method for stochastic optimization,” in International Conference on Learning Representations (ICLR) , 2015.
[10]
R. Liaw, E. Liang, R. Nishihara, P. Moritz, J. E. Gonzalez, and I. Stoica, “Tune: A Research Platform for Distributed Model Selection and Training,” arXiv preprint arXiv:1807.05118, 2018.
[11]
X. Glorot and Y. Bengio, “Understanding the difficulty of training deep feedforward neural networks,” in Proceedings of the Thirteenth International Conference on Artificial Intelligence and Statistics, Y. W. Teh and M. Titterington, Eds., in Proceedings of Machine Learning Research, vol. 9. Chia Laguna Resort, Sardinia, Italy: PMLR, May 2010, pp. 249–256. [Online]. Available: https://proceedings.mlr.press/v9/glorot10a.html
[12]
J. Menick, E. Elsen, U. Evci, S. Osindero, K. Simonyan, and A. Graves, “Practical Real Time Recurrent Learning with a Sparse Approximation,” in International Conference on Learning Representations, 2021. [Online]. Available: https://openreview.net/forum?id=q3KSThy2GwB
[13]
F. Schuessler, F. Mastrogiuseppe, A. Dubreuil, S. Ostojic, and O. Barak, “The interplay between randomness and structure during learning in RNNs,” in Advances in Neural Information Processing Systems, H. Larochelle, M. Ranzato, R. Hadsell, M. F. Balcan, and H. Lin, Eds., Curran Associates, Inc., 2020, pp. 13352–13362. [Online]. Available: https://proceedings.neurips.cc/paper_files/paper/2020/file/9ac1382fd8fc4b631594aa135d16ad75-Paper.pdf
[14]
Z. D. Bai and Y. Q. Yin, “Limiting behavior of the norm of products of random matrices and two problems of Geman-Hwang,” Probability Theory and Related Fields, vol. 73, no. 4, pp. 555–569, 1986.
[15]
R. Romo, C. D. Brody, A. Hernández, and L. Lemus, “Neuronal correlates of parametric working memory in the prefrontal cortex,” Nature, vol. 399, no. 6735, pp. 470–473, Jun. 1999.
[16]
B. Chang, M. Chen, E. Haber, and E. H. Chi, “AntisymmetricRNN: A Dynamical System View on Recurrent Neural Networks,” in International Conference on Learning Representations, 2019. [Online]. Available: https://openreview.net/forum?id=ryxepo0cFX

Notes

  1. While this is strictly not necessary in the online setting, we believe that a more fair comparison between both algorithms can be done in this way. ↩

  2. θ=(W,U)\theta = (W, U), f(θ,ht1,xt)=Wht−1+Uxtf(\theta, h_{t_1}, x_t)= W h_{t-1} + U x_t ↩

  3. Let λ1,…,λn\lambda_1, \dots, \lambda_n be the eigenvalues of a matrix A∈Cn×nA \in \mathbb{C}^{n\times n}. The spectral radius of A is defined as ρ(A)=max⁡{∣λ1∣,…,∣λn∣}\rho (A)=\max \left\{|\lambda _{1}|,\dotsc ,|\lambda _{n}|\right\}. ↩

  4. By this change of parametrization the terms Λ\Lambda, B~\tilde{B}, C~\tilde{C} are not related anymore by an invertible P, so to compute the output we take the real part of C~h~t\tilde{C}\tilde{h}_t. ↩

  5. Derivation from [5]. ↩

  6. You can do this almost surely. ↩

  7. Characteristic of the teacher is 11−ρ(A)\frac{1}{1 - \rho(A)}. ↩

  8. Annealing the learning rate in some form is a necessary condition in SGD to converge towards a ball of small radius centered at a local minima. ↩

  9. For a

    general function ff, and for simplicity we ignore the bias correction steps. ↩

  10. The epsilon was left there for numerical stability but turns out that practitioners are also tuning it. ↩

  11. Neither orthogonal, fluctuation is what matters. ↩

  12. We fixed the β2\beta_2 and not write it explicitly to simplify notation. ↩

  13. Not while training in RTRL, only when doing inference. ↩

  14. Recall that in the LRU the spectral radius is upper bounded by 1. ↩

  15. Here exp⁡\exp denotes element-wise exponential. ↩

  16. Recall that by Euler's identity ∣exp⁡(a+ib)∣=∣exp⁡(a)∣∣exp⁡(ib)∣=∥exp⁡(a)∥\left|\exp(a + ib)\right| = \left|\exp(a)\right|\left|\exp(ib)\right| = \left\lVert \exp(a)\right\rVert. ↩

  17. We drop the subscript jj to simplify notation. ↩

  18. Actually the empirical CCDF i.e the ECCDF ↩

  19. Unless there is a zero element in its diagonal, to be in the safe side and avoid division zero we could an epsilon term ↩

  20. We ignore the time dependence tt since in our model we sample iid noise. ↩

  21. The subscript denotes which value we used for β1\beta_1. ↩

  22. A Normal distribution has finite 4-th moment. ↩

  23. Since we are not using anymore the LRU, this term is not bounded anymore by 1. ↩

  24. Exchanging derivatives in this case can be proved to be correct. ↩