summaries: This work seeks to efficiently learn new tasks by combining meta-RL and imitation learning (IL). Such a combination is a natural thing to try, as both lines of work improve sample complexity of learning a new task: meta-RL by leveraging experience on prior related tasks, and IL by leveraging demonstrations. Demonstrations also form a natural way of specifying a new task to the agent. This work proposes PERIL, a method for combined Meta Imitation Learning and Meta Reinforcement Learning using context-based meta-learning. Given a set of demonstrations, a latent variable representing the desired task is inferred, and trajectories are generated conditioned on the inferred latent variable.  The data from the expert demonstrations and trajectories are used for meta-learning updates. This paper introduces PERIL, a meta RL method that combines demonstration trajectories and trajectories collected by the policy, in order to adapt to a new task. To this end, the authors combine ideas from metaRL (specifically from PEARL (Rakelly et al. 2019) and Humplik et al (2019)) where a set encoder is used to encode trajectories to a latent vector describing the task, with imitation learning techniques by (a) training this encoder also with demonstrations (b) initialising the latent vector at test time by feeding demonstrations through the encoder, and (c) having additional losses inspired by metaIL techniques. The motivation is that using demonstrations allows us to learn tasks that are difficult otherwise, for example because the rewards (at test time) are sparse. 
abstractText: Imitation learning is a natural way for a human to describe a task to an agent, and it can be combined with reinforcement learning to enable the agent to solve that task through exploration. However, traditional methods which combine imitation learning and reinforcement learning require a very large amount of interaction data to learn each new task, even when bootstrapping from a demonstration. One solution to this is to use meta reinforcement learning (meta-RL) to enable an agent to quickly adapt to new tasks at test time. In this work, we introduce a new method to combine imitation learning with meta reinforcement learning, Probabilistic Embeddings for hybrid meta-Reinforcement and Imitation Learning (PERIL). Dual inference strategies allow PERIL to precondition exploration policies on demonstrations, which greatly improves adaptation rates in unseen tasks. In contrast to pure imitation learning, our approach is capable of exploring beyond the demonstration, making it robust to task alterations and uncertainties. By exploiting the flexibility of meta-RL, we show how PERIL is capable of interpolating from within previously learnt dynamics to adapt to unseen tasks, as well as unseen task families, within a set of meta-RL benchmarks under sparse rewards.
references.authors: Yan Duan John Schulman Xi Chen Peter L Bartlett Ilya Sutskever Pieter Abbeel
references.title: Under review as a conference paper at ICLR 2017 RL 2 : FAST REINFORCEMENT LEARNING VIA SLOW REINFORCEMENT LEARNING
references.venue: Technical report
references.authors: Chelsea Finn Pieter Abbeel Sergey Levine
references.title: Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks
references.venue: Technical report,
references.authors: Abhishek Gupta Russell Mendonca YuXuan Liu Pieter Abbeel Sergey Levine
references.title: MetaReinforcement Learning of Structured Exploration Strategies
references.venue: Advances in Neural Information Processing Systems, 2018-December:5302–5311,
references.authors: Jan Humplik Alexandre Galashov Leonard Hasenclever Pedro A. Ortega Yee Whye Teh Nicolas Heess
references.title: Meta reinforcement learning as task inference
references.venue: URL http://arxiv
references.authors: Gerrit Schoettler Ashvin Nair Juan Aparicio Ojea Sergey Levine Eugen
references.title: Solowjow. MetaReinforcement Learning for Robotic Industrial Insertion Tasks
references.venue: URL http://arxiv
references.authors: Mel Vecerik Todd Hester Jonathan Scholz Fumin Wang Olivier Pietquin Bilal Piot Nicolas Heess Thomas Rothörl Thomas Lampe Martin Riedmiller
references.title: Leveraging Demonstrations for Deep Reinforcement Learning on Robotics Problems with Sparse Rewards
references.authors: Hanlei Wang
references.title: Adaptive Control of Robot Manipulators With Uncertain Kinematics and Dynamics
references.venue: Technical report,
references.authors: Haozhe Wang Jiale Zhou
references.title: Learning Context-aware Task Reasoning for Efficient Metareinforcement Learning KEYWORDS Multitask Learning; Deep Reinforcement Learning
references.venue: Technical report,
references.authors: Henry Zhu Justin Yu Abhishek Gupta Dhruv Shah Kristian Hartikainen Avi Singh Vikash Kumar Sergey Levine
references.title: The Ingredients of Real-World Robotic Reinforcement Learning
sections.heading: 1 INTRODUCTION
sections.text: Reinforcement Learning (RL) and Imitation Learning (IL) are two popular approaches for teaching an agent, such as a robot, a new task. However, in their standard form, both require a very large amount of data to learn: exploration in the case of RL, and demonstrations in the case of IL. In recent years, meta-RL and meta-IL have emerged as promising solutions to this, by leveraging a meta-training dataset of tasks to learn representations which can quickly adapt to this new data. However, both these methods have their own limitations. Meta-RL typically requires hand-crafted, shaped reward functions to describe each new task, which is tedious and not practical for nonexperts. A more natural way to describe a task is to provide demonstrations, as with meta-IL. But after adaptation, these methods cannot continue to improve the policy in the way that RL methods can, and are restricted by the similarity between the new task and the meta-training dataset. A third limitation, which both methods can suffer from, is that defining a low-dimensional representation of the environment for efficient learning (as opposed to learning directly from high-dimensional images), requires hand-crafting this representation. As with rewards, this is not practical for nonexperts, but more importantly, it does not allow generalisation across different task families, since each task family would require its own unique representation and dimensionality.
  In this work, we propose a new method, PERIL, which addresses all three of these limitations, in a hybrid framework that combines the merits of both RL and IL. Our method allows for tasks to be defined using demonstrations only as with IL, but upon adaptation to the demonstrations, it also allows for continual policy improvement through further exploration of the task. Furthermore, we define the state representation using only the agent’s internal sensors, such as position encoders of a robot arm, and through interaction we implicitly recover the state of external environment, such as the poses of objects which the robot is interacting with. Overall, this framework allows for learning of new tasks without requiring any expert knowledge in the human teacher.
  PERIL operates by implicitly representing a task by a latent vector, which is predicted during learning of a new task, through two means. First, during meta-training we encourage high mutual information between the demonstration data and the latent space, which during testing forms a prior for
  the latent space and represents the agent’s task belief from demonstrations alone. Second, we allow further exploration to continually update the latent space, by conditioning on the robot’s states and actions during exploration of this new task. We model the latent space via an encoder, from which posterior sampling can be done to encode the agent’s current task belief. In essence, the encoder aims to learn an embedding which can simultaneously (i) infer the task intent, and (ii) output a policy which can solve the inferred task. During meta-training, PERIL is optimised end-to-end, by simultaneously learning both a policy and the embedding function upon which the policy is conditioned.
  In our experiments we find PERIL achieves exceptional adaptation rates and is capable of exploiting demonstrations to efficiently explore unseen tasks. Through structured exploration, PERIL outperforms other Meta-RL and Meta-IL baselines and is capable of zero-shot learning. We show how our method is capable of multi-family meta-learning as well as out-of-family meta-learning by clustering distinct meta-trained latent space representations. As an extension, we also show how to use privileged information during training to create an auxiliary loss for training the embedding function, which helps to form a stronger relationship between the latent space and the true underlying state which defines the task. Supplementary videos are available at our anonymous webpage https://sites.google.com/view/peril-iclr-2021
