Computer Science Biology
Computer Science-2021.gz:143227
Computer Science
b1b9f680da032028eff377e2cda6e24538ba6381
Efficient and robust multi-task learning in the brain with modular latent primitives

Biological agents do not have infinite resources to learn new things. For this reason, a central aspect of human learning is the ability to recycle previously acquired knowledge in a way that allows for faster, less resource-intensive acquisition of new skills. In spite of that, how neural networks in the brain leverage existing knowledge to learn new computations is not well understood. In this work, we study this question in artificial recurrent neural networks (RNNs) trained on a corpus of commonly used neuroscience tasks. Combining brain-inspired inductive biases we call functional and structural, we propose a system that learns new tasks by building on top of pre-trained latent dynamics organised into separate recurrent modules. These modules, acting as prior knowledge acquired previously through evolution or development, are pre-trained on the statistics of the full corpus of tasks so as to be independent and maximally informative. The resulting model, we call a Modular Latent Primitives (MoLaP) network, allows for learning multiple tasks while keeping parameter counts, and updates, low. We also show that the skills acquired with our approach are more robust to a broad range of perturbations compared to those acquired with other multi-task learning strategies, and that generalisation to new tasks is facilitated. This work offers a new perspective on achieving efficient multi-task learning in the brain, illustrating the benefits of leveraging pre-trained latent dynamical primitives.


Introduction
A large body of work has shown that computations in the brain -implemented by the collective dynamics of large populations of neurons -can be modeled with recurrent artificial neural networks (RNNs) [48,61,76,60,35,80,10,58,71,45,70,3,8,69]. Along these lines, many investigations of the mechanisms underlying computations in the brain have been performed by training RNNs on tasks inspired by neuroscience experiments. In particular, recent studies [20,76] have proposed ways in which RNNs could learn multiple tasks while reusing parameters like biological agents do. However, in all of them, models start with no pre-existing knowledge about the world and need to learn all the shared parameters incrementally by seeing each task, one by one. Notably, this scenario, Preprint. Under review. often studied in deep learning under continual learning, is not exactly one in which biological agents usually operate.
Indeed, when faced with a new task, animals have access to varying amounts of pre-existing inductive biases acquired over large timescales : evolutionary [17,61] as well as those within their lifetime [6,73]. These biases are assumptions about the solution of future tasks based on heredity or experience : something really useful for biological agents who often inhabit particular ecological niches [9] where a substantial structure is shared between tasks. In this work, we explore how the common statistics of a corpus of tasks -standing in for the knowledge acquired through long timescalescould be encoded into an RNN in a biologically inspired way, and then leveraged to enable learning multiple tasks sequentially more efficiently than in traditional continual learning scenarios.
One way in which inductive biases can be expressed in the brain is in terms of neural architecture or structure [61]. Neural networks in the brain may come with a pre-configured wiring diagram, encoded in the genome [79]. Such structural pre-configurations can put useful constraints on the learning problem by forcing the representations to have a desirable structure. For example, a neural network made up of different specialized modules encourages the learning of independent and reusable knowledge, which leads to better generalization [54]. Moreover, modularity is known to increase the overall robustness of networks since it prevents local perturbation from spreading and affecting the dynamics too much [11]. Previous neuroscience studies have shown that the brain exhibits specializations-and thus, modularity-across various scales [19,68,74,26,47,46]. For example, visual information is primarily represented in the visual cortices, auditory information in the auditory cortices, decision-making in the prefrontal cortex-each of these regions being further comprised of cell clusters processing particular kinds of information [48,10,45].
Another way in which inductive biases may be expressed in the brain, beyond structure, is in terms of function : the specific neural dynamics instantiated in particular groups of neurons. Indeed, typical computations can be learned once and then recombined in subsequent tasks to enable more efficient learning; there is evidence that the brain implements such stereotyped dynamics [16,64]. Mixing in structural inductive biases, these generic functional dynamics are often local to a certain group of neurons, forming modules [55,68,5,57,46] that can perform different aspects of a task [37,76,10]. Thus, a network that implements modular functional primitives, or basis-computations, could offer dynamics useful for training multiple tasks.
Here, we investigate the advantages of combining structural and functional inductive biases with a modular RNN for learning multiple tasks efficiently. Specifically, our model learns a corpus of 9 different tasks from the neuroscience literature by building on top of shared, frozen latent modules. These modules are pre-trained to produce simple computations that constitute shared operations of the task ensemble. We achieve this by requiring modules to pre-learn leading canonical components of transformations required by the corpus as a whole, thus producing a provably disentangled and maximally informative latent representation (i.e., explaining the most covariance between input and outputs). Importantly, we conceptualize the pre-trained dynamics as being acquired through evolution [17] or another biologically instantiated meta-learning process [6,73], providing a biologically plausible way to access the shared statistics of many tasks encountered throughout the life of an animal. This enables representations that factorize across tasks (instead of the task-specific features usually obtained in a continual learning scenario [76]). Afterward, the different tasks can be learned sequentially simply by using task-specific output heads. We call the resulting model a Modular Latent Primitive (MoLaP) network.
Altogether, we show that by leveraging aplastic functional modules fitted on a corpus' shared statistics, our system is able to sequentially learn multiple tasks more efficiently than in typical continual learning approaches [76,20]. Also, we demonstrate that our model is more robust to perturbations: a desirable property that biological organisms are remarkably good at [4,15,24,75], compared to artificial systems, which are relatively sensitive [72]. Notably, even including pre-training, our method requires fewer total parameter updates to learn an entire corpus, compared to leading models of biologically plausible multi-task learning. Finally, we show that generalization to new tasks that share basic structure with the corpus is also facilitated. This draws a path towards cheaper multitask solutions, and offers new hypotheses for how continual learning might be implemented in the biological brain.
2 Relation to prior work

