Log In Sign Up

Modular Adaptive Policy Selection for Multi-Task Imitation Learning through Task Division

Deep imitation learning requires many expert demonstrations, which can be hard to obtain, especially when many tasks are involved. However, different tasks often share similarities, so learning them jointly can greatly benefit them and alleviate the need for many demonstrations. But, joint multi-task learning often suffers from negative transfer, sharing information that should be task-specific. In this work, we introduce a method to perform multi-task imitation while allowing for task-specific features. This is done by using proto-policies as modules to divide the tasks into simple sub-behaviours that can be shared. The proto-policies operate in parallel and are adaptively chosen by a selector mechanism that is jointly trained with the modules. Experiments on different sets of tasks show that our method improves upon the accuracy of single agents, task-conditioned and multi-headed multi-task agents, as well as state-of-the-art meta learning agents. We also demonstrate its ability to autonomously divide the tasks into both shared and task-specific sub-behaviours.


page 5

page 6


Shared Multi-Task Imitation Learning for Indoor Self-Navigation

Deep imitation learning enables robots to learn from expert demonstratio...

End-to-End Multi-Task Learning with Attention

In this paper, we propose a novel multi-task learning architecture, whic...

CRIL: Continual Robot Imitation Learning via Generative and Prediction Model

Imitation learning (IL) algorithms have shown promising results for robo...

Compositional Imitation Learning: Explaining and executing one task at a time

We introduce a framework for Compositional Imitation Learning and Execut...

Transporters with Visual Foresight for Solving Unseen Rearrangement Tasks

Rearrangement tasks have been identified as a crucial challenge for inte...

Multi-Task Policy Search

Learning policies that generalize across multiple tasks is an important ...

Automatic Expert Selection for Multi-Scenario and Multi-Task Search

Multi-scenario learning (MSL) enables a service provider to cater for us...

I Introduction

In the field of imitation learning (IL), an autonomous agent learns to perform tasks by mimicking demonstrations provided by an expert [1]. In control settings, there has been significant work tackling imitation of a single task [2, 3], as well as generalising around it [4, 5, 6] in recent years. However, learning multiple tasks separately is not always feasible or ideal, which is why the multi-task learning (MTL) paradigm [7] is used to combine the learning process of many tasks simultaneously. This combination can be challenging, because it not only needs to share commonalities between the tasks so that it performs better than learning them individually (positive transfer), but also avoid sharing unwanted dissimilarities that might hinder training, compared to the individual result (negative transfer) [8]. In our work, we aim to tackle this problem by introducing parallel modules that break down the shareable and non-shareable parts of tasks.

MTL can be particularly useful in deep IL dealing with control problems, since obtaining large expert datasets for robot execution can be challenging and time-consuming [9]. The sharing of knowledge and datasets can not only improve performance, but also reduce the network size, compared to using a separate agent for each task [10]

. This strategy also reduces the number of hyper-parameters requiring tuning during training, since all tasks are trained at once. MTL is also closely related to meta-learning. The objective of meta-learning in MTL and transfer learning (TL) is to find a common representation for all the tasks, so that agents can quickly converge to new tasks from this common point 

[11, 12, 13, 14]. However, this requires all tasks to be similar in the state space and similar in complexity, since it uses a common base policy and does not account for negative transfer. This can be tackled by either combining opposing gradient updates [15, 16], or by using a network which changes architecture based on the task. One way to achieve dynamic architecture is through the use of adaptive networks, which have multiple optional layers – either in parallel [17, 18], sequential [19, 20] or both [21] – and a router that selects which of these layers to activate for each task. This architecture can be particularly beneficial to image problems – especially given the many different types of layers that can be used as experts [18, 22]. However, control problems do not usually use very deep or convoluted architectures, so the benefits from such methods can be limited. But even cases where similar modules are used as streams, such as [23], face additional challenges in control, where the summation of the outputs of all the tasks can lead to erroneous results, since different tasks can have opposing actions.

Fig. 1: MAPS network pipeline. Proto-policy modules operate in parallel using only the state. The selector chooses which to combine based on both state and task.