sections.heading: 2 RELATED WORK
sections.text: Meta-RL was conceptualised as an RNN-based task. Developed by Wang (2016) and Duan et al., the authors use RNNs to feed a history of transitions into the model such that the policy can internalise the dynamics. On another line, Finn et al. (2017) developed a learning-to-learn strategy, model agnostic meta learning (MAML), which meta-learns an initialisation that adapts the parameters of the policy network and fine tunes it during meta-testing. Although promising results in simple goalfinding tasks, MAML-based methods fail to produce efficient stochastic exploration policies and adapt to complex tasks (Gupta et al., 2018). Meta-learning robust exploration strategies is key in order to improve sample efficiency and allow fast adaptation at test time. In light of this, contextbased RL was developed with the aim of reducing the uncertainty of newly explored tasks. These map transitions τ collected from an unseen task into a latent space z via an encoder qφ(z|τ), such that the conditioned policy πθ(τ |z) can efficiently solve said task (Rakelly et al.; Wang & Zhou, 2020). An underlining benefit of decoupling task encoding from the policy is that it disentangles task inference from reward maximisation, whilst gradient-based and RNN-based meta-RL policies do this internally. An important remark regarding training conditions of the discussed meta-RL methods is that they are typically meta-trained using dense reward functions (Rakelly et al.; Wang, 2016; Wang & Zhou, 2020). These dense reward functions provide information-rich contexts of the unseen task. Considering that the ultimate goal is to allow agents to solve new tasks in the real world, adaptation during test time must be robust to sparse reward feedback (Schoettler et al., 2020).
  In the context of RL, incorporating demonstrations has proven successful in aiding exploration strategies, stabilising learning and increasing sample efficiency (Vecerik et al., 2017). Learning expressive policies from a set of demonstrations requires a vast amount of expert trajectories (Ross et al.), particularly in high dimensional state-action spaces (Rajeswaran et al.). In contrast, Meta-IL can be implemented in meta-RL by conditioning the agent with expert trajectories. On the another hand, Zhou et al. propose a MAML-based meta-IL approach which averages objective across demonstrations. The latter learns to adapt at test-time by receiving binary rewards. A similar strategy was also developed by and Mendonca et al.. The caveats of these approaches remain that of traditional IL: (i) Imitating expert trajectories hinders the policy from doing better than the demonstrations; (ii) Cloning behaviours reduces flexibility and generalisation capacity.