Recurrent neural networks
Similar to the brain, computations in a RNN are implemented by the collective dynamics of a recurrently connected population of neurons [38]. In fact, when trained on similar tasks as animals, RNNs have been shown to produce dynamics consistent with those observed in animals; they can therefore serve as a proxy for computational studies of the brain [48,61,76,60,35,80,10,58,71,45,70,3,8,69]. Thus, by showing the benefits of pre-trained recurrent modules in RNNs, we offer a hypothesis for how multi-task learning is implemented in the brain.
While classic RNNs are trained with backpropagation through time (BPTT), reservoir computing approaches such as echo-state networks (ESNs) and liquid-state machines (LSMs) [53,34,42] avoid learning the recurrent weights of the network and instead only learn an output layer on top of a random high-dimensional expansion of the input produced by a random RNN called a reservoir. This avoids common problems that come with training RNNs [31] and can increase performance while significantly lowering the computational cost [53,34,42]. Our approach mixes both plastic RNNs and reservoir architectures, as modules can be seen as non-random reservoirs initialized to be maximally informative and performing independent computations in isolation.
The use of connected modules in RNNs is motivated by the fact that dynamical processes in the world can usually be described causally by the interaction between a few independent and reusable mechanisms [54]; modularity in RNNs -which doesn't emerge naturally [14] -has been shown to increase generalization capabilities [27,28,65,40,30,33,33,62].

Learning multiple tasks
In Multi-Task Learning (MTL) [13], the model has access to the data of all tasks at all times and must learn them all with the implicit goal of sharing knowledge between tasks. Typically, the model is separated into shared and task-specific parts which are learned end-to-end with gradient descent on all the tasks jointly (batches mix all the tasks). While we do require information about all tasks simultaneously for our pre-training step, how we do so sets us apart from other MTL methods. Indeed, the modules are trained on (the first few canonical components of) the shared computation statistics of the tasks rather than directly on tasks themselves; and we argue this offer a more realistic account of optimization pressure animals are subject to over long timescales (e.g., evolution or development). Most previous MTL studies using RNNs focus on NLP or vision tasks. The most similar to our approach is [76], which uses the same set of cognitive tasks we do, but does not use modules and trains shared parameters end-to-end jointly on all tasks.
Meanwhile, in Continual Learning (CL) [29,78,1,51,25,77,67,66,80,36,81,41,18,63,12], the system has to learn many different tasks sequentially and has only access to task-relevant data, one at a time. The main focus of this line of work is to alleviate the hard problem of catastrophic forgetting that comes with training shared representation sequentially [39,23,59]. We avoid this issue completely by assuming the pre-existence of aplastic modular primitives provided by statistical pre-training; all our shared parameters are frozen. Indeed, once the modules are set, our work can be conceptualized as continual learning since the tasks' output heads are learned sequentially. Note that other CL methods freeze previously learned parameters to avoid interference [63,44], but they do so one task at a time. Therefore, frozen representations end up being task-specific rather than factorized across tasks like ours; which hurts their efficiency. Closest to our approach is [20] in that they consider the same tasks, however, they learn the shared parameters progressively in orthogonal subspaces to protect them from interference. We use them as our main point of comparison to show the benefits of our approach over typical CL.
Finally, in Meta-Learning [32], a single model learns to solve a family of tasks by learning on two time-scales. In particular, in gradient-based meta-learning [21,49], a network initialization which is good for all tasks is learned over many meta-training steps, speeding up the training of new tasks. The pre-training of the modules on the joint statistics of the corpus in our system has a similar motivation: acquiring primitive latent representations useful across tasks to speed up learning of individual tasks.