In our work, we aim to apply the benefits of adaptive architectures and mixture of experts in control problems. Simple policies have been shown to learn short, simple behaviours very well (e.g. reaching an object [24]) but struggle when the tasks become more complicated (e.g. hammering a nail [25, 26], performing acrobatics [27]). Nevertheless, complicated tasks can usually be broken down into shorter, simpler sub-behaviours. Additionally, due to their simple nature, these behaviours are common amongst different tasks. As humans, we can often deduce how tasks can be broken down and the parts that can be shared thanks to our experience, but that can be difficult to model in agents [28, 29]. Also, similarities might not only be present in the task sequences, but in their general execution as well (e.g. performing a similar task in a different environment, or with a different tool). Our method aims to learn these simpler sub-behaviours by modelling them in the form of modular proto-policies.

The primary contribution of our work is a system that performs MTL by breaking down the tasks into sub-behaviours. To achieve this, we use multiple modules that work in parallel independently. Each of these modules is a proto-policy with the capacity to learn a simple behaviour. We also introduce a way to apply adaptive methods, similar to routing, to control problems. This is done by using a selector mechanism that decides how important each proto-policy is for a particular task, given the current state of the environment. The fact the modules learn only based on the current state and not the task means they learn general behaviours of the state-action space. The selector is the one that forces the proto-policies to learn different behaviours, which are either shared between tasks or used exclusively by one task. This way it achieves positive transfer while minimising negative transfer. The number of proto-policies depends on the number of common or different sub-behaviours present in the tasks, meaning a set of similar tasks can be represented with significantly fewer resources than using a separate agent for each task. A pipeline of our system is shown in Fig. 1. Our system is evaluated on 3 different sets of tasks that exhibit similarities in 3 distinct ways. One has commonalities in its sequence (i.e. same model performs different tasks), one in its environment (i.e. different models perform in the same environment) and one in its actions (i.e. same model performs in different environments). Our system shows better performance compared to a single agent baseline, task-conditioned and multi-headed multi-task methods, as well as state-of-the-art meta-learning. Our method also offers deeper understanding of the learning process by visualising the role of each proto-policy separately. Qualitative results of this investigation can be seen in Section IV-B.

Ii Related Work

Deep imitation learning has improved massively over the years [2, 30, 31]. Whilst behavioural cloning (BC) [32] achieved quick convergence, it required a large dataset and had trouble generalising to unseen states. To alleviate this, [2] introduced Generative Adversarial Imitation Learning (GAIL). Although it generalised better, especially with limited datasets, it required interactions with the environment during training. Since then, various works have sought to improve generalisation [4, 5, 6], and even achieve one-shot learning [30, 31]. Similar to our work,  [6] sought to not only imitate, but also segment skills. It achieved this by learning a multi-modal policy, but unlike ours, it did not take negative transfer into account. Since it was based on GAIL, it also required environmental interaction during training.

Meta-learning is closely connected to multi-task learning in control, since it can learn a general representation around a set of tasks. In the field of imitation, one such work is Model Agnostic Meta Learning (MAML), presented in [11] and optimised in [33], where it learnt a common policy for a number of tasks. It then showed this representation point quickly converges to new similar tasks. Whereas this work tried to find one common point between tasks, our work aims to break down tasks into common and uncommon representations. Therefore, it did not accommodate for negative transfer, like ours does. It also required a separate network for every single task. More recently, [12] improved multi-task imitation by utilising the agent’s own experience as it trained. Inspired by one-shot learning [31], it encoded the demonstrations into a task embedding and then evaluated the policy roll-outs based on this embedding. If the roll-outs’ behaviour was similar to the experts, they were added to the embedding. However, this technique required interaction with the environment during training, which can be demanding in control. In terms of modularity, [34] combined meta-learning with modular structures. However, it achieved this by using a set of structures that were dynamically combined to minimise the total loss of tasks. Whereas this can be beneficial in settings that involve a number of layers with potentially different structures, control settings such as the ones in this work have few layers, all of which typically have the same structure.

