Ofﬂine Meta-Reinforcement Learning with Online Self-Supervision
Abstract
Meta-reinforcement learning (RL) methods can meta-train policies that adapt to new tasks with orders of magnitude less data than standard RL, but meta-training itself is costly and time-consuming.
If we can meta-train on ofﬂine data, then we can reuse the same static dataset, labeled once with rewards for different tasks, to meta-train policies that adapt to a variety of new tasks at meta-test time.
Although this capability would make meta-RL a practical tool for real-world use, ofﬂine meta-RL presents additional challenges beyond online meta-RL or standard ofﬂine
RL settings.
Meta-RL learns an exploration strategy that collects data for adapting, and also meta-trains a policy that quickly adapts to data from a new task.
Since this policy was meta-trained on a ﬁxed, ofﬂine dataset, it might behave unpredictably when adapting to data collected by the learned exploration strategy, which differs systematically from the ofﬂine data and thus induces distributional shift.
We do not want to remove this distributional shift by simply adopting a conservative exploration strategy, because learning an exploration strategy enables an agent to collect better data for faster adaptation.
Instead, we propose a hybrid ofﬂine metaRL algorithm, which uses ofﬂine data with rewards to meta-train an adaptive policy, and then collects additional unsupervised online data, without any reward labels, to bridge this distribution shift.
By not requiring reward labels for online collection, this data can be much cheaper to collect.
We compare our method to prior work on ofﬂine meta-RL on simulated robot locomotion and manipulation tasks and ﬁnd that using additional unsupervised online data collection leads to a dramatic improvement in the adaptive capabilities of the meta-trained policies, matching the performance of fully online meta-RL on a range of challenging domains that require generalization to new tasks.
Introduction
Reinforcement learning (RL) agents are often described as learning from reward and punishment analogously to animals: in the same way that a person might train a dog by providing treats, we might train RL agents by providing rewards.
However, in reality, modern deep RL agents require so many trials to learn a task that providing rewards by hand is often impractical.
Meta-reinforcement learning in principle can mitigate this, by learning to learn using a set of meta-training tasks, and then acquiring new behaviors in just a few trials at meta-test time.
Current meta-RL methods are so efﬁcient that it is entirely practical for the meta-test time adaptation to use even human-provided rewards.
However, the meta-training phase in these algorithms still requires a large number of online samples, often even more than standard RL, due to the multi-task nature of the meta-learning problem. Ofﬂine reinforcement learning methods, which use only prior experience without active data collection, provide a potential solution to this issue, because a user must only annotate multi-task data with rewards once in the ofﬂine dataset, rather than doing so in the inner loop of RL training, and the same ofﬂine multi-task data can be reused repeatedly for many training runs.
While a few recent works have proposed ofﬂine meta-RL algorithms [8, 36], we identify a speciﬁc problem when an agent trained with ofﬂine meta-RL is tested on a new task: the distributional shift between the behavior policy and the meta-test time exploration policy means that adaptation procedures learned from ofﬂine data might not perform well on the (differently distributed) data collected by the exploration policy at meta-test time.
In practice, we ﬁnd that this leads to a large degradation in performance when adapting to new tasks.
This mismatch in training distribution occurs because ofﬂine meta-RL never trains on data generated by the meta-learned exploration policy.
We propose to address this challenge by collecting additional online data without any reward supervision, leading to a semi-supervised ofﬂine meta-RL algorithm, as illustrated in Figure 1.
Online data can be relatively cheap to collect when it does not require reward labels, but it can still make it possible to bridge the distributional shift issue.
To make it feasible to use this data for meta-training, we can generate synthetic reward labels for it based on the labeled ofﬂine data.
Based on this principle, we propose semi-supervised meta actor-critic (SMAC), which uses rewardlabeled ofﬂine data to bootstrap a semi-supervised meta-reinforcement learning procedure, in which an ofﬂine meta-RL agent collects additional online experience without any reward labels.
The agent uses the reward supervision from the ofﬂine dataset to learn to generate new reward functions, which it uses to autonomously annotate rewards in these otherwise rewardless interactions and meta-train on this new data.
We evaluate our method and prior ofﬂine meta-RL methods on a number of benchmarks [8, 36], as well as a challenging robotic manipulation domain that requires generalization to new tasks, with fewer than 400 time steps of reward labels at meta-test time.
We ﬁnd that, while standard meta-RL methods perform well at adapting to training tasks, they suffer from data-distribution shifts when adapting to new tasks that were not seen during meta-training.
In contrast, our method attains signiﬁcantly better performance, on par with an online meta-RL method that receives fully labeled online interaction data.
Related Works
Many prior meta-RL algorithms assume that reward labels are provided with each episode of online interaction [9, 12, 18, 53, 20, 43, 23, 30, 56, 54, 55, 27].
In contrast to these prior methods, our method only requires ofﬂine prior data with rewards, and additional online interaction does not require any ground truth reward signal.
Prior works have also studied other formulations that combine unlabeled and labeled trials.
For example, imitation and inverse reinforcement learning methods use ofﬂine demonstrations to either learn a reward function [1, 11, 22, 13] or to directly learn a policy [46, 45, 22, 44, 40].
Semi-supervised and positive-unlabeled reward learning [52, 57, 31] methods use reward labels provided for some interactions to train a reward function for RL.
However, all of these methods have been studied in the context of a single task.
In contrast, we focus on meta-learning an RL procedure that can adapt to new reward functions.
In other words, we do not focus on recovering a single reward function, because there is no single test time reward or task.
SMAC uses a context-based adaptation procedure similar to that proposed by Rakelly et al.
[43], which is related to contextual policies, such as goal-conditioned reinforcement learning [26, 47, 2, 42, 6, 50, 41, 38] or successor features [32, 3, 4, 16].
In contrast, our meta-learning procedure applies to any RL problem, does not assume that the reward is deﬁned by a single goal state or ﬁxed basis function, and only requires reward labels for static ofﬂine data.
Our method addresses a similar problem to prior ofﬂine meta-RL methods [36, 8], but we show that these approaches perform poorly due to distributional shift.
Our method addresses the distribution shift problem by using online interactions without reward supervision.
In our experiments, we found that SMAC greatly improves performance on both training and held-out tasks.
Lastly, SMAC is also related to unsupervised meta-learning methods [17, 25], which annotate data with their own rewards.
In contrast to these methods, we assume that there exists an ofﬂine dataset with reward labels that we can use to learn to generate similar rewards.
Preliminaries
Meta-reinforcement learning.
In meta-RL, we assume there is a distribution of tasks p T ( · ) .
A task T is a Markov decision process (MDP), deﬁned by a tuple T =
( S , A , r, γ, p 0 , p d ) , where S is the state space,
A is the action space, r is a reward function, γ is a discount factor, p 0 ( s 0 ) is the initial state distribution, and p d ( s t +1 | s t , a t ) is the environment dynamics distribution.
A replay buffer D is a set of state, action, reward, next-states tuples, D
= { s i , a i , r i , s (cid:48)
i } N size i =1 , where all the rewards come from the same task.
We will use the letter h to denote a small replay buffer or “history” and the notation h ∼ D to denote that a mini-batch h is sampled from a replay buffer D .
We will use the letter τ to represent a trajectory τ =
( s 1 , a 1 , s 2 , . . . )
without reward labels.
A meta-episode consists of sampling a task T ∼ p T ( · ) , collecting T trajectories with a policy π θ , adapting the policy to the task between each trajectory, and measuring the performance on the last trajectory.
We write the policy’s adaptation procedure as A φ , parameterized by meta-parameters φ .
Between each trajectory, the adaptation procedure transforms the history of interactions h within the meta-episode into a context z
=
A φ ( h ) that summarizes the previous interactions.
This context z ∈ Z is then given to the policy π θ ( a , | s , z ) .
The exact representation of π θ , A φ , and Z depends on the speciﬁc meta-RL method used.
For example, the context z can be weights of a neural network [12] outputted by a gradient update, hidden activations ouputted by a recurrent neural network [9], or latent variables outputted by a stochastic encoder [43].
Using this notation, the objective in meta-RL is to learn the adaptation parameters φ and policy parameters θ to maximize performance on a meta-episode given a new task T sampled from p ( T ) .
PEARL.
Since we require an off-policy meta-RL procedure for ofﬂine meta-training, we build on probabilistic embeddings for actor-critic RL (PEARL) [43], an online off-policy meta-RL algorithm.
In PEARL, z is a vector and the adaptation procedure A φ that maps h to z consists of sampling z from a distribution z ∼ q φ e ( z | h ) .
The distribution q φ e is generated by an encoder network with parameters φ .
This encoder is a set-based network that processes all of the tuples in h
= { s i , a i , r i , s (cid:48) i } N enc i
=1 in a permutation-invariant manner to produce the mean and variance of a diagonal multivariate Gaussian.
The policy is a contextual policy π θ ( a | s , z ) conditioned on z by concatenating z to the state s .
The policy parameter θ is trained using soft-actor critic [19] which involves learning a critic, or
Q -function, Q w ( s , a , z ) , with parameter w that estimates the sum of future discounted rewards conditioned on the current state, action, and context.
The encoder parameters are trained by backpropagating the critic loss into the encoder.
The actor, critic, and encoder losses are minimized via gradient descent with mini-batches sampled from separate replay buffers for each task.
Ofﬂine reinforcement learning.
In ofﬂine reinforcement learning, we assume that we have access to a dataset D collected by some policy behavior π β .
An RL agent must train on this ﬁxed dataset and cannot interact with the environment.
One challenge that ofﬂine RL poses is that the distribution of states and actions that an agent will see when deployed will likely be different from those seen in the ofﬂine dataset as they are generated by the agent, and a number of recent methods have tackled this distribution shift issue [15, 14, 33, 51, 39, 34].
Moreover, one can combine ofﬂine RL with meta-RL by training meta-RL on multiple datasets D 1 , . . .
, D N buff [8, 36], but in the next section we describe some limitations of this combination.
[Figure]
D K L ( q φ ( z | h ) || p ( z ))
Ant Direction: Online vs Oﬄine z -Posteriors
[Figure]
P o s t - A d a p t a t i o n R e t u r n s
Ant Direction: Adapting from Online vs Oﬄine Data data source oﬄine buﬀer online policy
The Problem with Naïve Ofﬂine Meta-Reinforcement Learning
Ofﬂine meta-RL methods can in principle utilize the same constraint-based approaches that standard ofﬂine RL algorithms have used to mitigate distributional shift.
However, they must also contend with an additional distribution shift challenge that is speciﬁc to the meta-RL scenario: distribution shift in z -space.
Distribution shift in z -space occurs because meta-learning requires learning an exploration policy π θ that generates data for adaptation.
However, ofﬂine meta-learning only trains the adaptation procedure A φ ( h ) using ofﬂine data h generated by a previous behavior policy, which we denote as π β .
After ofﬂine training, there will be a mismatch between this learned exploration policy π θ and the behavior policy π β , leading to a difference in the data h and in turn, in the context variables z
= A φ ( h ) .
In other words, if we write p ( z | π ) to denote the marginal distribution over z given data generated by policy π , the differences between trajectories from π θ and π β will result in differences between p ( z | π β ) during ofﬂine training and p ( z | π θ ) at meta-test time.
To illustrate this issue, we empirically compare p ( z | π β ) and p ( z | π θ ) .
While computing these distributions in closed form would require strong assumptions about how the policy, adaptation procedure, and environment interact, we approximate the these distributions by using a PEARL-style encoder discussed in Section 3: p ( z | π )
≈ q φ e ( z | h ) where h ∼ π .
We use this approximation to measure the KL-divergence observed during ofﬂine training between the posterior p ( z | π ) and a ﬁxed prior p z ( z ) .
If these two distributions were the same, then we would expect the distribution of KL divergences to also be similar.
However, we see in Figure 2 that these two distributions are markedly different when analyzing a training run of SMAC on the Ant Direction task (see Section 6).
We also observe that this distribution shift negatively impacts the resulting policy.
In Figure 2, we plot the performance of the learned policy when conditioned on z sampled from q φ e ( z | π β ) compared to q φ e ( z | π θ ) .
We see that the policy conditioned on z generated from the behavior policy π β data leads to improvement, while the same policy conditioned on z generated from the exploration policy π θ slightly drops in performance.
Since we evaluate the same policy π θ and only change how z is sampled, this degradation in performance suggests that the policy suffers from distributional shift between p ( z | π β ) and p ( z | π θ ) : the encoder produces z vectors that too unfamiliar to the policy after reading in these exploration trajectories, and therefore actually attains better performance when conditioned on the trajectories from π β .
We note that this issue arises in any method that trains non-Markovian policies with ofﬂine data.
For example, recurrent policies for partially observed MDPs [24] depend both on the current observation o and a history h .
When deployed, these policies must also contend with potential distributional shifts between the training and test-time history distributions, in addition to the change in observation distribution o .
This additional distribution shift may explain why many memory-based recurrent policies are often trained online [9, 21, 10] or have beneﬁted from refreshing the memory states [28].
In this paper, we focus on addressing this issue speciﬁcally in the ofﬂine meta-RL setting.
Ofﬂine meta-RL with self-supervised online training.
In complex environments where many behaviors are possible, the distribution shift in z -space will likely be inevitable, since the learned policy is likely to deviate from the behavior policy.
To address this issue, we introduce an additional assumption: in addition to the ofﬂine dataset, we assume that the agent can autonomously interact with the environment without observing additional reward supervision .
This problem statement is useful for scenarios where autonomously interacting with the world is relatively easy, but online reward supervision is more expensive to obtain.
For instance, it may be cheap to label rewards in an ofﬂine dataset for robotics by reward sketching [5], but expensive to have a labeler available online while the robot runs to provide rewards.
Formally, we assume that the agent can generate additional rollouts in an MDP without a reward function, T \ r = ( S , A , γ, p 0 , p d ) .
These additional interactions enable the agent to explore using the learned policy.
These exploration trajectories are from the same distribution that will be observed at meta-test time, and therefore can be included into the meta-training process to mitigate the distributional shift issue described above.
However, meta-training requires not just states and actions, but also rewards.
In the next section, we describe a method for autonomously labeling these rollouts with synthetic reward labels to enable an agent to meta-train on this additional data.
Semi-Supervised Meta Actor-Critic
In this section, we present semi-supervised meta actor-critic (SMAC), a method that performs ofﬂine meta-training followed by self-supervised online meta-training.
For the ofﬂine meta-training, we assume access to a set of replay buffers, D
= {D i } N buff i
=1 , where each buffer corresponds to data for one task.
For self-supervised online meta-training, we assume that we can sample MDPs without a reward function.
The SMAC adaptation procedure consists of passing history through the encoder described in Section 3, resulting in a posterior q ( z | h ) .
SMAC then uses this posterior for both meta-RL training and for reward generation.
Below, we describe both components of the algorithm.
5.1 Ofﬂine Meta-Training
To learn from the user-provided ofﬂine data, we adapt the PEARL meta-learning method [43] to the ofﬂine setting.
We use an actor-critic algorithm to train a contextual policy using a set-based encoder, and update the critic by minimizing the Bellman error:
[Equation]
where ¯ w are target network weights [37] updated with the soft update [35] of ¯ w ← η · ¯ w +(1 − η ) · w .
PEARL uses soft actor critic (SAC) [19] to train their policy and Q-function.
SAC has been primarily applied in the online setting, in which a replay buffer is continuously expanded by adding data from the latest policy.
However, when naïvely applied to the ofﬂine setting, actor-critic methods such as
SAC suffer from off-policy bootstrapping error accumulation [15, 33, 51], which occurs when the target Q-function for bootstrapping Q ( s (cid:48) , a (cid:48) ) is evaluated at actions a (cid:48) outside of the training data.
To avoid this error accumulation during ofﬂine training, we update our actor with a loss that implicitly constrains the policy to stay close to the actions observed in the replay buffer, following the approach in a previously proposed single-task ofﬂine RL algorithm called AWAC [39].
AWAC uses the following loss to approximate a constrained optimization problem, where the policy is constrained to stay close to the data observed in D :
[Equation]
We estimate the value function V ( s , z ) =
E a ∼ π θ ( a | s , z ) Q ( s , a , z ) with a single sample, and λ is the resulting Lagrange multiplier for the optimization problem.
See Nair et al.
[39] for a full derivation.
This modiﬁed actor update makes it possible to train the encoder, actor, and critic on the ofﬂine data without the overestimation issues that afﬂict conventional actor-critic algorithms [33].
However, it does not address the z -space distributional shift issue discussed in Section 4, because the exploration policy learned via this ofﬂine procedure will still deviate signiﬁcantly from the behavior policy π β .
As discussed previously, we will aim to address this issue by collecting additional online data without reward labels and learning to generate reward labels if self-supervised meta-training.
Learning to generate rewards.
To continue meta-training online without ground truth reward labels, we propose to use the ofﬂine dataset to learn a generative model over meta-training task reward functions that we can use to label the transitions collected online.
Recall that during ofﬂine learning, we learn an encoder q φ e which maps experience h to a latent context z that encodes the task.
In the same way that we train our policy π θ ( a | s , z ) that conditionally decodes z into actions, as well as a
Q-function Q w ( s , a , z ) that conditionally decodes z into Q-values, we additionally train a reward decoder r φ d ( s , a , z ) 1 that conditionally decodes z into rewards.
We train the reward decoder r φ d to reconstruct the observed reward in the ofﬂine dataset through a mean squared error loss.
Because we use the latent space z for reward-decoding, we back-propagate the reward decoder loss into q φ e .
As visualized in Figure 3, we also regularize the posteriors q φ e ( z | h ) against a prior p z ( z ) to provide an information bottleneck in that latent space z and ensure that samples from p z ( z ) represent meaningful latent variables.
We found it beneﬁcial to not back-propagate the critic loss into the encoder, in contrast to prior work such as PEARL.
To summarize, we train the reward encoder and decoder by minimizing the following loss
[Equation]
[Equation]
In the next section, describe how we use this reward decoder to generate new reward labels.
5.2 Self-Supervised Online Meta-Training
We now describe the self-supervised online training procedure, during which we use the reward decoder to provide supervision.
First, we collect a trajectory τ by rolling out our exploration policy π θ conditioned on a context sampled from the prior p ( z ) .
To emulate the ofﬂine meta-training supervision, we would like to label τ with rewards that are in the distribution of meta-training tasks.
As such, we sample a replay buffer D i uniformly from D to get a history h ∼ D i from the ofﬂine data.
We then sample from the posterior z ∼ q φ e ( z | h ) and label the reward r generated of a new state and action, ( s , a ) , using the reward decoder
[Equation]
We then add the labeled trajectory to the buffer and perform actor and critic updates as in ofﬂine meta-training.
Lastly, since we do not observe additional ground-truth rewards, we do not update the reward decoder r φ d or encoder q φ e , and instead only train the policy and Q-function during the self-supervised phase.
We visualize this procedure in Figure 3.
5.3 Algorithm Summary and Details
We visualize SMAC in Figure 3.
For ofﬂine training, we assume access to ofﬂine datasets D
=
{D i } N buff i
=1 , where each buffer corresponds to data generated for one task.
Each iteration, we sample a
Algorithm
1: Input: datasets D = {D i } N buff i
=1 , policy π θ , Q-function Q w , encoder q φ e , and decoder r φ d . 2: for iteration n = 1 , 2 , . .
. , N ofﬂine do (cid:46) ofﬂine
Sample buffer D i ∼ D and two histories from buffer h , h (cid:48) ∼ D i . 4:
Use the ﬁrst history sample to h to infer z encode it z ∼ q φ e ( h ) .
Update π θ , Q w , q φ e , r φ d by minimizing L actor , L critic , L reward with samples z , h (cid:48) .
6: for iteration n = 1 , 2 , . . .
, N online do (cid:46) self-supervised phase 7:
Collect trajectory τ with π θ ( a | s , z ) , with z t ∼ p ( z ) .
Label the rewards in τ using Equation (4) and add the resulting data to D i .
Sample buffer D i ∼ D and two histories from buffer h , h (cid:48) ∼ D i .
Encode ﬁrst history z
= q φ e ( h ) .
Update π θ , Q w by minimizing L actor , L critic with samples z , h (cid:48) .
buffer D i ∼ D and a history from this buffer h ∼ D i .
We condition the stochastic encoder q φ e on this history to obtain a sample z ∼ q φ e ( z | h ) .
We then use this sample z and a second history sample h (cid:48) ∼ D i to update the Q -function, the policy, encoder, and decoder by minimizing Equation (1),
Equation (2), and Equation (3) respectively.
During the self-supervised phase, we found it beneﬁcial to train the actor with a combination of the loss in Equation (2) and the original PEARL actor loss, weighted by hyperparameter λ pearl .
We provide pseudo-code for SMAC in Algorithm 1 and a complete list of hyperparameters, such as the network architecture and RL hyperparameters, in
Appendix B.
Experiments
We proposed a method that uses additional online data to mitigate the distribution shift in z -space that occurs in ofﬂine meta-RL.
In this section, we evaluate how well the self-supervised phase of
SMAC mitigates this negative drop in performance, and compare SMAC to other ofﬂine meta-RL methods on a range of meta-RL problems that require generalization to unseen tasks at meta-test time, across multiple simulated robotics domains.
Meta-RL Tasks
We ﬁrst evaluate our method on multiple simulated meta-learning tasks that have been used in past online and ofﬂine meta-RL papers [49, 12, 43, 8, 36] (see Figure 8).
The ﬁrst task,
Cheetah Velocity , contains a two-legged “half cheetah” that can move forwards or backwards along the x-axis.
The second task, Ant Direction , contains a quadruped “ant” robot that can move in a plane.
We also evaluated SMAC on a signiﬁcantly more diverse robot manipulation metalearning task called Sawyer Manipulation , based on the goal-conditioned environment introduced in Khazatsky et al.
Sawyer Manipulation is a simulated PyBullet environment [7] which comprises a Sawyer robot arm that can manipulate drawers, pick and place objects, and push buttons.
Sampling a task T ∼ p ( T ) involves sampling both a new conﬁguration of the environment and the desired behavior to achieve.
The initial conﬁguration of the objects can vary drastically, with the presence and location of objects randomized as shown in Figure 9 and the agent is tested on one of three possible desired behaviors, such as pushing a button, opening a drawer, or lifting an object.
In all of the environments, we test the meta-RL procedure’s ability to generalize to new tasks by evaluating the policies on held-out tasks sampled from the same distribution as in the ofﬂine datasets.
We give a complete description of the possible tasks and how the prior data was collected in
Appendix B.
Comparisons and ablations.
As an upper bound, we include the performance of PEARL with online training using oracle ground-truth rewards rather than self-generated rewards, which we label
Online Oracle .
To understand the impact of using the actor loss in Equation (2), we include an ablation in which we use the actor loss from PEARL but still employ our proposed unsupervised online phase, which we label SMAC (actor ablation) .
We also include a meta-imitation baseline, which infers the task like PEARL, but then imitates the task data in the dataset.
In this baseline, we replace the actor update in Equation (2) with simply maximizing log π θ ( a | s , z ) .
We label this baseline meta behavior cloning .
This baseline illustrates the gap between ofﬂine meta-RL and imitation, and helps us understand the gap between the (highly suboptimal) behavior policy and RL.
[Figure]
o s t - A d a p t a t i o n R e t u r n s
[Figure]
a p t
[Figure]
i
[Figure]
s
[Figure]
a p t a t i
[Figure]
[Figure]
For comparisons to prior work, we include the two previously proposed ofﬂine meta-RL methods: meta-actor critic with advantage weighting (labelled MACAW ) [36] and Bayesian ofﬂine RL (labelled
BOReL ) [8].
Since these methods have only been applied to the ofﬂine phase, we report their performance only after ofﬂine training, since they do not have a self-supervised online stage.
For both prior works, we used the code released by the authors.
We trained these methods using the same ofﬂine dataset and matched hyperparameters when possible, such as batch size and network size.
Comparison results.
We plot the mean post-adaptation returns and standard deviation acrossseeds in Figure 4.
We see that across all three environments, SMAC consistently improves during the self-supervised phase, and often achieves a similar performance to the oracle that uses ground-truth reward during the online phase of learning.
SMAC also signiﬁcantly improves over meta behavior cloning, which conﬁrms that the data in the ofﬂine dataset is far from optimal.
We found that BOReL and MACAW performed comparatively poorly on all three tasks.
A likely cause for this performance is that BOReL and MACAW were both developed assuming several orders of magnitude more data than the regime that we tested.
For example, in the BOReL paper [8], the
Cheetah Velocity was trained with an ofﬂine dataset using 400 million transitions and performs additional reward relabeling using ground-truth information about the transitions.
In contrast, our ofﬂine dataset contains only 240 thousand transitions, roughly three orders of magnitude fewer transitions.
Similarly, MACAW uses 100M transitions for Cheetah Velocity , over 40 times more transitions than used in our experiments.
These prior methods also collect ofﬂine datasets by training task-speciﬁc policies , which converge to near-optimal policies within the ﬁrst million time step [19], meaning that they utilize very high-quality data.
In contrast, our data collection protocol produces more realistic ofﬂine datasets that are highly suboptimal, as evidenced by the performance of the meta behavior cloning baseline, leaving plenty of room for improvement with ofﬂine RL.
We also observed that our method improves over the performance of BOReL and MACAW even before the online phase (i.e., at zero new environment steps) on the
Cheetah and Sawyer Manipulation tasks, and achieves a particularly large improvement on the
Sawyer Manipulation environments, which are by far the most challenging and exhibit the most variability between tasks.
In this domain, we also see the largest gains from the AWAC actor update, in contrast to the actor ablation (in blue), indicating that properly handling the ofﬂine phase is also important for good performance.
In conclusion, our method (and its ablation) is the only one that is able to attain good generalization performance at meta-test time on these tasks, and actually attains performance that is close to the Online Oracle upper bound baseline, indicating that unsupervised online ﬁne-tuning is highly effective for mitigating distributional shift in meta-RL, whereas without it ofﬂine meta-RL generally does not exceed the performance of a meta-imitation learning baseline.
Supplementary Material A Additional Experimental Results
Exploration and ofﬂine dataset visualization In Figure 5, we visualize the post-adaption trajectories generated when conditioning the encoder the online exploration trajectories h online and the ofﬂine trajectories h ofﬂine .
Similar to Figure 7, and also visualize the online and ofﬂine trajectories themselves.
We see that the exploration trajectories h online and the ofﬂine trajectories h ofﬂine are very different (green vs red, respectively), but the self-supervised phase mitigates the negative impact that this distribution shift has on ofﬂine meta RL.
In particular, the post-adaptation trajectories conditioned on these two data sources (blue and orange) are similar after the self-supervised training, whereas before the self-supervised training, only the trajectories conditioned on the ofﬂine data (blue) move in multiple directions.
[Figure]
Addressing state-space distribution shift by self-supervised meta-training on test tasks.
Another source of distribution shift that can negatively impact a meta-policy is a distribution shift in state space.
While this distribution shift occurs in standard ofﬂine RL, we expect this issue to be more prominent in meta RL, where there is a focus on generalizing to completely novel tasks.
In many real-world scenarios, experiencing the state distribution of a novel task is possible, but it is the supervision (ie. reward signal) that is expensive to obtain.
Can we mitigate state distribution shift by allow the agent to meta-train in the test task environments, but without rewards?
In this experiment, we evaluate our method, SMAC, when training online on the test tasks instead of on the meta-training tasks as in the experiments in Section 6.
Prior work has explored this idea of self-supervision with test tasks in supervised learning [48] and goal-conditioned RL [29].
We use the Sawyer Manipulation environment to study how self-supervised training can mitigate state distribution shifts, as these environments contain signiﬁcant variation between tasks.
To further increase the complexity of the environment, we use a version of the environment which samples from a set of eight potential desired behaviors instead of three.
We compare self-supervised training on test tasks to self-supervised training on the set of metatraining tasks, which are also the tasks contained in the ofﬂine dataset.
A large gap in performance indicates that interacting with the test tasks can mitigate the resulting distribution shift even when no reward labels are provided.
Number of Environment Steps (x1000) −−−−−
P o s t - A d a p t a t i o n
R e t u r n s
[Figure]
We show the results in Figure 6 and ﬁnd that there is indeed a large performance gap between the two training modes, with self-supervision on test tasks improving post-adaptation returns while self-supervision on meta-training tasks does not improve post-adaptation returns.
We also compare to an oracle method that performs online training with the test tasks and the ground-truth reward signal.
We see that SMAC is competitive with the oracle, demonstrating that we do not need access to rewards in order to improve on test tasks.
Instead, the entire performance gain comes from experiencing the new state distribution of test tasks.
Overall, these results suggest that SMAC is effective for mitigate distribution shifts in both z -space and state space, even when an agent can interact in the environment without reward supervision.
Visualizing the distribution shift.
We also investigate if the self-supervised training helps speciﬁcally because it mitigates a distribution shift caused by the exploration policy.
To investigate this, we visualize the trajectories of the learned policy both before and after the self-supervised phase for the
Ant Direction task in Figure 7.
For each plot, we show trajectories from the policy π θ ( a | s , z ) when the encoder q φ e ( z | h ) is conditioned on histories from either the ofﬂine dataset ( h ofﬂine ) or from the learned exploration policy ( h online ).
Since the same policy is evaluated, differences between
[Figure]
the resulting trajectories represent the distribution shift caused by using history from the learned exploration policy rather than from the ofﬂine dataset.
We see that before the self-supervised phase, there is a large difference between the two modes that can only be attributed to the difference in h .
When using h online , the post-adaptation policy only explores one mode, but when using h ofﬂine , the policy moves in all directions.
This qualitative difference explains the large performance gap observed in Figure 2 and highlights that the adaptation procedure is sensitive to the history h used to adapt.
In contrast, after the self-supervised phase, the policy moves in all directions regardless of where the history came from.
In Appendix A, we also visualize the exploration trajectories and found that the exploration trajectories are qualitatively similar both before and after the self-supervised phase.
Together, these results illustrate the SMAC policy learns to adapt to the exploration trajectories by using the self-supervised phase to mitigate the distribution shift that occurs with naïve ofﬂine meta RL.
B Experimental Details B.1 Environment Details
In this section, we describe the state and action space of each environment.
We also describe how reward functions were generated and how the ofﬂine data was generated.
Ant Direction The Ant Direction task consists of controlling a quadruped “ant” robot that can move in a plane.
Following prior work [43, 8], the reward function is the dot product between the agent’s velocity and a direction uniformly sampled from the unit circle.
The state space is R 20 , comprising the orientation of the ant (in quaternion) as well as the angle and angular velocity of alljoints.
The action space is [ − 1 , 1] 8 , with each dimension corresponding to the torque applied to a respective joint.
The ofﬂine data is collected by running
PEARL [43] on this meta RL task withpre-sampled 2 target velocities.
We terminate
PEARL after 100 iterations, with each iteration containing at least 1000 new transitions.
In
PEARL, there are two replay buffers saved for each task, one for sampling data for training the encoder and another for training the policy and
Q-function.
We will call the former replay buffer the encoder replay buffer and the latter the RL replay buffer.
The encoder replay buffer contains data generated by only the exploration policy, in which z ∼ p
z ( z ) .
The RL replay buffer contains all data generated, including both exploration and post-adaptation, in which z ∼ q φ e ( z | h ) .
To make the ofﬂine dataset, we load the last 1200 samples of the RL replay buffer and the last 400 transitions from the encoder replay buffer into corresponding RL and encoder replay buffers for SMAC.
In the initial submission, we mistakenly stated that we used 1200 samples when in fact we used 1600 samples for each task.
During the self-supervised phase, we add all new data to both replay buffers.
Cheetah Velocity The Cheetah Velocity task consists of controlling a two-legged “half cheetah” that can move forwards or backwards along the x-axis.
Following prior work [43, 8], the reward function is the absolute difference product between the agent’s x-velocity and a velocity uniformly sampled from [0 , 3] .
The state space is R 20 , comprising the z -position; the cheetah’s x- and zvelocity; the angle and angular velocity of each joint and the half-cheetah’s y-angle; and the XYZ position of the center of mass.
The action space is [ − 1 , 1] 6 , with each dimension corresponding to the torque applied to a respective joint.
The ofﬂine data is collected in the same way as in the Ant Direction task, using a run from PEARL with 100 pre-sampled target velocities.
For the ofﬂine dataset, we use the ﬁrst 1200 samples from the RL replay buffer and last 400 samples from the encoder replay buffer after 50 PEARL iterations, with each iteration containing at least 1000 new transitions.
For only this environment, we found that it was beneﬁcial to freeze the encoder buffer during the self-supervised phase.
Sawyer Manipulation The state space, action space, and reward is described in Section 6.
Tasks are generated by sampling the initial conﬁguration, and then the desired behavior.
There are ﬁve objects: a drawer opened by handle, a drawer opened by button, a button, a tray, and a graspable object.
If an object is not present, it takes on position 0 in the corresponding element of the state space.
First, the presence or absence of each of the ﬁve is randomized.
Next, the position of the drawers (from 2 sides), initial position of the tray (from 4 positions), and the object (from 4 positions) is randomized.
Finally, the desired behavior is randomly chosen from the following list, but only including the ones that are possible in the scene: "move hand", "open top drawer with handle", or "open bottom drawer with button".
The ofﬂine data is collected using a scripted controller that does not know the desired behavior and randomly performs potential tasks in the scene, choosing another task if it ﬁnishes one task before the trajectory ends.
This data is loaded into a single replay buffer used for both the encoder and RL.
Ofﬂine data collection.
For the MuJoCo tasks, we generate data by following a similar procedure as [15], in which we use the replay buffer from a single PEARL run that uses the ground-truth reward.
We limit the data collection to 1200 transitions or 6 trajectories per task and terminate the PEARL run early, forcing the meta-RL agent to learn from sub-optimal data.
For Sawyer Manipulation , we collect data using a scripted policy that randomly performs as many potential tasks in the environment, without knowing what the desired behavior in a sampled task is.
We used 50 training tasks andtrajectories of length 75 per task.
In the ofﬂine dataset, the robot succeeds on the task 46% of the transitions.
B.2 Hyperparameters
We list the hyperparameters for training the policy, encoder, decoder, and Q-network in Table 1.
If hyperparameters were different across environments, they are listed in Table 2.
For pretraining, we use the same hyperparameters and train for 50000 gradient steps.
Below, we give details on non-standard hyperparameters and architectures.
Batch sizes.
The RL batch size is the batch size per task when sampling ( s , a , r, s (cid:48) ) tuples to update the policy and Q-network.
The encoder batch size is the size of the history h per task used to conditioned the encoder q φ e ( z | h ) .
The meta batch size is how many tasks batches were sampled and concatenated for both the RL and encoder batches.
In other words, for each gradient update, the policy and Q-network observe ( RL batch size ) × ( meta batch size ) transitions and the encoder observes ( RL batch size ) × ( encoder batch size ) transitions.
[Table] [Table]
horizon (max # of transitions per trajectory)
[Table]
Encoder architecture.
The encoder uses the same architecture as in Rakelly et al.
The posterior is given as the product of independent factors
[Equation]
where each factor is a multi-variate Gaussian over R d z with learned mean and diagonal variance.
In other words,
[Equation]
The mean and standard deviation is the output of a single MLP network with output dimensionality 2 × d z .
The output of the MLP network is split into two halves.
The ﬁrst half is the mean and the second half is passed through the softplus activation to get the standard deviation.
Self-supervised actor update.
The parameter λ pearl controls the actor loss during the selfsupervised phase, which is
[Equation]
where L PEARLactor is the actor loss from PEARL [43].
For reference, the PEARL actor loss is
[Equation]
When the parameter λ pearl is zero, the actor update is equivalent to the actor update in AWAC [39].