Relationship with hierarchical reinforcement learning
Works in Hierarchical Reinforcement Learning (HRL) [52] also use so-called primitive policies in order to solve (sometimes multiple [2]) decision making tasks. In this case, the primitives are complete policies pre-trained to perform some basic action (e.g., move to the right) and they are composed sequentially (in time) to perform complex tasks. In our case, the primitives are combined in a latent space by the output layer, thus achieving a different type of compositionality. We also use a supervised learning objective to train our model. Task-specific readout weights (plastic) Task-specific input weights (plastic )   T1  T3 T4 T5 T6 T7 T8 T9  T2  T1  T3 T4 T5 T6 T7 T8 T9  which are used to pre-train separate network modules. B. During task training, recurrent weights remain frozen and only input and readout weights are adjusted. Task-specific responses can be obtained via separate readout weights. C. Parameter overview for the various multi-task training methods. Parameters trained (or updated) and total network size is compared across the three methods. MoLaP makes ∼ 2 orders of magnitude fewer parameter updates than DNI, at a relatively moderate increase of total parameter count.

Model and experimental details 3.1 Modularity
Our network is based on an RNN architecture with hidden state h that evolves according to with activation function σ = tanh, external input x i t , uncorrelated Gaussian noise η i t , and linear readouts y i t . Inputs enter through shared weights and outputs are read out through dedicated weights. Modules are embedded within the larger network with module size N M = N T otal /n M , total number of units in the network N T otal = 100, and number of modules n M = 2 throughout this paper. Modules are inter-connected with the reservoir, but not directly to each other ( Figure 1A). Starting from an initial state, with weights drawn from a Gaussian distribution, each module is trained to produce a module-specific target output time series z t by minimizing the squared loss using the Adam optimizer (see A for more details). Module-specific inputs and targets are obtained via canonical correlation analysis (CCA; Figure 1A; see section 3.3).
In the pre-training phase ( Figure 1A), intra-module weights are plastic (unfrozen) while intermodule weights remain aplastic (frozen). Modules are trained sequentially on latent primitives (see Section 3.3) such that only intra-module connections of the module currently being trained are allowed to change, while the others remain frozen. The gradient of the error, however, is computed across the whole network. Thus for the case outlined in Figure 1, for example, module 1 (M1) is trained first, followed by modules 2 (M2) and 3 (M3). When M1 is being trained, only connections inside of M1 are allowed to change, while the connections in the rest of the network remain frozen. After that, M1 connections are frozen, and M2's intra-module connections are unfrozen for training.

Tasks
Neuroscience tasks [76], like the ones we employ here (explained in greater detail in A.1), are structured as trials, analogous to separate training batches. In each trial, stimuli are randomly drawn, e.g., from a distribution of possible orientations. In a given trial, there is an initial period without a stimulus in which animals are required to maintain fixation. Then, in the stimulus period, a stimulus appears for a given duration and the animal is again required to maintain fixation without responding. Finally, in the response period, the animal is allowed to make a response.