Adaptive networks have also been used in MTL by adapting their architecture based on the task they are executing. In routing networks, [17] used parallel streams of layers and a router to select which layers to use or skip. While their router was conditioned on each task and input, like our selector, it was applied on every layer sequentially. Our system, on the other hand, trains high level features in parallel and selects them near the end of the pipeline. Additionally, their router was trained using RL, which can be hard to converge, whereas our selector works more like a regulariser that preserves the objectives of MTL and is optimised with gradient descent. Similar to [17], [19] also connected their modules sequentially with no task-division, but updated their router with gradient descent. Using gradient descent to train the router was also performed in [18], which used a number of different types of layers and a router selected the best one based on the task. This is similar to the mixture of experts presented in [22]. In their work, various different types of layers were selected using a gate and were then linearly combined. Whereas our work also combines features from multiple streams, its main difference from these two works is that it does not use modules that are structurally different, instead it aims to help them learn different high level representations. Using modules and BC to break down a task was also the objective of [35]. But while they managed to divide one task, our work aims to extend upon it and cover multiple tasks. The work that mostly relates to us is [21], where they used modules both sequentially and in parallel, with a gating mechanism deciding their contribution. Similar to our objective, they wanted the system to learn sub-categories of images but, unlike us, they had prior knowledge of the different sub-categories, and that is hard to obtain in sequential control data.

Multi-task learning in control

has also been achieved using both imitation and reinforcement learning (RL) 

[36, 37, 38, 39, 40]. However, RL only methods require a reward function for each task rather than expert demonstrations [41], as well as interactions with the environment, which are not necessary with many IL methods. Even the RL methods with limited interactions presented in [42] required additional knowledge. Contrary to meta-learning, [10] tackled MTL in IL and RL by defining the policy as a function of not only the state, but also the task. However, conditioning the entire feature pipeline on the task, as well as using a single fixed policy, can make it hard to adapt to different tasks. This is why we use an adaptive approach that does not condition the features on the task directly. In a similar way, [43] designed a multi-headed MTL system that conditioned only the final features on the task id. Another similarity with our system is that it used many parallel streams of features which are combined at high level. However, all the streams were needed to execute a task, which can be problematic as the number of tasks and streams increases.

Iii Proposed Method


The system is modelled after a Markov Decision Process (MDP). MDPs are expressed with a set of states

, a set of actions

, the probability

that action will lead to state and the reward for taking action . In control settings the states are the environment and the actions are the robot. In RL, the reward needs to be defined. In IL, it might be available to the experts, but is unknown to the imitation algorithms and needs to be inferred. The goal of imitation is to learn a policy

i.e. a probability distribution that produces actions similar to the experts. A demonstration dataset

comprises a number of trajectories and each is a sequence of state-action pairs.

Iii-a Modular Adaptive Policy Selection (MAPS)

Our framework, depicted in Fig. 1, consists of proto-policy modules that operate in parallel. Similar to single-task imitation networks, each module receives , the current state of the environment, but outputs a number of features instead of a distribution. The selection of the modules is performed by a selector network that outputs task-relevant scores , one for each module. The scores are then multiplied with the proto-policy features . After that, the

feature vectors are concatenated and inserted to a probability distribution layer

that transforms them into a distribution of actions , like a policy network. Therefore, the final actions are


This architecture allows for learning primitives independently from specific tasks. This way, a module does not know which - or if any - tasks use it and how much. This leads to modules that learn commonalities between tasks, but also modules that learn features exclusively tailored to one task. Therefore, the system is capable of performing positive transfer, while avoiding negative transfer.

The two parts of the system, the selector and the proto-policy modules, have very distinct roles. The modules learn separate parts of the task space (be it for many tasks or one) and the selector learns which modules should be used by a task and when. These two objectives form the final loss:


The term is the one that learns the tasks by performing the correct actions. The term is a regulariser that ensures positive transfer is performed, while avoiding negative transfer. For the rest of the paper we will be using behavioural cloning (BC) as the imitation technique for , but any other IL technique (e.g. GAIL) can also be used. Since BC minimises the difference between expert and policy actions, the imitation loss can be written as


where the state-action pairs of the expert trajectories . As evident in (3), the partial derivatives with respect to (modules), (selector) and (distribution layer) are interconnected. Therefore, training and jointly allows both of them to benefit from each other.

Iii-B Module Selection

Routing networks have often been used in adaptive networks to determine the architecture used at any given point [17, 19]. However, these are usually applied in a sequential fashion, deciding if a layer will be used or skipped based on the task and the features of the previous layer. In our case, the selector is applied once for all the modules, and its decision is about how important each module is for the current state and task. This is done by producing a significance score that is then multiplied with the features of the corresponding module. The final score of selector is normalised using softmax:


The selector is responsible for deciding which modules to activate, based on the current task and state . Ideally, this decision would be based on which tasks, or parts of tasks, are similar – and should share modules – and which of them are too different and should have dedicated modules for themselves. Unfortunately, such information is not easily obtainable, or even available. To overcome this, our selection mechanism focuses more on the general objective of MTL, rather than specific common characteristics of each task. This objective is broken down into four terms: sharing, exploration, sparsity and smoothness.

Sharing. The objective of this term is to make different tasks share the same modules for the same input state . Therefore, it represents the positive transfer part of MTL. The concept of sharing has been previously presented in [19], where the router encouraged the tasks to share initial layers. We define our term in a similar way, only we have no preference in certain modules and we prefer using the loss to increase robustness and offer better balance with the other losses. The final sharing loss is the mean difference between the scores of all the possible pairs of tasks. For the total number of samples in , it can be described as


Exploration. The objective of this term is to make all modules learn something and avoid mode collapse to one or two modules. This incentivises the system to break the tasks down to multiple – shareable or not – elements. The exploration loss chosen for this term is similar to the importance loss presented in [18] and [22], where the coefficient of variation of a batch is minimised. This ensures that in a batch with samples from all tasks, all modules will be used. Therefore, this loss is applied per batch. For as the trajectories of task , and given that is a distribution and its mean is , the exploration loss can be described as


Sparsity. The objective of this term is to ensure each module learns a distinct part of a task. Using the sharing and exploration terms only, it is still possible for all the tasks to use all the modules uniformly. But that renders the selector useless and the modules indistinguishable. The sparsity loss counters this by making each task use only a small subset of modules. Additionally, the combination of sparsity and exploration enables a module to be exclusively used by one task, thus allowing task-specific learning and that minimises negative transfer. Regarding the loss, while [19] also introduced a sparsity regularisation in the form of log-likelihood, it proved quite unstable in our case. This was due to the logarithmic nature of the loss reaching , which could not be easily balanced with the rest of the terms that minimise at . The Shannon entropy [44]

, on the other hand, proved to be a much more stable choice. However, since sparsity wants to avoid uniform distribution at

, the variable needs to be incorporated in the loss. For this reason, we shift the entropy function so that its maximum lands on the uniform point. This final sparsity loss is


Smoothness. The objective of this term is to provide temporal stability in the selection of modules for each task. This way it avoids erratic module changes between steps. To achieve this, we use the discrete derivative of :


where and the states at time steps and in a trajectory .

The total loss of selector comprises the 4 above-mentioned losses:


It is worth noting that the individual losses compete with each other. Whereas any combination of sharing, exploration and sparsity in pairs makes the loss decrease, the combination of all three makes them compete. This is a manifestation of the opposing MTL objectives of positive transfer without negative transfer. This means careful consideration of the coefficients is required to achieve balance. For example, if we know there are dissimilar tasks, greater emphasis should be given to exploration (e.g. Gravity set in Section IV-A). On the other hand, if all the tasks are executed in a similar manner, greater emphasis should be given to sparsity and sharing (e.g. MT10 set in Section IV-A). The smoothing loss closely relates to sparsity and is necessary for modular consistency. The combination of sparsity and smoothness ensures that each task consistently uses the same few modules, rather than using a single but different module at every step.

Iv Experiments

We evaluate the system under 3 different MTL settings covering environmental, model and task variations. We investigate the success rate and stability of the method against a single agent per task baseline, a multi-task agent conditioned on the task id (MT BC), a multi-task agent with multiple heads, one for each task (MT-MH BC), and MAML, which is a standard meta-learning approach for MTL and TL. We also evaluated the method qualitatively by investigating the features each module learns and if the tasks can be broken down into segments, according to our original hypothesis.

Environmental variation set (HalfCheetah Gravity). This set of 5 tasks involves the same agent, performing the same task, only under different environmental conditions. Specifically, they all involve OpenAI’s [45] HalfCheetah agent running, only under different accelerations of gravity. For as the default HalfCheetah’s gravity acceleration, the 5 different values used are , , , , and . These environments were first introduced in [46]. To obtain the expert Gravity datasets, an RL agent was trained for each task using TRPO [47] and the reward function provided in [46]. It was then used to generate 35 expert demonstrations.

