A UTOMATIC D ATA A UGMENTATION FOR G ENERALIZATION IN R EINFORCEMENT L EARNING
Anonymous authors
Paper under double-blind review
A BSTRACT
Deep reinforcement learning (RL) agents often fail to generalize beyond their training environments.
To alleviate this problem, recent work has proposed the use of data augmentation.
However, different tasks tend to beneﬁt from different types of augmentations and selecting the right one typically requires expert knowledge.
In this paper, we introduce three approaches for automatically ﬁnding an effective augmentation for any RL task.
These are combined with two novel regularization terms for the policy and value function, required to make the use of data augmentation theoretically sound for actor-critic algorithms.
We evaluate our method on the Procgen benchmark which consists of 16 procedurally generated environments and show that it improves test performance by 40% relative to standard RL algorithms.
Our approach also outperforms methods speciﬁcally designed to improve generalization in RL, thus setting a new state-of-the-art on Procgen.
In addition, our agent learns policies and representations which are more robust to changes in the environment that are irrelevant for solving the task, such as the background.
I NTRODUCTION
Generalization to new environments remains a major challenge in deep reinforcement learning (RL).
Current methods fail to generalize to unseen environments even when trained on similar settings (Farebrother et al., 2018; Packer et al., 2018;
Zhang et al., 2018a; Cobbe et al., 2018; Gamrian & Goldberg, 2019; Cobbe et al., 2019; Song et al., 2020).
This indicates that standard RL agents memorize speciﬁc trajectories rather than learning transferable skills.
Several strategies have been proposed to alleviate this problem, such as the use of regularization (Farebrother et al., 2018;
Zhang et al., 2018a; Cobbe et al., 2018; Igl et al., 2019), data augmentation (Cobbe et al., 2018; Lee et al., 2020; Ye et al., 2020;
Kostrikov et al., 2020; Laskin et al., 2020), or representation learning (Zhang et al., 2020a;c).
In this work, we focus on the use of data augmentation in RL.
We identify key differences between supervised learning and reinforcement learning which need to be taken into account when using data augmentation in RL.
More speciﬁcally, we show that a naive application of data augmentation can lead to both theoretical and practical problems with standard RL algorithms, such as unprincipled objective estimates and poor performance.
As a solution, we propose Data-regularized Actor-Critic or DrAC , a new algorithm that enables the use of data augmentation with actor-critic algorithms in a theoretically sound way.
Speciﬁcally, we introduce two regularization terms which constrain the agent’s policy and value function to be invariant to various state transformations.
Empirically, this approach allows the agent to learn useful behaviors (outperforming strong RL baselines) in settings in which a naive use of data augmentation completely fails or converges to a sub-optimal policy.
While we use Proximal
Policy Optimization (PPO, Schulman et al.
(2017)) to describe and validate our approach, the method can be easily integrated with any actor-critic algorithm with a discrete stochastic policy such as
A3C (Mnih et al., 2013), SAC (Haarnoja et al., 2018), or IMPALA (Espeholt et al., 2018).
The current use of data augmentation in RL either relies on expert knowledge to pick an appropriate augmentation (Cobbe et al., 2018; Lee et al., 2020; Kostrikov et al., 2020) or separately evaluates a large number of transformations to ﬁnd the best one (Ye et al., 2020;
Laskin et al., 2020).
In this paper, we propose three methods for automatically ﬁnding a useful augmentation for a given RL task.
The ﬁrst two learn to select the best augmentation from a ﬁxed set, using either a variant of the upper conﬁdence bound algorithm (UCB, Auer (2002)) or meta-learning (RL 2 , Wang et al.
We refer to these methods as UCB-DrAC and RL2-DrAC , respectively.
The third method, MetaDrAC , directly meta-learns the weights of a convolutional network, without access to predeﬁned transformations (MAML, Finn et al.
Figure 1 gives an overview of UCB-DrAC.
We evaluate these approaches on the Procgen generalization benchmark (Cobbe et al., 2019) which consists of 16 procedurally generated environments with visual observations.
Our results show that
UCB-DrAC is the most effective among these at ﬁnding a good augmentation, and is comparable or better than using DrAC with the best augmentation from a given set.
UCB-DrAC also outperforms baselines speciﬁcally designed to improve generalization in RL (Igl et al., 2019; Lee et al., 2020;
Laskin et al., 2020) on both train and test.
In addition, we show that our agent learns policies and representations that are more invariant to changes in the environment which do not alter the reward or transition function ( i.e. they are inconsequential for control), such as the background theme.
To summarize, our work makes the following contributions: (i) we introduce a principled way of using data augmentation with actor-critic algorithms, (ii) we propose a practical approach for automatically selecting an effective augmentation in RL settings, (iii) we show that the use of data augmentation leads to policies and representations that better capture task invariances, and (iv) we demonstrate state-of-the-art results on the Procgen benchmark.
B ACKGROUND
We consider a distribution q ( m ) of Markov decision processes (MDPs, Bellman (1957)) m ∈ M , with m deﬁned by the tuple ( S m , A , T m , R m , p m , γ ) , where S m is the state space, A is the action space, T m ( s (cid:48) | s, a ) is the transition function, R m ( s, a ) is the reward function, and p m ( s 0 ) is the initial state distribution.
During training, we restrict access to a ﬁxed set of MDPs, M train = { m 1 , . . .
, m n } , where m i ∼ q , ∀ i = 1 , n .
The goal is to ﬁnd a policy π θ which maximizes the expected discounted reward over the entire distribution of MDPs, J ( π θ ) =
E q,π,T m ,p m (cid:2) (cid:80) Tt =
γ t R m ( s t , a t ) (cid:3) .
In practice, we use the Procgen benchmark which contains 16 procedurally generated games.
Each game corresponds to a distribution of MDPs q ( m ) , and each level of a game corresponds to an MDP sampled from that game’s distribution m ∼ q .
The MDP m is determined by the seed ( i.e. integer) used to generate the corresponding level.
Following the setup from Cobbe et al.
(2019), agents are trained on a ﬁxed set of n = 200 levels (generated using seeds from 1 to 200) and tested on the full distribution of levels (generated by sampling seeds uniformly at random from all computer integers).
Proximal Policy Optimization (PPO, Schulman et al.
(2017)) is an actor-critic algorithm that learns a policy π θ and a value function V θ with the goal of ﬁnding an optimal policy for a given MDP.
PPO alternates between sampling data through interaction with the environment and maximizing a clipped surrogate objective function J PPO using stochastic gradient ascent.
See Appendix A for a full description of PPO.
One component of the PPO objective is the policy gradient term J PG , which is estimated using importance sampling:
[Equation]
where ˆ A ( · ) is an estimate of the advantage function, π θ old is the behavior policy used to collect trajectories ( i.e. that generates the training distribution of states and actions), and π θ is the policy we want to optimize ( i.e. that generates the true distribution of states and actions).
A UTOMATIC D ATA A UGMENTATION FOR RL 3. D ATA A UGMENTATION IN RL
Image augmentation has been successfully applied in computer vision for improving generalization on object classiﬁcation tasks (Simard et al., 2003; Cire¸san et al., 2011; Ciregan et al., 2012;
Krizhevsky et al., 2012).
As noted by Kostrikov et al.
(2020), those tasks are invariant to certain image transformations such as rotations or ﬂips, which is not always the case in RL.
For example, if your observation is ﬂipped, the corresponding reward will be reversed for the left and right actions and will not provide an accurate signal to the agent.
While data augmentation has been previously used in RL settings without other algorithmic changes (Cobbe et al., 2018;
Ye et al., 2020; Laskin et al., 2020), we argue that this approach is not theoretically sound.
If transformations are naively applied to observations in PPO’s buffer, as done in Laskin et al.
(2020), the PPO objective changes and equation (1) is replaced by
[Equation]
where f : S × H → S is the image transformation.
However, the right hand side of the above equation is not a sound estimate of the left hand side because π θ ( a | f ( s ))
(cid:54) =
π θ ( a | s ) , since nothing constrains π θ ( a | f ( s )) to be close to π θ ( a | s ) .
Moreover, one can deﬁne certain transformations f ( · ) that result in an arbitrarily large ratio π θ ( a | f ( s ))
/π θ ( a | s ) .
Figure 2 shows examples where a naive use of data augmentation prevents PPO from learning a good policy in practice, suggesting that this is not just a theoretical concern.
In the following section, we propose an algorithmic change that enables the use of data augmentation with actor-critic algorithms in a principled way.
3. P OLICY AND V ALUE F UNCTION R EGULARIZATION
Inspired by the recent work of Kostrikov et al.
(2020), we propose two novel regularization terms for the policy and value functions that enable the proper use of data augmentation for actor-critic algorithms.
Our algorithmic contribution differs from that of Kostrikov et al.
(2020) in that it constrains both the actor and the critic, as opposed to only regularizing the Q-function.
Following Kostrikov et al.
(2020), we deﬁne an optimality-invariant state transformation f : S ×
H → S as a mapping that preserves both the agent’s policy π and its value function V such that
V ( s ) =
V ( f ( s, ν )) and π ( a | s )
=
π ( a | f
( s, ν )) , ∀ s ∈ S , ν ∈ H , where ν are the parameters of f ( · ) , drawn from the set of all possible parameters H .
To ensure that the policy and value functions are invariant to such transformation of the input state, we propose an additional loss term for regularizing the policy,
[Equation]
as well as an extra loss term for regularizing the value function,
[Equation]
Thus, our data-regularized actor-critic method, or DrAC , maximizes the following objective:
[Equation]
where α r is the weight of the regularization term (see Algorithm 1).
The use of G π and G V ensures that the agent’s policy and value function are invariant to the transformations induced by various augmentations.
Particular transformations can be used to impose certain inductive biases relevant for the task ( e.g. invariance with respect to colors or translations).
In addition, G π and G V can be added to the objective of any actor-critic algorithm with a discrete stochastic policy ( e.g. A3C, TRPO, ACER, SAC, or IMPALA) without any other changes.
Note that when using DrAC, as opposed to the method proposed by Laskin et al.
(2020), we still use the correct importance sampling estimate of the left hand side objective in equation (1) (instead of a wrong estimate as in equation (2)).
This is because the transformed observations f ( s ) are only used to compute the regularization losses G π and G V , and thus are not used for the main PPO objective.
Without these extra terms, the only way to use data augmentation is as explained in Section 3.1, which leads to inaccurate estimates of the PPO objective.
Hence, DrAC beneﬁts from the regularizing effect of using data augmentation, while mitigating adverse consequences on the RL objective.
See
Appendix B for a more detailed explanation of why a naive application of data augmentation with certain policy gradient algorithms is theoretically unsound. do 7: 8: ˆ π i ← π φ (
| s i ) 9: ˆ V i ← V φ ( s i ) 10: end for 11: G π ( θ ) =
[Equation]
M (cid:80) Mi =1 KL [ˆ π i | π θ ( ·| f
( s i , ν i ))]
(cid:46) Regularize the policy 12:
G V ( φ ) = 1 M (cid:80) Mi
=1 (cid:16) ˆ V
i − V φ ( f ( s i , ν i ))
(cid:17)(cid:46)
Regularize the value function 13:
J DrAC ( θ, φ ) =
J PPO ( θ, φ ) − α r
( G π ( θ ) + G V
( φ ))
(cid:46) Compute the total loss function 14: θ ← arg max θ J DrAC (cid:46) Update the policy 15: φ ← arg max φ J DrAC (cid:46) Update the value function 16: end for 17: end for
3. A UTOMATIC D ATA A UGMENTATION
Since different tasks beneﬁt from different types of transformations, we would like to design a method that can automatically ﬁnd an effective transformation for any given task.
Such a technique would signiﬁcantly reduce the computational requirements for applying data augmentation in RL.
In this section, we describe three approaches for doing this.
In all of them, the augmentation learner is trained at the same time as the agent learns to solve the task using DrAC.
Hence, the distribution of rewards varies signiﬁcantly as the agent improves, making the problem highly nonstationary.
Upper Conﬁdence Bound.
The problem of selecting a data augmentation from a given set can be formulated as a multi-armed bandit problem, where the action space is the set of available transformations F = { f 1 , . . .
, f n } .
A popular algorithm for such settings is the upper conﬁdence bound or UCB (Auer, 2002), which selects actions according to the following policy:
[Equation]
where f t is the transformation selected at time step t , N t ( f ) is the number of times transformation f has been selected before time step t and c is UCB’s exploration coefﬁcient.
Before the t-th DrAC update, we use equation (6) to select an augmentation f .
Then, we use equation (5) to update the agent’s policy and value function.
We also update the counter: N t ( f ) =
N t − 1 ( f ) + 1 .
Next, we collect rollouts with the new policy and update the Q-function: Q t ( f ) = 1 K (cid:80) ti = t − K R ( f i = f ) , which is computed as a sliding window average of the past K mean returns obtained by the agent after being updated using augmentation f .
We refer to this algorithm as UCB-DrAC (Algorithm 4).
Note that UCB-DrAC’s estimation of Q ( f ) differs from that of a typical UCB algorithm which uses rewards from the entire history.
However, the choice of estimating Q ( f ) using only more recent rewards is crucial due to the nonstationarity of the problem.
Meta-Learning the Selection of an Augmentation.
Alternatively, the problem of selecting a data augmentation from a given set can be formulated as a meta-learning problem.
Here, we consider a meta-learner like the one proposed by Wang et al.
Before each DrAC update, the meta-learner selects an augmentation, which is then used to update the agent using equation (5).
We then collect rollouts using the new policy and update the meta-learner using the mean return of these trajectories.
We refer to this approach as RL2-DrAC (Algorithm 4).
Meta-Learning the Weights of an Augmentation.
Another approach for automatically ﬁnding an appropriate augmentation is to directly learn the weights of a certain transformation rather than selecting an augmentation from a given set.
In this work, we focus on meta-learning the weights of a convolutional network which can be applied to the observations to obtain a perturbed image.
We meta-learn the weights of this network using an approach similar to the one proposed by Finn et al.
For each agent update, we also perform a meta-update of the transformation function by splitting DrAC’s buffer into meta-train and meta-test sets.
We refer to this approach as Meta-DrAC (Algorithm 4).
More details about the implementation of these methods can be found in Appendix D.
E XPERIMENTS
In this section, we evaluate our methods on the Procgen benchmark (Cobbe et al., 2019) which consists of 16 procedurally generated games (see Figure 6 in Appendix G).
Procgen has a number of attributes that make it a good testbed for generalization in RL: (i) it has a diverse set of games in a similar spirit with the ALE benchmark (Bellemare et al., 2013), (ii) each of these games has procedurally generated levels which present agents with meaningful generalization challenges, (iii) agents have to learn motor control directly from images, and (iv) it has a clear protocol for testing generalization.
All environments use a discrete 15 dimensional action space and produce 64 × 64 × 3 RGB observations.
We use Procgen’s easy setup, so for each game, agents are trained on 200 levels and tested on the full distribution of levels.
We use PPO as a base for all our methods.
More details about our experimental setup and hyperparameters can be found in Appendix E.
Data Augmentation.
In our experiments, we use a set of eight transformations: crop, grayscale, cutout, cutout-color, ﬂip, rotate, random convolution and color-jitter (Krizhevsky et al., 2012; DeVries & Taylor, 2017).
We use RAD ’s
(Laskin et al., 2020) implementation of these transformations, except for crop , in which we pad the image with 12 (boundary) pixels on each side and select random crops of 64 × 64 .
We found this implementation of crop to be signiﬁcantly better on Procgen, and thus it can be considered an empirical upper bound of RAD in this case.
For simplicity, we will refer to our implementation as RAD.
DrAC uses the same set of transformations as RAD, but is trained with additional regularization losses for the actor and the critic, as described in Section 3.2.
Automatic Selection of Data Augmentation.
We compare three different approaches for automatically ﬁnding an effective transformation: UCB-DrAC which uses UCB (Auer, 2002) to select an augmentation from a given set, RL2-DrAC which uses RL 2 (Wang et al., 2016) to do the same, and
Meta-DrAC which uses MAML (Finn et al., 2017) to meta-learn the weights of a convolutional network.
Meta-DrAC is implemented using the higher library (Grefenstette et al., 2019).
Note that we do not expect these approaches to be better than DrAC with the best augmentation.
In fact, DrAC with the best augmentation can be considered to be an upper bound for these automatic approaches since it uses the best augmentation during the entire training process.
Ablations.
Rand-DrAC uses a uniform distribution to select an augmentation each time.
CropDrAC uses crop for all games (which is the most effective augmentation on half of the Procgen games).
UCB-RAD combines UCB with RAD ( i.e. it does not use the regularization terms).
Baselines.
We also compare with Rand-FM (Lee et al., 2020) and IBAC-SNI (Igl et al., 2019), two methods speciﬁcally designed for improving generalization in RL and previously tested on CoinRun, one of the Procgen games.
Rand-FM uses a random convolutional networks to regularize the learned representations, while IBAC-SNI uses an information bottleneck with selective noise injection.
[Table]
Evaluation Metrics.
At the end of training, for each method and each game, we compute the average score over 100 episodes and 10 different seeds.
The scores are then normalized using the corresponding PPO score on the same game.
We aggregate the normalized scores over all 16 Procgen games and report the resulting mean, median, and standard deviation (Table 1).
For a per-game breakdown, see Tables 6 and 7 in Appendix I.
4. G ENERALIZATION A BILITY
Table 1 shows train and test performance on Procgen.
UCB-DrAC signiﬁcantly outperforms PPO,
Rand-FM, and IBAC-SNI.
Regularizing the policy and value function leads to improvements over merely using data augmentation, and thus the performance of DrAC is better than that of RAD (both using the best augmentation for each game).
Our experiments show that the most effective way of automatically ﬁnding an augmentation is UCB-DrAC.
As expected, meta-learning the weights of a
CNN using Meta-DrAC performs reasonably well on the games in which the random convolution augmentation helps.
But overall, Meta-DrAC and RL2-DrAC are worse than UCB-DrAC.
In addition,
UCB is generally more stable, easier to implement, and requires less ﬁne-tuning compared to metalearning algorithms.
See Figures 7 and 8 in Appendix J for a comparison of these three approaches on each game.
Moreover, automatically selecting the augmentation from a given set using UCB-DrAC performs similarly well or even better than a method that uses the best augmentation for each task throughout the entire training process.
UCB-DrAC also achieves higher returns than an ablation that uses a uniform distribution to select an augmentation each time, Rand-DrAC.
Nevertheless, UCBDrAC is better than Crop-DrAC, which uses crop for all the games (which is the best augmentation for eight of the Procgen games as shown in Tables 4 and 5 from Appendix H).
4. R EGULARIZATION E FFECT
In Section 3.1, we argued that additional regularization terms are needed in order to make the use of data augmentation in RL theoretically sound.
However, one might wonder if this problem actually appears in practice.
Thus, we empirically investigate the effect of regularizing the policy and value
[Figure]
function.
For this purpose, we compare the performance of RAD and DrAC with grayscale and random convolution augmentations on Chaser, Miner, and StarPilot.
Figure 2 shows that not regularizing the policy and value function with respect to the transformations used can lead to drastically worse performance than vanilla RL methods, further emphasizing the importance of these loss terms.
In contrast, using the regularization terms as part of the RL objective (as DrAC does) results in an agent that is comparable or, in some cases, signiﬁcantly better than PPO.
4. A UTOMATIC A UGMENTATION
Our experiments indicate there is not a single augmentation that works best across all Procgen games (see Tables 4 and 5 in Appendix H).
Moreover, our intuitions regarding the best transformation for each game might be misleading.
For example, at a ﬁrst sight, Ninja appears to be somewhat similar to Jumper, but the augmentation that performs best on Ninja is color-jitter, while for Jumper is random-conv (see Tables 4 and 5).
In contrast, Miner seems like a different type of game than
Climber or Ninja, but they all have the same best performing augmentation, namely color-jitter.
These observations further underline the need for a method that can automatically ﬁnd the right augmentation for each task.
Table 1 along with Figures 7 and 8 in the Appendix compare different approaches for automatically ﬁnding an augmentation, showing that UCB-DrAC performs best and reaches the asymptotic performance obtained when the most effective transformation for each game is used throughout the entire training process.
Figure 3 illustrates an example of UCB’s policy during training on Ninja and
Dodgeball, showing that it converges to always selecting the most effective augmentation, namely color-jitter for Ninja and crop for Dodgeball.
Figure 5 in Appendix F illustrates how UCB’s behavior varies with its exploration coefﬁcient.
4. R OBUSTNESS A NALYSIS
To further investigate the generalizing ability of these agents, we analyze whether the learned policies and state representations are invariant to changes in the observations which are irrelevant for solving the task.
We ﬁrst measure the Jensen-Shannon divergence (JSD) between the agent’s policy for an observation from a training level and a modiﬁed version of that observation with a different background theme ( i.e. color and pattern).
Note that the JSD also represents a lower bound for the joint empirical risk across train and test (Ilse et al., 2020).
The background theme is randomly selected from the set of backgrounds available for all other Procgen environments, except for the one of the original training level.
Note that the modiﬁed observation has the same semantics as the original one (with respect to the reward function), so the agent should have the same policy in both cases.
Note that many of the backgrounds are not uniform and can contain items such as trees or planets which can be easily
[Figure]
[Table]
misled for objects the agent can interact with.
As seen in Table 2, UCB-DrAC has a lower JSD than
PPO, indicating that it learns a policy that is more robust to changes in the background.
To quantitatively evaluate the quality of the learned representation, we use the cycle-consistency metric proposed by Aytar et al.
and also used by Lee et al.
See Appendix C for more details about this metric.
Table 2 reports the percentage of input observations in the seen environment that are cycle-consistent with trajectories in modiﬁed unseen environments, which have a different background but the same layout.
UCB-DrAC has higher cycle-consistency than PPO, suggesting that it learns representations that better capture relevant task invariances.
4. D EEP M IND C ONTROL S UITE E XPERIMENTS
In this section, we evaluate our approach on the DeepMind Control Suite from pixels (DMC, Tassa et al.
We use four tasks, namely Cartpole Balance, Finger Spin, Walker Walk, and Cheetah
Run, in three settings with different types of backgrounds, namely the default , simple distractors, and natural videos from the Kinetics dataset (Kay et al., 2017), as introduced in Zhang et al.
(2020b).
See
Figure 9 for a few examples.
Note that in the simple and natural settings, the background is sampled from a list of videos at the beginning of each episode, which creates spurious correlations between the backgrounds and the rewards.
In the simple and natural distractor settings, as shown in Figure 11,
UCB-DrAC outperforms PPO and RAD with the best augmentation on all these environments in the most challenging setting with natural distractors.
See Appendix K for results on DMC with default and simple distractor backgrounds, where our method also outperforms the baselines.
R ELATED W ORK
Generalization in Deep RL.
A recent body of work has pointed out the problem of overﬁtting in deep RL (Rajeswaran et al., 2017; Machado et al., 2018; Packer et al., 2018; Zhang et al., 2018a;b;
Cobbe et al., 2018; 2019; Yarats et al., 2019; Raileanu & Rocktäschel, 2020).
A promising approach to prevent overﬁtting is to apply regularization techniques originally developed for supervised learning
[Figure]
such as dropout (Srivastava et al., 2014) or batch normalization (Ioffe & Szegedy, 2015).
Farebrother et al.
(2018) and Cobbe et al.
(2018) show that such regularization methods can improve the generalization ability of RL agents in Atari (Machado et al., 2018) and CoinRun (Cobbe et al., 2018), respectively.
Similarly, Igl et al.
(2019) use selective noise injection with a variational information bottleneck, while Lee et al.
(2020) regularize the agent’s representation with respect to random convolutional transformations.
More recently, Sonar et al.
(2020) learn invariant policies, Zhang et al.
(2020a)
and
Zhang et al.
(2020c) learn state abstractions using bisimulation, Roy & Konidaris (2020) align the features of two domains using Wasserstein distance, while Igl et al.
(2020) reduce non-stationarity using policy distillation, and Mazoure et al.
(2020) maximize the mutual information between the agent’s internal representation of successive time steps.
More similar to our work, Cobbe et al.
, Ye et al.
(2020) and Laskin et al.
(2020) add augmented observations to the training buffer of an RL agent.
However, as we show here, naively applying data augmentation in RL can lead to both theoretical and practical issues.
Our algorithmic contributions alleviate these problems while still beneﬁtting from the regularization effect of data augmentation.
Data Augmentation has been extensively used in computer vision for both supervised (LeCun et al., 1989; Becker & Hinton, 1992; LeCun et al., 1998; Simard et al., 2003; Cire¸san et al., 2011; Ciresan et al., 2011; Krizhevsky et al., 2012) and self-supervised (Dosovitskiy et al., 2016; Misra & van der
Maaten, 2019) learning.
More recent work uses data augmentation for contrastive learning, leading to state-of-the-art results on downstream tasks (Ye et al., 2019; Hénaff et al., 2019;
He et al., 2019;
Chen et al., 2020).
Domain randomization can also be considered a type of data augmentation, which has proven useful for transferring RL policies from simulation to the real world (Tobin et al., 2017).
However, domain randomization requires access to a physics simulator, which is not always available.
Recently, a few papers propose the use of data augmentation in RL (Cobbe et al., 2018; Lee et al., 2020; Srinivas et al., 2020; Kostrikov et al., 2020;
Laskin et al., 2020), but all of them use a ﬁxed (set of) augmentation(s) rather than automatically ﬁnding the most effective one.
The most similar work to ours is that of Kostrikov et al.
(2020), who propose to regularize the Q-function in Soft Actor-Critic (SAC) (Haarnoja et al., 2018)
using random shifts of the input image.
Our work differs from theirs in that it automatically selects an augmentation from a given set, regularizes both the actor and the critic, and focuses on the problem of generalization rather than sample efﬁciency.
While there is a body of work on the automatic use of data augmentation (Cubuk et al., 2019b;a; Fang et al., 2019;
Shi et al., 2019; Li et al., 2020), these approaches were designed for supervised learning and, as we explain here, cannot be applied to RL without further algorithmic changes.
D ISCUSSION
In this work, we propose UCB-DrAC, a method for automatically ﬁnding an effective data augmentation for RL tasks.
Our approach enables the principled use of data augmentation with actor-critic algorithms by regularizing the policy and value functions with respect to state transformations.
We show that UCB-DrAC avoids the theoretical and empirical pitfalls typical in naive applications of data augmentation in RL.
Our approach improves training performance by 19% and test performance by 40% on the Procgen benchmark, and sets a new state-of-the-art on the Procgen benchmark.
In addition, the learned policies and representations are more invariant to spurious correlations between observations and rewards.
A promising avenue for future research is to use a more expressive function class for meta-learning the augmentations.
A PPO
Proximal Policy Optimization (PPO)
Schulman et al.
(2017) is an actor-critic RL algorithm that learns a policy π θ and a value function V θ with the goal of ﬁnding an optimal policy for a given MDP.
PPO alternates between sampling data through interaction with the environment and optimizing an objective function using stochastic gradient ascent.
At each iteration, PPO maximizes the following objective:
[Equation]
where α 1 , α 2 are weights for the different loss terms, S π θ is the entropy bonus for aiding exploration,
J V is the value function loss deﬁned as
[Equation]
The policy objective term J π is based on the policy gradient objective which can be estimated using importance sampling in off-policy settings ( i.e. when the policy used for collecting data is different from the policy we want to optimize):
[Equation]
where ˆ A ( · ) is an estimate of the advantage function, θ old are the policy parameters before the update, π θ old is the behavior policy used to collect trajectories ( i.e. that generates the training distribution of states and actions), and π θ is the policy we want to optimize ( i.e. that generates the true distribution of states and actions).
This objective can also be written as
[Equation]
9) where
[Equation]
is the importance weight for estimating the advantage function.
PPO is inspired by TRPO (Schulman et al., 2015), which constrains the update so that the policy does not change too much in one step.
This signiﬁcantly improves training stability and leads to better results than vanilla policy gradient algorithms.
TRPO achieves this by minimizing the KL divergence between the old ( i.e. before an update) and the new ( i.e. after an update) policy.
PPO implements the constraint in a simpler way by using a clipped surrogate objective instead of the more complicated
TRPO objective.
More speciﬁcally, PPO imposes the constraint by forcing r ( θ ) to stay within a small interval around 1, precisely [1 − (cid:15), 1 + (cid:15) ] , where (cid:15) is a hyperparameter.
The policy objective term from equation (7) becomes
[Equation]
where ˆ A = ˆ
A θ old ( s, a ) for brevity.
The function clip( r ( θ ) , 1 − (cid:15), 1 + (cid:15) ) clips the ratio to be no more than 1 + (cid:15) and no less than 1 − (cid:15) .
The objective function of PPO takes the minimum one between the original value and the clipped version so that agents are discouraged from increasing the policy update to extremes for better rewards.
Note that the use of the Adam optimizer (Kingma & Ba, 2015) allows loss components of different magnitudes so we can use G π and G V from equations (3) and (4) to be used as part of the DrAC objective in equation (5) with the same loss coefﬁcient α r .
This alleviates the burden of hyperparameter search and means that DrAC only introduces a single extra parameter α r .
B N AIVE A PPLICATION OF D ATA A UGMENTATION IN RL
In this section, we further clarify why a naive application of data augmentation with certain RL algorithms is theoretically unsound.
This argument applies for all algorithms that use importance sampling for estimating the policy gradient loss, including TRPO, PPO, IMPALA, or ACER.
The use of importance sampling is typically employed when the algorithm performs more than a single policy update using the same data in order to correct for the off-policy nature of the updates.
For brevity, we will use PPO to explain this problem.
The correct estimate of the policy gradient objective used in PPO is the one in equation (1) (or equivalently, equation (8)) which does not use the augmented observations at all since we are estimating advantages for the actual observations, A ( s, a ) .
The probability distribution used to sample advantages is π old ( a | s ) (rather than π old ( a | f ( s )) since we can only interact with the environment via the true observations and not the augmented ones (because the reward and transition functions are not deﬁned for augmented observations).
Hence, the correct importance sampling estimate uses π ( a | s ) /π old ( a | s ) .
Using π ( a | f ( s )) /π old ( a | f ( s )) instead would be incorrect for the reasons mentioned above.
What we argue is that, in the case of RAD, the only way to use the augmented observations f ( s ) is in the policy gradient objective, whether by π ( a | f ( s ))
/π old ( a | f ( s )) or π ( a | f ( s ))
/π old ( a | s ) , depending on the exact implementation, but both of these are incorrect.
In contrast, DrAC does not change the policy gradient objective at all which remains the one in equation (1) and instead uses the augmented observations in the additional regularization losses, as shown in equations (3), (4), and (5).
C C YCLE -C ONSISTENCY
Here is a description of the cycle-consistency metric proposed by Aytar et al.
and also used in Lee et al.
(2020) for analyzing the learned representations of RL agents.
Given two trajectories V and U , v i ∈ V ﬁrst locates its nearest neighbor in the other trajectory u j = argmin u ∈ U (cid:107) h ( v i ) − h ( u ) (cid:107) 2 , where h ( · ) denotes the output of the penultimate layer of trained agents.
Then, the nearest neighbor of u j ∈ V is located, i.e. , v k = argmin v ∈ V (cid:107) h ( u j ) − h ( u j ) (cid:107) 2 , and v i is deﬁned as cycle-consistent if | i − k | ≤ 1 , i.e. , it can return to the original point.
Note that this cycle-consistency implies that two trajectories are accurately aligned in the hidden space.
Similar to Aytar et al.
(2018), we also evaluate the three-way cycle-consistency by measuring whether vi remains cycle-consistent along both paths, V → U → J → V and V → J → U → V , where J is the third trajectory.
D A UTOMATIC D ATA A UGMENTATION A LGORITHMS
In this section, we provide more details about the automatic augmentation approaches, as well as pseudocodes for all three methods we propose.
RL2-DrAC uses an LSTM (Hochreiter & Schmidhuber, 1997) network to select an effective augmentation from a given set, which is used to update the agent’s policy and value function according to the
DrAC objective from Equation (5).
We will refer to this network as a (recurrent) selection policy.
The
LSTM network takes as inputs the previously selected augmentation and the average return obtained after performing one update of the DrAC agent with this augmentation (using Algorithm 1 with K=1).
The LSTM outputs an augmentation from the given set and is rewarded using the average return obtained by the agent after one update with the selected augmentation.
The LSTM is trained using
REINFORCE (Williams, 2004).
See Algorithm 3 for a pseudocode of RL2-DrAC. Meta-DrAC meta-learns
the weights of a convolutional neural network (CNN) which is used to augment the observations in order to update the agent’s policy and value function according to the
DrAC objective from Equation (5).
For each DrAC update of the agent, we split the trajectories in the replay buffer into meta-train and meta-test using a 9 to 1 ratio.
The CNN’s weights are updated using
MAML (Finn et al., 2017) where the objective function is maximizing the average return obtained by
DrAC (after an update using Algorithm 1 with K = 1 and the CNN as the transformation f ). N f )
= 1 , ∀ f ∈ F (cid:46) : Q ( f ) = 0 , ∀ f ∈ F 4: R ( f ) = FIFO ( W ) , ∀ f ∈ F
, K do 6: f k = argmax f ∈F (cid:104) Q ( f ) + c (cid:113) log( k ) N ( f ) (cid:105)
Update the policy and value function according to
1 : 8: θ ← arg max
J
9: φ ← arg max φ J DrAC function 10:
Compute the mean return obtained by the new policy r k .
Add to ﬁrst
Q ( f k ) ← 1 | R ( f k ) | (cid:80) r ∈ R ( f k ) r 13:
N ( f k ) ← N ( f k ) +14: end for
4: r 0 ← do 6:
13: end for
[Table]
E H YPERPARAMETERS
We use Kostrikov (2018)’s implementation of PPO (Schulman et al., 2017), on top of which all our methods are build.
The agent is parameterized by the ResNet architecture from (Espeholt et al., 2018) which was used to obtain the best results in Cobbe et al.
Following Cobbe et al.
(2019), we also share parameters between the policy an value networks.
To improve stability when training with DrAC, we only backpropagate gradients through π ( a | f ( s, ν )) and V ( f ( s, ν )) in equations (3) and (4), respectively.
Unless otherwise noted, we use the best hyperparameters found in Cobbe et al.
(2019) for the easy mode of Procgen ( i.e. same experimental setup as the one used here), namely:
For
DrAC, we did a grid search for the regularization coefﬁcient α r ∈ [0 . 0001 , 0 . 01 , 0 . 05 , 0 . 1 , 0 .
5 , 1 . 0] used in equation (5) and found that the best value is α r = 0 . 1 , which was used to produce all the results in this paper.
For UCB-DrAC, we did grid searches for the exploration coefﬁcient c ∈ [0 . 0 , 0 . 1 , 0 .
5 , 1 . 0 , 5 . 0] and the size of the sliding window used to compute the Q-values K ∈ [10 , 50 , 100] .
We found that the best values are c = 0 .
1 and K = 10 , which were used to obtain the results shown here.
For RL2-DrAC, we performed a hyperparameter search for the dimension of recurrent hidden state h ∈ [16 , 32 , 64] , for the learning rate l ∈ [3 e − 4 , 5 e − 4 , 7 e − 4] , and for the entropy coefﬁcient e ∈ [1 e − 4 , 1 e − 3 , 1 e − 2] and found h = 32 , l = 5 e − 4 , and e = 1 e − 3 to work best.
We used
Adam with (cid:15) = 1 e − 5 as the optimizer.
For Meta-DrAC, the convolutional network whose weights we meta-learn consists of a single convolutional layer with 3 input and 3 output channels, kernel size 3, stride 1 and 0 padding.
At each epoch, we perform one meta-update where we unroll the inner optimizer using the training set and compute the meta-test return on the validation set.
We did the same hyperparameter grid searches as for RL2-DrAC and found that the best values were l = 7 e − 4 and e = 1 e − 2 in this case.
The buffer of experience (collected before each PPO update) was split into 90% for meta-training and 10% for meta-testing.
For Rand-FM Lee et al.
we use the recommended hyperparameters in the authors’ released implementation, which were the best values for CoinRun (Cobbe et al., 2018), one of the Procgen games used for evaluation in (Lee et al., 2020). [Figure]
For IBAC-SNI Igl et al.
we also use the authors’ open sourced implementation.
We use the parameters corresponding to IBAC-SNI λ = .
We use weight regularization with l 2 = .
0001 , data augmentation turned on, and a value of β = . 0001 which turns on the variational information bottleneck, and selective noise injection turned on.
This corresponds to the best version of this approach, as found by the authors after evaluating it on CoinRun (Cobbe et al., 2018).
While IBACSNI outperforms the other methods on maze-like games such as heist, maze, and miner, it is still signiﬁcantly worse than our approach on the entire Procgen benchmark.
For both baselines, Rand-FM and IBAC-SNI, we use the same experimental setup for training and testing as the one used for our methods.
Hence, we train them for 25M frames on the easy mode of each Procgen game, using (the same) 200 levels for training and the rest of the levels for testing.
We use the Adam (Kingma & Ba, 2015) optimizer for all our experiments.
Note that by using
Adam, we do not need separate coefﬁcients for the policy and value regularization terms (since Adam rescales gradients for each loss component accordingly).
F A NALYSIS OF UCB’ S B EHAVIOR
In Figure 3, we show the behavior of UCB during training, along with train and test performance on the respective environments.
In the case of Ninja, UCB converges to always selecting the best augmentation only after 15M training steps.
This is because the augmentations have similar effects on the agent early in training, so it takes longer to ﬁnd the best augmentation from the given set.
In contrast, on Dodgeball, UCB ﬁnds the most effective augmentation much earlier in training because there is a signiﬁcant difference between the effect of various augmentations.
Early discovery of an effective augmentation leads to signiﬁcant improvements over PPO, for both train and test environments.
Another important factor is the exploration coefﬁcient used by UCB (see equation (6)) to balance the exploration and exploitation of different augmentations.
Figure 5 compares UCB’s behavior for different values of the exploration coefﬁcient.
Note that if the coefﬁcient is 0, UCB always selects the augmentation with the largest Q-value.
This can sometimes lead to UCB converging on a suboptimal augmentation due to the lack of exploration.
However, if the exploration term of equation (6) is too large relative to the differences in the Q-values among various augmentations, UCB might take too long to converge.
In our experiments, we found that an exploration coefﬁcient of 0 .
1 results in a good exploration-exploitation balance and works well across all Procgen games.
H B EST A UGMENTATIONS
[Table] [Table]
I B REAKDOWN OF P ROCGEN S CORES
[Table] [Table]
[Figure] [Figure]
[Figure] [Figure]
BossFight
[Figure]
Plunder
CaveFlyer
CoinRun
[Figure] [Figure]
[Figure] [Figure]
[Figure]
For our DMC experiments, we ran a grid search over the learning rate in [1 e − 4 , 3 e − 4 , 7 e − 4 , 1 e − 3] , the number of minibatches in [32 , 8 , 16 , 64] , the entropy coefﬁcient in [0 . 0 , 0 . 01 , 0 .
001 , 0 . 0001] , and the number of ppo epochs per update in [3 , 5 , 10 , 20] .
For Walker Walk and Finger Spin we useaction repeats and for the others we use 4.
We also use 3 stacked frames as observations.
For Finger
Spin, we found 10 ppo epochs, 0.0 entropy coefﬁcient, 16 minibatches, and 0.0001 learning rate to be the best.
For Cartpole Balance, we used the same except for 0.001 learning rate.
For Walker Walk, we used 5 ppo epochs, 0.001 entropy coefﬁcient, 32 minibatches, and 0.001 learning rate.
For Cheetah
Run, we used 3 ppo epochs, 0.0001 entropy coefﬁcient, 64 minibatches, and 0.001 learning rate.
We use γ = 0 .
99 , γ = 0 .
95 for the generalized advantage estimates, 2-48 steps, 1 process, value loss coefﬁcient 0.5, and linear rate decay over 1 million environment steps.
We also found crop to be the best augmentation from our set of eight transformations.
Any other hyperaparameters not mentioned here were set to the same values as the ones used for Procgen as described above.