Deriving latent primitives
We derive inputs and targets for pre-training directly from the entire corpus of tasks by leveraging canonical correlation analysis (CCA; Figure 1A): In CCA, we seek A and B such that the correlation between the two variables X (task inputs) and Y (task outputs) is maximized. We then obtain the canonical variates U and V by projecting A and B back into the sample space of inputs and outputs, respectively, with n: number samples and r: number of latent dimensions. The canonical variates are used to pre-train the modules (3.1), with latent dimensions r = 1, 2, 3, .. corresponding to module numbers M = 1, 2, 3, ... (Figure 1A).

Task training
In the task-training phase ( Figure 1B), recurrent weights remain aplastic (like in reservoir computing) and only input and output weights are allowed to change. Task-specific input (W in ) and readout weights (W out ) are trained by minimizing a task-specifc loss function (Eq 1). Separate linear readouts are used to obtain the outputs of the network (see A.2 for details):

Results
Training multiple tasks with separate networks requires a high total number of parameters (as separate networks are used for each task) as well as a high number of parameter updates (as all of the network parameters are updated for each task). Thus, assuming a corpus of 9 tasks, a network size of 100 units, one input and one readout unit, naively training separate networks takes 9.18e5 parameters and parameter updates (Table 1-Separate networks). In contrast, using recently proposed dynamical noninterference (DNI; [20]), one network is trained to perform all tasks; however, all of the parameters still need to be updated on each task as the shared representations are learned sequentially. Thus, DNI still requires 9.18e5 parameters to be optimized (Table 1-DNI).
Similar to DNI, our approach (MoLaP) uses one network to perform all tasks; but MoLaP keeps both the total number of parameters, and the number of parameter updates low ( Figure 1C-MoLaP). With MoLaP, the number of necessary parameter updates is ∼ 2 orders of magnitude smaller compared to DNI and independent network approaches, with only a relatively modest 18% increase in total parameter count compared to DNI ( Figure 1C, Table 1). This arises from using shared reservoirs pre-trained on the joint statistics of the task corpus.  Despite low parameter update requirements, using MoLaP, we achieve similar performance to both independent networks and DNI (Figure 2), with successful learning (> 70% decisions correct) across all 9 tasks (Figure 2A,B). To further investigate the role of latent primitive representations in MoLaP, we also compared a MoLaP version without pre-training (using randomly initialized modules like in reservoir computing), and a version using principal components analysis (PCA) instead of CCA to obtain latent inputs and targets for pre-training (Figure 2A). PCA offers an alternative way to derive latent primitives, and differs from CCA by successively maximizing the variance in the latent dimensions separately for inputs and outputs. The distinction is that PCA extracts a lowdimensional space from a single dataset (the covariance matrix), while CCA explicitly extracts modes that maximize variance across variables (the cross-covariance matrix; see also A for further details). This feature turns out to be crucial for deriving useful latent primitives.
Performance is more similar for easier tasks (T1-T4) than for more complex tasks (T5-T9), where flexible input-output mapping is required [19]. However, only MoLaP achieves the highest performance across all tasks. We show the performance of the trained MoLaP network with pre-training ( Figure 2D) and without ( Figure 2E) on task T7 (context-dependent memory task 1, see A.1 for task details). With pre-training, both readout variables hit the target (Figure 2Da

Perturbations
We analyzed performance after modular weight lesion for the different approaches, here shown for task T9 (Figure 3; see Figure S1&Figure S2 for a complete overview of tasks T1-T9)). Weights are "lesioned" by picking a percentage of entries W i,j rec from the connectivity matrix (Equation 1) and setting them to zero. With module 1 (M1) weights lesioned, MoLaP performance remained high when < 10% of the intra-module weights were lesioned, above that of DNI and comparable to separately trained networks ( Figure 3A). With module 2 (M2) weights lesioned, MoLaP performance remained high even at a higher percentage of intra-module weights lesioned, above that of DNI and separate networks ( Figure 3B). When plotting outputs of MoLaP at 30% of the M2 weights lesioned, we observed that the output signal of output unit 1 remained high, resulting in a higher percentage of correctly decoded decisions on average (Figure 3Bb,d) compared to when M1 was lesioned (Figure 3Ab,d). This can be explained by the fact that the first dimension of the canonical variables (on which M1 was trained) captures a higher percentage of the variance between inputs and targets than the second dimension (on which M2 was trained). Hence, when M2 is lesioned, M1 is still able to compensate and performance is preserved.
We also considered the effect of lesioning inter-module connections ( Figure 3C). Performance degrades quickly when inter-weights are lesioned, for all approaches. When plotting outputs of MoLaP at 30% inter-module connections lesioned, we observed that the combined error across output variables is higher compared to lesioning intra-module weights (Figure 3Cb-e). Based on this we would predict that cutting connections between areas is far more devastating than killing a few units within an area.
Furthermore, we analyzed performance after a number of different global perturbations (Figure S3, Figure S4, Figure S5). We considered three different global perturbations: lesioning entries in the connectivity matrix, adding global Gaussian noise to the entire connectivity matrix, and silencing activity of units in the network (by clamping their activity at zero). All perturbations are repeated for 30 random draws.
We found that on simpler tasks such as T1 ( Figure S5A), all approaches perform similarly for the various global perturbations (see Figure S3&Figure S4 for all tasks). DNI performed somewhat better than the other approaches on simpler tasks when weights and activity were lesioned ( Figure S5A,C), and somewhat worse than other approaches when noise was added globally ( Figure S5B). On more complex tasks such as T7 ( Figure S5B), however, we found that MoLaP was more robust to global perturbations. MoLaP performance remained higher compared to other approaches when up to 10% of connections were lesioned ( Figure S5Ba) or when up to 10% of units were silenced (Figure 4Bc). MoLaP performance was also robust to global noise, even at relatively high levels ( Figure S5Bb).
Over the space of all the tasks we consider, we found that MoLaP performed better than the other approaches for all the perturbations under consideration (Figure 4).