Model variation set (HalfCheetah Modified). This set of 11 tasks involves performing the same task, under the same environment, only using a different model. Specifically, they all involve OpenAI’s HalfCheetah agent running, only the HalfCheetah’s body parts are modified. The model has 5 different body parts, and each of them is enlarged or shrunk by 25% for every task. The body parts include head, torso, thigh, leg, and foot. The original model along with the 5 enlarged and 5 shrunk models make up the 11 tasks of this dataset. Like the Gravity tasks, the Modified environments were introduced in [46] and the 35 expert demonstrations were obtained using an RL TRPO agent.

Task variation set (MT10). This set of 10 tasks involves using the same actor performing different tasks in similar environments. Specifically, the sawyer robot gripper is used to perform different tasks manipulating various objects. These tasks include reach, push, pick and place, press button, insert peg in hole, open door, open drawer, close drawer, open window, and close window. These tasks were first introduced in [24]. The expert datasets were obtained in the course of this work using a human expert that manually executed 20 demonstrations of the tasks in the simulated environments.

The selector has 2 hidden layers, while all the proto-policies used have 3. All layers have 128 features each. Both the modules and the selector are optimised using Adam  [48] with a learning rate of

. The batch size for Gravity and Modified is 128, whereas MT10 uses 32. All the baselines use the same policy structure, optimiser, and batch size as the modules. MAML also uses a meta-batch size of 160 for Gravity and Modified, and 40 for MT10. The hyperparameters used are

=1, =0.1, =0.5, =1 for MT10 and =1, =0.5, =0.001, =1 for Gravity and Modified because sparsity was overpowering the BC loss. All sets use =0.75, =0.25 and the datasets use 70% for training and 30% for validation and tuning. The simulation environment used in this work is Mujoco Pro [49].

Iv-a Quantitative Results

Fig. 2: Aggregated average results of all the tasks in each of the following sets: Gravity (left), Modified (middle) and MetaWorld’s MT10 (right). The runs presented are MAPS with 10 modules, MAML, task-conditioned BC, multi-headed BC and single agent BC over a different number of experts.

We evaluate the performance of our method by unrolling the policies on 100 test initial positions for each task, over multiple seeds. We then measure its highest success rate over various different numbers of experts. The results are normalised with the mean reward of the expert trajectories. We then compare the results with 4 different baselines: independent single BC agents for each task, a multi-task BC agent that uses the task id as auxiliary input, a multi-task BC agent that is multi-headed, and agents trained with MAML and then finetuned on each task (up to 10 updates), as described in [11]. Whereas MAML can be used in both supervised and RL problems, only its RL version was previously tested in control environments [11, 24].

Fig. 3: Number of tasks each method performed better or worse than Single agent BC, normalised by the total number of tasks.
Fig. 4: Ablations with different selector terms on the MT10 set with 10 modules. Top: Bar graphs of the different terms, showing their influence in module selection. Bottom: Success rate of the different terms for different experts. It shows the influence of each term on performance.
Fig. 5: Aggregated average success % of MAPS across all tasks for different number of modules M and experts.

Fig. 2 shows the experimental results on all the tasks of the 3 sets. As a general rule, MAPS with 10 modules (blue) performs significantly better than all the baselines. Additionally, Fig. 3 shows how often the methods perform better or worse compared to the independent BC agent, which has no negative but also no positive transfer. This is done by counting the instances the average performance of a specific task with specific number of experts is better or worse than the single agent BC average performance. This number is then normalised by 104, the total number of different experiment settings (26 tasks under 4 different number of experts). The worst performing one is MAML (orange), which seems to struggle in some tasks, potentially due to them being too different and it being unable to find a single common representation between them. The task-id conditioned MT BC (magenta) performs better than the single agent baseline (green) in most of the tasks, but still suffers from negative transfer in others, as seen in Fig. 3. This is because the baseline relies solely on training to identify the task similarities. Whilst this architecture is more general than MAPS – and can potentially find similarities of any form – it can struggle to do so in sets of tasks that are complex or diverse. In these cases, the network can overfit to one or two tasks, which result to negative transfer for the rest. The MT-MH BC baseline (red) performs worse than MAPS by , but is almost always better than the single agent baseline. This indicates that using both common and task-specific structure is beneficial to multi-task problems. This is seen even more evidently in MAPS, which performs better than the single agent baseline (positive transfer) more than of the time, with of that being a significant (more than ) improvement. This is mainly thanks to the fact MAPS has a significant amount of structure which allows it to have both shareable and task-specific parts.