sections.heading: 3 HYBRID META-REINFORCEMENT AND IMITATION LEARNING
sections.heading: 3.1 PROBLEM STATEMENT
sections.text: We assume access to a set of tasks T ∈ p(T ), with each task represented as a partially observable Markov decision process (POMDP). Observations o are incomplete and only include measurements of the agent’s internal state. For example, a peg-in-hole task would include the robot’s (and therefore the peg’s) pose in the observation, but not the hole’s pose. The full state s contains both the robot’s internal state, and the state of the external environment. Our method involves an agent inferring z, a descriptor of a task which provides the information required to solve that task, such as a representation of s. Each task is then defined as T = {p(o0|z), p(o′, z′|o, a, z), r(o, a|z)}, with an unknown initial observation distribution p(o0|z), transition distribution p(o′, z′|o, a, z), and reward function r(o, a|z), where a is the action taken by the agent. By leveraging task beliefs, PERIL exploits enriched observational spaces (s ∼ {o ∩ z}) with the objective of closing said POMDP into a stable MDP form. With the aim of supporting continuous task inference through interaction, we construct z as a probabilistic embedding conditioned on a set of recently collected transitions, referred to as the context c. We define a contexton cTt = (ot, at, rt, ot+1) as a transition collected on task T at time-step t such that the context cT0:t (what we call c) denotes the set of accumulated contextons. During meta-testing, the agent then attempts to find the true posterior p(z|c) over the task belief z ∼ p(z|c), by conditioning on c. Demonstrations significantly reduce the search space in exploration whilst providing a natural means of communicating the task. Thus, access to expert trajectories provides information-rich context which can be exploited to pre-condition the policy via a prior over z. Subsequently, online adaptation through RL can further disambiguate z. In our approach, we leverage dual meta-learning objectives to perform hybrid adaptation to new tasks, with conditioning on both demonstration contexts and exploratory contexts, where we define a demonstration as a trajectory of T observations and actions d = {(ot, at)}Tt=1, and an adaptation episode τe as a trajectory of N steps τe = {(ot, at, rt, zt)}Nt=1: Primal Inference: The agent observes a set of k = 1, ...,K demonstrations from an expert set Ddemo := {dk} to form a context prior cdemo = {dk}Kk . Exploratory Adaptation: The agent explores with initialised context c ←− cdemo and adapts with sampled trajectories τ such that at time-step t, a hybrid context is formed c←− cdemo ∩ τ0:t. Primal task inference aims to provide long-term inference on a task belief: meta-trained inference from previously solved tasks. Using posterior sampling, exploratory adaptation provides a proxy for short-term memory: as the context is updated with recent transitions, structured exploration can adjust primal inference by reasoning about the uncertainty of z, where c := {cdemo∩(τTe , ..., τ∞Te )}.
sections.heading: 3.2 PROBABILISTIC EMBEDDINGS FOR META-RL
sections.text: As we do not have access to the posterior p(z|c), we use variational inference methods to produce an approximation qφ(z|c). Through generative processes, we sample z ∼ qφ(z|c) and optimise φ by maximising a meta-objective conditioned on z. Variational Encoders (VEs) are capable of producing latent distributions which optimise an arbitrary task-dependent objective G(T |·). We average the expectancy over a set of tasks from p(T ) to formulate a meta-objective which rewards fast adaptation to unseen tasks (Eq. 1), where β controls the constraint for mutual information between the inferred variable z and context c. This information bottleneck filters down redundant information and compresses the z into a generalisable form. We set the prior p(z) to a unit Gaussian.
  φ∗ = argmax φ
  ET ∈p(T ) [ Ez∼qφ(z|cT ) [ G(T |z) + βDKL [ qφ(z|cT )||p(z) ]] (1)
  Traditional meta-RL methods leverage RNN-based inference systems to produce latent features from a history of recently collected transitions. The problem with this approach is that learning from entire trajectories leads to massive variances which hinder the learning process (Duan et al.; Humplik et al., 2019). In theory recurrence is not strictly required, since any MDP is defined by a distribution of sequentially invariant transitions. In light of this, we exploit task encoders as suggested by Rakelly et al., where q(z|c) is modelled as a product of Gaussian Factors. Each factor ψφ(z|cn) parameterised by φ, is independently computed: ψφ(z|cn) = N (fµψ(cn), fσψ (cn)).
  We build on top of probabilistic meta-RL methods derived by Rakelly et al.. Decoupling task inference from task completion allows efficient off-policy objectives to be optimised. Moreover, conditioning a policy with diverse task descriptors aims to generalise behaviours amongst different dynamics and rewards. This is generally not the case when employing MAML-based or RNN-based meta-training kernels to ”learn how to learn” new tasks, since policy gradients modify the policy parameters online which, in turn, can result in highly unstable and inefficient adaptation to new tasks, requiring up to hundreds of sample trajectories in unseen environments.
  To that end, we employ meta-adapted maximum entropy RL, where a proxy for the policy π(a|s) is defined by including the task belief z as part of the observational space πθ(a|o, z), resulting in taskconditioned critic LTcritic and actor LTactor losses for the the Q-function Qθ(·) and the policy πθ(·) respectively (see A.1 for more details). As VEs are a form of generative processes, G(T |·) can be defined with the aim of recovering transition dynamics or reconstructing state spaces (Humplik et al., 2019). Instead, we optimise qφ(z|c) in a model-free manner as proposed in Rakelly et al.. Here, parameters φ can be optimised to maximise expected discounted rewards under a policy πθ(·|z) through reconstruction of Qθ(·, z). We fold LTcritic as a proxy for the task-dependent goal G(T |z):
  G(T |z)←− LTcritic(z) (2)
sections.heading: 3.3 CONDITIONING ON DEMONSTRATIONS
sections.text: By leveraging meta-learning, we suggest that the agent can learn to exploit the overlapping statistical information from within heterogeneous demonstrations belonging to different tasks, with the aim of inferring task embeddings z which can help improve exploration during test-time adaptation. In order to link demonstrations into the probabilistic meta-RL framework, we formulate an objective based on mutual information I(z; τ) between the demonstration trajectories and the latent space distribution p(z) (Eq. 3). This objective is similar to that used in Yu et al. with the exception that we adapt this to meta-imitation learning and off-policy RL instead of recovering reward functions.
  I(z; τ) = Ez∼p(z),τ∼pθ(τ |z) [ log p(z|τ)− log p(z) ]
  (3)
  As direct access to the posterior p(z|τ) is not available, I(z; τ) is intractable. However, in order to adjust for this, we leverage a variational approximation to p(z|τ) using our task belief encoder qφ(z|τ). We assume access to a distribution of expert demonstrations pπE (τ |z). Additionally, we include further desiderata over the mutual information objective based on distributional matching:
  Learning from demonstrations. Matching generated trajectories to those sampled from expert trajectories: minθ Ep(z)[DKL(pπE (τ |z)||pθ(τ |z))]. This secondary objective can be considered as trying to match the distribution of trajectories generated by the agent’s policy conditioned on z, to those from the expert policy (similar to BC). Since they share the same marginal distribution p(z), matching these distributions also encourages matching of the conditionals pπE (z|τ) and p(z|τ). Linking variational posterior. minθ Epθ(τ)[DKL(p(z|τ)||q(z|τ))]. Encourage qφ(z|τ) to approximate the true posterior p(z|τ) such that, given a new demonstration, the encoder properly infers the task. This objective acts as a regulator as it reduces over-fitting by penalising variance: optimal distributional mismatch is reached when the encoder produces constant information-less representations of z. The distributional matching objective can therefore be defined as in (4).
  min φ −I(z; τ) + Ep(z)[DKL(pπE (τ |z)||p(τ |z))] + Ep(τ)[DKL(p(z|τ)||qφ(z|τ))] (4)
  After several manipulation steps (see section A.1 for more details), we deconstruct this objective into a differentiable form and define two separate loss components LTbc (Eq. 5) and LTinfo (Eq. 6), where πb is the behavioural policy which collected the transitions (truncated importance sampling).
  LTbc = −Eτ∼pTπE (τ),z∼qφ(z|τ)[log πθ(τ |z)] (5)
  LTinfo = −Eτ∼pTπE ,z∼qφ(z|τ),τb∼πb(τ |z)
  [ min ( log πθ(τb|z) log πb(τb|z) , 1 ) log qφ(z|τb) ] (6)
  As LTinfo conditions the encoder, we aggregate it to the task-dependent goal G(T |z) (7).
  G(T |z)←− LTcritic(z) + LTinfo(z) (7)
sections.heading: 3.4 AUXILIARY SYSTEMS
sections.text: An inherent problem is that the agent generates predictions Qθ(o, a, z) based on unsupervised estimates z ∼ qφ(z|cT ). Whilst this is theoretically generalisable to any MDP, it brings large variances and instabilities during training because the agent must simultaneously (i) distinguish one task from another, and (ii) use the task beliefs to solve that task. A plausible solution to mitigate these instabilities is to exploit privileged information (a brief task descriptor such as the position and orientation of a door) during training, allowing the encoder qφ(z|cT ) to produce task beliefs z which provide succinct descriptors of T . Although this information is not available during testing, it could be made available, for example, if training is performed in a full-state simulation, or in the real-world but with extra environment instrumentation. In theory, a perfect task descriptor is that which provides sufficient information to close the POMDP. We model ground truth task descriptor b̂ for T as a vector b̂ ∈ Rv where v is the dimension of the task descriptor. During training we wish to condition the encoder to produce latent spaces z ∼ qφ(z|cT ) which, when mapped into the dimensions of b, can produce approximations of b̂. We use a VAE dλ(b|z) parameterised by λ as our auxiliary module, which produces vectors bµ, bσ ∈ Rv and optimise it via a log-likelihood maximisation objective (8).
  LTaux = −E(b̂,c)∼T ,z∼qφ(z|c) [ log dλ(b = b̂|z) ]
  (8)
  Inference b ∼ dλ(b|z) from the trajectories in cT is decoupled from RL as gradients do not pass through the actor or the critic. This stabilises the encoder by having a fixed supervised target, and allows off-policy training. Leveraging auxiliary objectives for meta-RL was coined by Humplik et al. (2019), where the authors condition task inference solely on LTaux to train RNN-based policies. However, in PERIL we use simple descriptors such that these solely condition the encoder to converge towards a suggested direction. Thus, we extend G(T |z) with the auxiliary loss to produce the ultimate meta-objective (9). Details of the final computational graph is presented in Figure 8. By keeping the critic loss LTcritic in G(T |z), we give freedom for the encoder to perform unsupervised learning so that it can structure representations of z which represent different dynamics and rewards: if we solely base task inference on LTaux, a task such as screwing a bolt would output the same task belief as a task of inserting a peg, even though the tasks are fundamentally different.
  G(T |z)←− LTcritic(z) + LTinfo(z) + LTaux(z) (9)
sections.heading: 3.5 IMPLEMENTATION
sections.text: Meta-training requires sampling from a set of transitions (ot, at, rt, ot+1) T t=0 corresponding to a distribution of tasks T ∈ p(T ) and optimising the meta-objective. We use task-specific replay buffers BT to store collected transitions from which we can randomly sample during training. Following primal inference objective outlined in section 3.1, task inference is initially conditioned via contextons retrieved from expert demonstrations. Consequently, we store a set of k demonstrations generated by an expert policy on task-conditioned demonstration buffers DT . This expert policy may consist of a human user or, in our case, a pre-trained SAC agent with access to the full state of the environment. Meta-training algorithms are presented in Algorithms 1 and its process is illustrated in Figure 2. Further details of the meta-training and meta-testing processes in section A.2. We augment DT with imperfect trajectories which lead to demo-like (and increased) sum of rewards. This allows PERIL to: (i) be robust to imperfect demonstrations and surpass performance from the expert; (ii) combat the overfitting nature of BC from a narrow set of k demonstrations. The agent must also exploit posterior sampling to update its task belief in order to accomplish continuous adaptation objectives. To this end, we use exploratory data to update the task belief during adaptation and set additional task-dependent encoder buffers X T which only stores recently collected contextons. This mitigates distributional shift between off-policy training and on-policy adaptation.
sections.heading: 4 EXPERIMENTS
sections.text: We leverage probabilistic meta-RL methods to find values for z which reconstruct unobserved representations of a new task. To that end, we focus on validating PERIL in environments where the agent must explore in order to understand the dynamics, whilst also utilising sparse rewards to identify the task intent. Furthermore, neural networks, are particularly susceptible to abrupt discontinuities. Thus, it is of particular interest to leverage meta-training in situations as such. We devise
  Algorithm 1 PERIL: Meta-training Require: Batch of T training tasks {Ti}i=1,..,T , Ti ∈ p(T )
  1: Initialise πθ, Qθ, qφ, bλ and replay BTi , encoder X Ti and demo buffersDTi for T ∈ {Ti}i=1,..,T 2: while not done do 3: for each Ti, i ∈ {1, ..., T} do . Collect data 4: Initialise context from demonstration ci = {τE}, τE ∼ Di and clear encoder buffer 5: for k = 1,...,K do 6: Sample from context z ∼ qφ(z|ci) 7: Roll out policy τ ∼ πθ(τ |z). Add to Bi and Xi. Add to Di if ER[τ ] > ER[τE ] 8: Update context ci ←− {ci ∪ xi}, xi ∈ Xi 9: for n = 1, ..., Nt do . Training for Nt steps
  10: for each Ti, i ∈ {1, ..., T} do 11: Sample buffers xi ∼ Xi, τE ∼ Di, bi ∼ Bi to form hybrid context ci = {τE ∪ xi} 12: Sample z ∼ qφ(z|ci) and compute losses Limi, Libc, Liactor Licritic, LiDKL , L i aux 13: Update parameters θπ, θQ, φ, λ via gradient descent
  tasks which involve contact-rich interactions and boundaries, factors which are considered to require a higher level of perception of the environment (Zhu et al., 2020). More details on A.3.
  The different task families tested in this study are illustrated in Figure 3. Within a task family, one single task is defined by the configuration of the environment, such as the pose of the object or goal. When leveraging privileged information, this pose is used as the task descriptor. For each task, demonstrations are provided from different robot initial poses, and the agent is then required to perform that task, from any new robot initial pose. We compare our proposed methods to other meta-RL and IL baselines. To ensure fairness in all tests, we used the same number of parameters during training. Specifically, MetaIL (Yu et al.), extends PEARL by conditioning exploration on demonstrations. We also use Noisy-BC as a baseline where the agent clones a demonstration with additional noise (20% of p(o0|·)) . We also consider the case where privileged information is unavailable, thus compare these baselines to both PERIL and PERIL-A. In PERIL we omit Laux.
sections.heading: 4.1 PERFORMANCE
sections.text: We evaluate the performance of each method over 5 task families (Figure 4) using k = 3 demonstrations per task. Since meta-learning requires trajectory-based adaptation, we record the averaged trajectory return after 3 policy roll-outs. The results indicate that, in contrast to other baselines, meta-learning without demonstrations through sparse reward feedback is particularly ineffective (PEARL). On the other hand, PERIL-based methods significantly outperform MetaIL and NoisyBC, especially in tasks from Peg2D or Reach2D/3D where the agent must explore efficiently. It is in these cases where the auxiliary module contributes greatest. On the other hand, in task families such as Stick2D and Key2D, a few contact-rich interactions with the environment can quickly help decipher the task. In this case, goal-oriented auxiliary targets are not as helpful.
sections.heading: 4.2 INCREASING GENERALISATION
sections.text: Most meta-RL research involves adaptation to tasks within a single task family (Rakelly et al.; Duan et al.; Yu et al.). But in practice, we seek agents capable of interpolating from a diverse set of dynamics. To test the representational power behind PERIL we evaluate training and adaptation performance in multi-task family settings (Figure 5). Here, we train a single agent along each task from from within the 2D task families. TSNE plots of the latent space distribution created during metatesting reveals PERIL-based methods produce structured task beliefs during hybrid inference of new tasks. Moreover, this verifies PERIL’s long-term memory contribution. Last, it showcases PERIL performs structured exploration at the multi-task level, allowing the agent to efficiently switch from one macro policy to another and robustly inherit a diverse set of behaviours. Despite the effectiveness of privileged information in complex exploration tasks in single task family adaptation, auxiliary systems do not generally contribute as much during meta-multi-tasking. We believe that task inference is substantially more convoluted in the multi-task family case as discerning dynamics and intent requires more complex embeddings in the latent space than the position of the goal. We also test generalisation by adapting PERIL in out-of-task distributions (Figure 6), where PERIL interpolates from within meta-trained latent space representations to adapt to unseen dynamics.
  Metrics during adaptation of unseen tasks reveal PERIL is substantially more efficient in exploration with respect to other baselines, and is capable of zero-shot learning (Table 1), where the context from the demonstration is sufficient to condition the agent to adapt to an unseen task. Note we record the K-shot as the average kth adaptation trajectory until successful completion of the new task.
sections.heading: 4.3 ALTERATIONS ON K
sections.text: We study the inherent meta-IL dependency over the number of per-task expert demonstrations k. We find that increasing the number of demonstrations per task slightly improves sample efficiency but does not alter the asymptotic capacity of PERIL (Figure 7). Improvement is small since, by augmenting the demonstrations online, PERIL is capable of self-inducing additional demos which improves sample efficiency.
sections.heading: 5 CONCLUSION
sections.text: We have introduced PERIL, a new method for meta imitation and meta reinforcement learning which builds a representation of a new task by conditioning on both demonstrations, and further exploration. This provides a framework where new tasks can be defined naturally by a non-expert, without requiring reward shaping or state-space engineering. Experiments across a range of tasks show our method is able to adapt not only to novel instances within a task family, but also to entirely novel task families, whilst doing so with superior data efficiency to a range of baselines. This provides the foundation for further theoretical extensions of this framework, such as learning from imperfect demonstrations, as well as further applications, such as real-world contact-rich robot manipulation.
sections.heading: A APPENDIX
sections.heading: A.1 MATHEMATICAL EXTENSIONS
sections.heading: Probabilistic Kernel
sections.text: We adopt a MaxEnt RL formulation to define a meta-objective for task T ∈ p(T ) (10), where H(·|o) represents the observational entropy, and the temperature α controls the weighting term for the entropy-based reward.
  π∗ = argmax π ∑ T ∈p(T ) Ec∼T [∑ t∈T Ez∼p(z|c),(ot,at)∼πT [ r(ot, at, z) + αH(π(·|ot, z) ]] (10)
  Optimising the objective defined in (10) is possible by using the SAC soft policy iteration approach. The difference to standard SAC is that in our case, the observation is augmented by z resulting in task-conditioned critic (11) and actor (12) losses for the the Q-function Qθ(·) and the policy πθ(·) respectively. V corresponds to the frozen target value function (no gradients stored in the forward pass).
  Notice we use the term BT to represent the distribution of transitions in task T , which is modelled by a replay buffer. Moreover, the over-line operator in z denotes that gradients are detached. You may seek further details on the derivation of actor and critic losses in Appendix B of (Haarnoja et al.).
  LTcritic = Ec∼T ,z∼qφ(z|c),(o,a,r,o′)∼BT [ Qθ(o, a, z)− (r + V (o′, z)) ]2 (11)
  LTactor = Ec∼T ,z∼qφ(z|c),o∼BT ,a∼πθ(a|o,z) [ DKL ( πθ(a|o, z) ∣∣∣∣∣ ∣∣∣∣∣exp(Qθ(o, a, z))Zθ(o) )] (12)
  Where Zθ(o) is the normalising partition function, which is intractable yet has no effect on the computation of the gradients. In the computation of LTactor, the gradients for z are detached, allowing the policy loss to exploit the representation of the MDP passed on by the critic without conditioning the inference network qφ(z|c).
  Observe in 11 we allow gradients from the inference process q : C φ−→ Z to pass onto the computation of Qθ(o, a, z) such that meta-optimisation of the latent variable z is conditioned on reconstructing the Q-function.
sections.heading: Conditioning on Demonstrations
sections.text: We minimise the conditioned mutual information term by enduring the following deconstruction process.
  min φ −I(z; τ) + Ep(z)[DKL(pπE (τ |z)||p(τ |z))] + Ep(τ)[DKL(p(z|τ)||qφ(z|τ))]
  = min φ Ep(z)[DKL(pπE (τ |z)||p(τ |z))] + Ep(z,τ)
  [ log p(z)
  p(z|τ) + log p(z|τ) qφ(z|τ)
  ]
  = min φ
  Ep(z)[DKL(pπE (τ |z)||p(τ |z))] + Ez∼p(z),τ∼p(τ |z) [ log qφ(z|τ) ]
  (13)
  In order to optimise the two terms in (13), we define Lbc and Linfo as the leftmost and rightmost distribution expectancies respectively. In this definition, the expectancies are not differentiable and requires parametric manipulation. The first step is to adapted this objective into a meta-RL form, by approximating the conditional p(τ |z) with the policy pθ(τ |z). We define the first term Lbc(θ) as the conditional behavioural cloning loss.
  Lbc = Ep(z)[DKL(pπE (τ |z)||pθ(τ |z))] (14)
  By manipulation of the Kullback-Liebler divergence we obtain the following expansion.
  min θ Ep(z)[DKL(pπE (τ |z)||pθ(τ |z)] = min θ Ez∼pθ(z|τ) [ log pπE (τ |z) log pθ(τ |z) ]
  min θ Ez∼pθ(z|τ) [ log pπE (τ |z) log pθ(τ |z) ] = min θ Ez∼pθ(z|τ) [ log pπE (τ |z) ] −min θ Ez∼pθ(z|τ) [ log pθ(τ |z) ]
  We then substitute policy πθ as the conditional distribution pθ(τ |z) and our variatonal inference approximation for the posterior qφ(z|τ):
  min θ
  Ez∼pθ(z|τ) [ log pπE (τ |z) ] −min
  θ Ez∼pθ(z|τ)
  [ log pθ(τ |z) ]
  = min θ H(pπE (τ |z))− Ez∼qφ(z|τ)
  [ log πθ(τ |z) ] Because the entropy term is not dependent on the parameters θ, we derive a lower bound objective which is identical to the maximum likelihood estimator for trajectory distributional matching in BC:
  LTbc = −Eτ∼pTπE (τ),z∼qφ(z|τ)[log πθ(τ |z)] (15)
  Note that in the final representation (15), expert trajectory distributions pTπE (τ) are conditioned by task T as would be the case during meta-training. To obtain a tractable form of Linfo we leverage generative processes to switch sampling distributions as we do not have direct access to the prior p(z) to sample z. To that end we sample from both expert distributions τ ∼ pTπE (τ) and the posterior approximation (encoder) z ∼ qφ(z|τ) to arrive to (16).
  LTinfo = −Eτ∼pTπE ,z∼qφ(z|τ),τθ∼πθ(τ |z) [ log qφ(z|τθ) ]
  (16)
  Notice how in LTinfo we generate a set of trajectories τθ from a task belief sampled from expert demonstration trajectories. From this we aim to maximise the likelihood of matching the posteriors on z given τθ. In essence, this can be viewed as a two-player game: we want to match the z generated by demonstrations to the z generated by a policy which is also conditioned on the demonstrations.
  In this form, LTinfo is incompatible with off-policy RL as τθ is sampled from the current policy πθ. We propose truncated importance sampling by sampling from the distribution which collected τθ (17). We use a behavioural policy πb(τ |z) which is updated every episode as a frozen copy of πθ.
  LTinfo = −Eτ∼pTπE ,z∼qφ(z|τ),τb∼πb(τ |z)
  [ min ( log πθ(τb|z) log πb(τb|z) , 1 ) log qφ(z|τb) ] (17)
sections.heading: A.2 ALGORITHM DETAILS
sections.heading: Computational Graph
sections.text: Figure 8 illustrates the computational graph and training procedure of PERIL.
sections.heading: Meta Training
sections.text: Algorithm 2 is a detailed extension of the meta-training algorithm presented in the main text.
  Algorithm 2 PERIL: Meta-training Require: Batch of T training tasks {Ti}i=1,..,T , Ti ∈ p(T )
  1: Initialise πθ, Qθ, qφ, bλ and απ , αQ, αφ, αb. 2: Initialise replay BTi , encoder X Ti and demo buffers DTi for T ∈ {Ti}i=1,..,T 3: while not done do 4: for each Ti, i ∈ {1, ..., T} do 5: Initialise context by sampling demonstrations ci = {τE}, τE ∼ Di 6: Xi ← ∅ . Clear task encoder to reduce on-policy mismatch 7: for k = 1,...,Kprior do . Demonstration-conditioned trajectories 8: Sample z ∼ qψ(z|ci) 9: Collect trajectories τ ∼ πθ(τ |z) and add to Bi and Xi
  10: for k = 1,...,Kpost do . Exploration-conditioned trajectories via posterior sampling 11: Sample z ∼ qφ(z|ci) 12: τ ∼ πθ(τ |z), Bi ←− Bi ∪ τ 13: if ER[τ ] > ER[τE ] then 14: Di ←− {Di ∪ τ} . Demo augmentation 15: ci ←− {ci ∪ xi}, xi ∈ Xi 16: for i = 1, ..., Nt do 17: Sample R random training tasks from p(T ) 18: Clone behavioural policy πb ←− πθ . To apply TRIS 19: for each Ti, i ∈ R do 20: Sample recent trajectories xi ∼ Xi, τE ∼ Di, bi ∼ Bi 21: Form hybrid context ci = {τE ∪ xi} 22: Sample latent task descriptor z ∼ qφ(z|ci) 23: Compute losses Limi, Libc, Liactor Licritic, LiDKL , L i aux
  24: φ←− φ− αφ∇φ ∑ i∈R(Licritic + LiDKL + L i mi + Liaux)
  25: θQ ←− θπ − απ∇π ∑ i∈R Licritic
  26: θπ ←− θQ − αQ∇Q ∑ i∈R(Liactor + Libc)
  27: λ←− λ− αλ∇λ ∑ i∈R Liaux
sections.heading: Meta Testing
sections.text: Algorithm 3 presentes the process behind meta-testing.
  Algorithm 3 Meta-Test adapation
  Require: Networks πθ, qφ, test task T ∼ p(T ), demonstration buffer DT , 1: Initialise context by sampling k demonstrations c = {τE}k1 ∼ DT 2: for r = 1, ..., R do 3: Sample z ∼ qφ(z|c) 4: Roll out policy πθ(a|o, z) for N steps and collect trajectory τ = {(ot, at, rt, ot+1)Nt=1} 5: Update context c← {c ∩ τ}
sections.heading: A.3 ENVIRONMENTS
sections.text: 2D task families are set up with Pymunk and the 3D reach task families are set up from MuJoCo’s ReachEnv. Each task T ∈ p(T ) also contains an initial observational distribution p0(o)T . This distribution defines how the robot is initialised in the environment before collecting data. Since in this project we want to focus on meta-learning the dynamics of contact-rich tasks, we provide an initial distribution p0(o)T which allows the agent to start relatively close to the interaction. We summarise p0(o)T in Table 2, where P0 and θ0 represent the initial effector position in Pymunk units (PyU) (or meters if Reach3D) and angle (radians). Note that via inverse kinematics, the other links of the robot are automatically set.
sections.heading: A.3.1 SPACES
sections.text: Each task has an accessible ground truth task descriptor b̂ ∈ R2 which describes the exact position in space of its goal G. In all 2D tasks, the base (origin) of the robotic manipulator is kept constant. The first component of the observational spaceO is defined by the normalised relative position from the tip of the end effector (P ∈ R2) to the origin Ω of the robot (18), where ω is the vector which defines the width and height in PyU of the visualisation domain (1280, 720). The second component of the observational space corresponds to the sine and cosines of the angle of the end effector θ. The action space A gives complete freedom to the effector and it includes its cartesian velocity (vx, vy) (PyU/s) and angular velocity ωθ (rad/s). Through inverse kinematics, the latter are translated back to the other links. Observation and action spaces are summarised in Table 3.
  orel = O(P ) = P − Ω ω
  (18)
  By definition of the observational space, the agent has no information about the position or condition of the goal. Hence, during adaptation the robot must seek to find the goal and identify the task
  dynamics using its own interactions as well as the information given by the demonstration. Note that in real world conditions, observation and action spaces could be augemented with kinematic components such as forces and torques at the end effector. However, in this simulated environment, we will show that deciphering the dynamics can be performed by using the aforementioned observational and action spaces.
sections.heading: A.3.2 REWARD FUNCTIONS
sections.text: Naive dense reward functions are provided during meta-training of the critic. These reward functions are unshaped and give no information about the dynamics. In essence the reward function r(·) is defined as the absolute distance from the effector tip P to the goal G. The only exception is the Key2D task family, where reward functions are augmented with additional incentives to twist the handle to a desired angle α. Table 4 summarises the reward functions used in each task family.
  On the other hand, we only provide binary sparse rewards r(·) ∈ [0, 1] to the task encoder. These are 0 in all cases except when the effector has reached its goal, where we provide a reward of 1.
sections.heading: A.4 HYPER-PARAMETERS
sections.text: Unless otherwise noted, the default hyperparameters for PERIL are as described below.
sections.heading: Training Loop
sections.text: • Action space |a|: 3 • Observational space |o|: 4 • Latent space |z|: 8 • Maximum path length H: 60 • Prior collection steps Kprior: 240 • Posterior collection steps Kposterior: 240 • RL batch size: 256 • Encoder batch size: 64 • Number of expert demonstrations K: 3 • RL sparse rewards: False • Task belief sparse rewards: True • Maximum context size: 256 • Number of pre-training steps: 1000 • Number of training steps: 1000 • Number of tasks to average gradients in meta-training R: 16 • Number of tasks to collect data from each epoch: 32 • Number of Epochs: 100 • Discount factor γ: 0.98 • Entropy temperature: 0.1 • Soft target value = 0.005 • Kullback-Liebler divergence weighting wKL: 0.1 • Behavioural cloning weighting wbc: 0.5
  • Mutual information weighting wmi: 0.2 • Auxilliary loss weighting waux: 4.0
sections.heading: Actor
sections.text: • Hidden layer size h: 256 • Architecture: [|o, a, z|, h, h, 1] • Learning rate απ: 3× 10−4
  • Output: Bounded action [-1,1] via tanh
sections.heading: Critic
sections.text: • Hidden layer size h: 256 • Architecture: [|a, z|, h, h, 1] • Learning rate: αQ: 3× 10−4
sections.heading: Encoder
sections.text: • Latent size: d • Input affinity architecture: [|o, a, r, o|, 256, 256, d] • Output affinity architecture: [d, 64, 64, |z|] • Learning rate: αq: 3× 10−4
sections.heading: Belief Module
sections.text: • Task descriptor dimension |b|: 2 • Architecture: [|z|, 32, 16, |b|] • Learning rate: αb: 3× 10−4