Generalization
Finally, we analyzed the generalization performance of MoLaP by holding out each tasks, in turn, from the entire corpus used to derive the canonical variables for pre-training ( Figure 5; see section 3 for details). We found that performance generalized to the left-out task relatively well, achieving higher performance than pre-training on the complete corpus using PCA (see Figure 2). We also observed some task-specific effects; performance on T7 was relatively worse when it was left out from the corpus of tasks used in pre-training, compared to when other tasks were left out. Even when two tasks were left out, MoLaP dynamics still generalized well with performance remaining high on the majority of tasks. See Appendix A for details on 2-tasks hold out protocol. Performance (% decisions correct on a 2000-trial test set) for all tasks, after pre-training with CCA where all tasks were included (grey), pre-training with CCA where one task (dark blue) or two (light blue) tasks were left out, and pre-training with PCA where one task (dark green) or two tasks (light green) were left out. For leave-one-out, the left-out task corresponds to the task depicted on the x-axis. For leave-two-out, the task depicted and the one immediately next on the right were left out (in the case of T9, both T9 and T1 were left out).

Discussion
We present a new approach for multi-task learning leveraging pre-trained modular latent primitives that act as inductive biases acquired through evolution or previous experience on shared statistics of a task corpus. The modules are inspired from organization of brain activity and provide useful dynamics for solving a number of different tasks; including those that are not in the corpus used for pre-training, but share some structure with it (i.e., generalization). We showed that our approach achieves high performance across all tasks, while not suffering from the effects of task order or task interference that might arise with other continual learning approaches [20,81]. Crucially, our approach achieves high performance with ∼ 2 orders of magnitude fewer parameter updates compared to other approaches (even including the pre-training phase) at the cost of only a moderate increase in the number of total parameters. MoLaP scales better with tasks, thus reducing overall training cost.
Our results also show that networks composed of pre-trained task modules are more robust to perturbations, even when perturbations are specifically targeted at particular modules. As readouts may draw upon dynamics across different modules, task performance is not drastically affected by the failure of any one particular module. The lower performance of the fully connected modular network may be due to the trained connection weights, which increase the inter-connectivity of different cell clusters and thus the susceptibility of local cell clusters to perturbations in distal parts of the network. This result generates useful hypotheses for multi-task learning in the brain. It suggests that decisionmaking related circuits in the brain, such as in the prefrontal cortex, need not re-adjust all weights during learning. Rather, pre-existing dynamics may be leveraged to solve new tasks. This prediction could be tested by using recurrent networks fitted to population activity recorded from the brain [56,50] as reservoirs of useful dynamics. We hypothesize that the fitted networks contain dynamics useful to new tasks; if so, it should be possible to train readout weights to perform new tasks. Moreover, targeted lesions may be performed to study the effect of perturbations on network dynamics in the brain; our work suggests networks with functional task modules are less prone to being disrupted by perturbations. Based on our work we would also expect functional modules to encode a set of basis-tasks (commonly occurring dynamics) for the purpose of solving future tasks.
In a recent study, [22] examined the effects of 'rich' and 'lazy' learning on acquired task representations and compared their findings to network representations in the brain of macaques and humans. The lazy learning paradigm is similar to ours in as far as learning is confined to readout weights; but it lacks our modular approach and does not show performance on multiple tasks. Conversely, our networks are not initialized with high variance weights as in the lazy regime. Ultimately, we observe improved robustness using our approach, unlike lazy learning which appears to confer lower robustness compared with rich learning. This work enhances our understanding of resource-efficient continual learning in recurrent neural networks. As such, we do not anticipate any direct ethical or societal impact. Over the long-term, our work can have impact on related research communities such as neuroscience and deep learning, with societal impact depending on the development of these fields.