Fig. 4 details the significance of the various selector terms in the tasks with most variation in the MT10 set using 10 modules. Specifically, it presents the difference in behaviour and performance when one of the terms in removed, compared to MAPS, which uses all of them. The bar graph (top) was produced using only one seed and 10 experts to clearly show the behaviour of each run, whereas the line graphs (bottom) show average performance across multiple seeds and experts. The bar graph shows that by removing sharing, the modules tend to become task-specific, similar to the single agent baseline. By removing exploration, all the tasks end up using only one module, similar to the MT-BC baseline. This is why it is the most important term for the MT10 set in terms of performance. Sparsity, on the other hand, is responsible for making modules task-specific, and its absence also leads to negative transfer. Finally, smoothing has the least impact on performance, since it is there mainly to stabilise sparsity and avoid abrupt module changes.

Fig. 5 shows a heatmap with ablation studies of MAPS with various numbers of modules. The only case where a greater number of modules than tasks was beneficial was in the Gravity set. The other sets’ performance seems to plateau at . This practically shows how the number of modules should not depend on the number of tasks, but rather the similarities between them. In the MT10 set, where we expect more similarities between the tasks, we see the success of is comparable to the one of . Therefore, even with half the size of the single agents’ resources, MAPS can still achieve better performance.

Iv-B Qualitative Module Understanding and Task Breakdown

We also evaluate how well MAPS manages to break down task behaviour in the MT10 set. Fig. 6 (left) presents the occurrence of every module in each individual task. This shows the influence of the selector losses, as well as the common or task-specific nature of the modules.

Fig. 6: Break down of the MT10 tasks with 10 modules (left) and visual examples of individual modules (right). Tasks window-open and drawer-close share “grab handle” and “move forward” modules. Task drawer-open shares but uses as a task-specific “move backwards” module.

The Fig. 6 bar graph shows our initial hypothesis is correct and tasks are composed of shareable modules, task-specific modules, or a combination of the two. An example of this is the subset of window-open, drawer-open, and drawer-close tasks. These tasks use both shareable and task-specific modules. The most similar tasks are window-open and drawer-close, which use the same modules and . An example of applying these modules individually on each task can be seen in Fig. 6 (right). The figure shows these two modules have learnt two distinct behaviours: (orange) has learnt to reach (and grab when possible) the handle, and (blue) has learnt to move forward and reach the target. It is very encouraging then that drawer-open also uses to perform the “grab the handle” sub-behaviour. However, its movement after that needs to be backwards, compared to the forward movement of . Therefore, this movement is learnt in a different module (magenta), which is task-specific for drawer-open. This behaviour demonstrates how MAPS can perform positive transfer, while avoiding negative transfer. Finally, Fig. 6 also shows how the combination of all the modules produces a successful trajectory. It should be noted that even though the sub-behaviour “grab the handle” is a natural movement for humans, it is there only because it was present in the trajectories performed by the human expert. Only in the drawer-close task is enough to succeed, which is more likely what an RL agent would have learnt. However, MAPS is capable of also finding and modelling minute sub-behaviours that make the trajectories look more natural. 44footnotetext: Video examples at

V Conclusion and Future Work

We present a new method of imitation in multi-task control problems by breaking down the tasks into distinct sub-behaviours. To achieve this, we use an modular architecture that utilises a multitude of independent proto-policy modules and a selector that forces them to cooperate. Our experiments show that this method can be used in various different MTL settings and can not only improve the success rate, but also reduce the resources required, compared to using separate agents. We also show how the proto-policies can be evaluated individually by qualitatively analysing their behaviour. This indicates that MAPS can also offer a better understanding of what is being learnt in every module, something that is not always easy to do in neural networks 


As a future extension of our work, we would like to see it used in transfer learning problems as well, where the already-learnt modules are used on new tasks. Another extension would be to use MAPS with other IL methods like GAIL. Finally, while this work achieves general task decomposition, we would like to see it extended to structured decomposition by combining it with hierarchical RL [51, 52, 53].