A.1 Tasks
We show that we can leverage our pre-configured modular network to learn a set of nine different neuroscience tasks, previously used to study multi-task learning [76,20]. Trained simultaneously into one and the same network, these tasks produce a rich and varied population structure and are mapped into different parts of state space [76]. Simultaneous training, however, does not guarantee good performance on all tasks; this can be improved by using a multi-task training paradigm whereby new tasks are projected into non-interfering subspaces [20]. This approach is still dependent on task order, however: how well a new task is learnt often depends on its placement in the training curriculum.
We employ a set of nine different tasks: Delay Pro, Delay Anti, Mem Pro, Mem Anti, Mem Dm 1, Mem Dm 2, Context Mem Dm 1, Context Mem Dm 2 and Multi Mem. In Delay Pro and Delay Anti, the network receives three inputs (Fixation, cos(θ), sin(θ), with θ varying from 0-180 degrees). The angle inputs turned on at the Go-signal and remained on for the duration of the trial. The network was required to produce three outputs, yielding the correct location during the output period (when the fixation signal switched to zero). In the anti-versions, the network is required to respond in the direction opposite to the inputs. In Mem Pro and Mem Anti, the input stimulus turns off after a short, variable duration. As before, the network is required to produce three outputs encoding the correct location during the output period.
In Mem Dm 1 and Mem Dm 2, the network receives two inputs (Fixation, and a set of stimulus pulses separate by 100msec). The network is required to reproduce the higher valued pulse during the output period. Depending on the task, the network receives one or the other input stimulus pulse set.
In Context Mem Dm 1 and Context Mem Dm 2, the network receives three inputs (Fixation, and two sets of stimulus pulses). The network is required to reproduce the higher value pulse during the output period, ignoring the other input stimulus set. The two tasks differ in which input stimulus to pay attention to. In Multi Mem, the network again receives three inputs (Fixation, and both sets of stimulus pulses). The network needs to yield the summed value of the stimulus train with the higher total magnitude of the two pulses.
In models, a context signal indicates when to maintain fixation, separate inputs are fed in through different channels with dedicated input weights, and the choice can be indicated (and decoded) from separate output units for each target.

A.2 Training details
All networks were trained on a single laptop with the Apple M1 Max processor using a custom implementation of recurrent neural networks based on JAX [7]. The code to train MoLaP networks can be found at https://github.com/dashirn/MoLaP. We used a recurrent neural network (RNN) model with the hyperbolic tangent as the activation function throughout (σ = tanh, Equation 1), in accordance with previous approaches to modeling neuroscience tasks [48,10,45]. Previous work suggests the dynamics obtained with different activation functions, such as tanh or ReLu, and different network models such as RNNs, GRUs and LSTMs are similar [43]. All networks were trained by minimizing the mean squared error using Adam as an optimizer. We used a custom implementation of DNI ( [20]) leveraging the same setup as above based on JAX; we also compared our results with those obtained from the native implementation (available at https://github.com/ LDlabs/seqMultiTaskRNN under a MIT license), and obtained similar results.
We performed a gridsearch over various parameter ranges (Table 2), and settled on the parameter combination that worked best across all training paradigms. We used a network of N = 100 for MoLaP and separate networks, and N = 200 for DNI.

A.2.1 Pre-training
The canonical correlation analysis (CCA) model was fitted to inputs and outputs across the entire corpus of tasks for the entire training set simultaneously, and then divided into separate batches for training. We found that two latent dimensions in the canonical variables (U and V , see (2)) captured ≈ 60% of the variance in the relationship between inputs and targets, while three captured ≈ 70%. We also fitted MoLaP networks with three modules and found they portrayed similarly to the results For pre-training the recurrent network in MoLaP, we set the learning rate at α = 3e − 3, with a batch size of 200 trials, the scaling factor at g = 1.5, the L2-norm weight regularization parameter at 1e-5, the activity regularization parameter at 1e-7, and the number of iterations at 200. Each module was trained separately, with the number of units set at N M 1 = N M 2 = 50. When a particular module was being trained, all other connections in the network remained frozen (information from the error gradient was prohibited from updating frozen units). So, for example, during training of module 1 (M1), all connections except those within module remained frozen. After M1 pre-training was complete, M1 connections were frozen M2 connections were unfrozen.

A.2.2 Pre-training with PCA
Alternatively, we also used principal components analysis (PCA) to derive inputs and outputs for pretraining. PCA was performed on the entire corpus of tasks for the entire training set simultaneously, separately for inputs and targets across all tasks. We thus obtained input and output vectors in the reduced space which we used analogously to CCA to train each module sequentially.

A.2.3 Task-training
In MoLaP, after pre-training, all connections in the recurrent weight matrix were frozen and only input and readout weights were allowed to change. Task-specific input and readout weights were trained for tasks T1-9.
For task-training in MoLaP, we set the learning rate at α = 1e − 2 for all networks, the batch size at 200 trials, the scaling factor at g = 1.5, the L2-norm weight regularization parameter at 1e-5, the activity regularization parameter at 1e-7, and the number of iterations at 200. Task-training in separate networks and with DNI only differed in that we set the learning rate at α = 3e − 3 which we found worked best.
Across all approaches, the weights in the recurrent weight matrix, W rec (Equation 1), were initially drawn from the standard normal distribution and scaled by a factor of g √ N . The input weights, W in , were also initially drawn from the standard normal distribution and scaled by a factor of 1 √ Nin with N in varying by task. Each input unit also received an independent white noise input, η i , with zero mean and a standard deviation of σ = 0.002. Output weights, W out , were also initially drawn from the standard normal distribution and multiplied by a factor of 1 √ Nout with N out varying by task.

A.3 Task performance
In order to measure task performance, a test set of 2000 trials was randomly generated from a separate random seed in JAX for each task. Performance was calculated as the percentage of correct decisions over this test set. Decisions, rather than other error metrics such as mean squared error, were chosen as a performance metric as they reflect the ultimate goal of biological agents. For all output units other than unit 1, a decision was considered correct if the mean output over the response period did not deviate more than a fixed amount (δ = 0.1) from the target direction. For output unit 1 (which indicated if fixation was maintained throughout the task), a deviation of (δ = 0.1) was permitted. For all output units, the response was decoded by taking the mean across the last 30 time points (response period) in a given trial. Performance was averaged across all output units.

A.4 Perturbation studies
We considered 3 types of perturbations: lesioned weights, silenced activity, and added Gaussian noise. In the case of lesioned weights, perturbations were performed both in a modular and in global fashion. In modular perturbations, connections to lesion were picked randomly from within modules only, or from among inter-modular connections ( Figure S1, Figure S2). Global perturbations involved all the units in the network ( Figure S3, Figure S4, Figure S5). Weight lesioning was performed by setting chosen connections to zero. Activity silencing was performed by silencing the activity of chosen units. Gaussian noise of different variance σ ∈ [0, 0.03] was added to the entire connectivity matrix. All perturbations were repeated for 30 different random draws.