Trust-PCL: An Off-Policy Trust Region Method for Continuous Control
Ofir Nachum, Mohammad Norouzi, Kelvin Xu, Dale Schuurmans
Introduction
The goal of model-free reinforcement learning (RL) is to optimize an agent’s behavior policy through trial and error interaction with a black box environment. Value-based RL algorithms such as Q-learning (Watkins, 1989) and policy-based algorithms such as actor-critic (Konda & Tsitsiklis, 2000) have achieved well-known successes in environments with enumerable action spaces and predictable but possibly complex dynamics, e.g., as in Atari games (Mnih et al., 2013; Van Hasselt et al., 2016; Mnih et al., 2016). However, when applied to environments with more sophisticated action spaces and dynamics (e.g., continuous control and robotics), success has been far more limited.
In an attempt to improve the applicability of Q-learning to continuous control, Silver et al. (2014) and Lillicrap et al. (2015) developed an off-policy algorithm DDPG, leading to promising results on continuous control environments. That said, current off-policy methods including DDPG often improve data efficiency at the cost of optimization stability. The behaviour of DDPG is known to be highly dependent on hyperparameter selection and initialization (Metz et al., 2017); even when using optimal hyperparameters, individual training runs can display highly varying outcomes.
On the other hand, in an attempt to improve the stability and convergence speed of policy-based RL methods, Kakade (2002) developed a natural policy gradient algorithm based on Amari (1998), which subsequently led to the development of trust region policy optimization (TRPO) (Schulman et al., 2015). TRPO has shown strong empirical performance on difficult continuous control tasks often outperforming value-based methods like DDPG. However, a major drawback is that such methods are not able to exploit off-policy data and thus require a large amount of on-policy interaction with the environment, making them impractical for solving challenging real-world problems.
Efforts at combining the stability of trust region policy-based methods with the sample efficiency of value-based methods have focused on using off-policy data to better train a value estimate, which can be used as a control variate for variance reduction (Gu et al., 2017a; b).
In this paper, we investigate an alternative approach to improving the sample efficiency of trust region policy-based RL methods. We exploit the key fact that, under entropy regularization, the optimal policy and value function satisfy a set of pathwise consistency properties along any sampled path (Nachum et al., 2017), which allows both on and off-policy data to be incorporated in an actor-critic algorithm, PCL. The original PCL algorithm optimized an entropy regularized maximum reward objective and was evaluated on relatively simple tasks. Here we extend the ideas of PCL to achieve strong results on standard, challenging continuous control benchmarks. The main observation is that by alternatively augmenting the maximum reward objective with a relative entropy regularizer, the optimal policy and values still satisfy a certain set of pathwise consistencies along any sampled trajectory. The resulting objective is equivalent to maximizing expected reward subject to a penalty-based constraint on divergence from a reference (i.e., previous) policy.
We exploit this observation to propose a new off-policy trust region algorithm, Trust-PCL, that is able to exploit off-policy data to train policy and value estimates. Moreover, we present a simple method for determining the coefficient on the relative entropy regularizer to remain agnostic to reward scale, hence ameliorating the task of hyperparameter tuning. We find that the incorporation of a relative entropy regularizer is crucial for good and stable performance. We evaluate Trust-PCL against TRPO, and observe that Trust-PCL is able to solve difficult continuous control tasks, while improving the performance of TRPO both in terms of the final reward achieved as well as sample-efficiency.
Related Work
Trust Region Methods. Gradient descent is the predominant optimization method for neural networks. A gradient descent step is equivalent to solving a trust region constrained optimization,
Another approach to trust region optimization is given by proximal gradient methods (Parikh et al., 2014). The class of proximal gradient methods most similar to our work are those that replace the hard constraint in (2) with a penalty added to the objective. These techniques have recently become popular in RL (Wang et al., 2016; Heess et al., 2017; Schulman et al., 2017b), although in terms of final reward performance on continuous control benchmarks, TRPO is still considered to be the state-of-the-art.
Softmax Consistency. To comply with the information geometry over policy parameters, previous work has used the relative entropy (i.e., KL divergence) to regularize policy optimization; resulting in a softmax relationship between the optimal policy and state values (Peters et al., 2010; Azar et al., 2012; 2011; Fox et al., 2016; Rawlik et al., 2013) under single-step rollouts. Our work is unique in that we leverage consistencies over multi-step rollouts.
The existence of multi-step softmax consistencies has been noted by prior work—first by Nachum et al. (2017) in the presence of entropy regularization. The existence of the same consistencies with relative entropy has been noted by Schulman et al. (2017a). Our work presents multi-step consistency relations for a hybrid relative entropy plus entropy regularized expected reward objective, interpreting relative entropy regularization as a trust region constraint. This work is also distinct from prior work in that the coefficient of relative entropy can be automatically determined, which we have found to be especially crucial in cases where the reward distribution changes dramatically during training.
Most previous work on softmax consistency (e.g., Fox et al. (2016); Azar et al. (2012); Nachum et al. (2017)) have only been evaluated on relatively simple tasks, including grid-world and discrete algorithmic environments. Rawlik et al. (2013) conducted evaluations on simple variants of the CartPole and Pendulum continuous control tasks. More recently, Haarnoja et al. (2017) showed that soft Q-learning (a single-step special case of PCL) can succeed on more challenging environments, such as a variant of the Swimmer task we consider below. By contrast, this paper presents a successful application of the softmax consistency concept to difficult and standard continuous-control benchmarks, resulting in performance that is competitive with and in some cases beats the state-of-the-art.
Notation & Background
We model an agent’s behavior by a policy distribution over a set of actions (possibly discrete or continuous). At iteration , the agent encounters a state and performs an action sampled from . The environment then returns a scalar reward and transitions to the next state . When formulating expectations over actions, rewards, and state transitions we will often omit the sampling distributions, , , and , respectively.
Maximizing Expected Reward. The standard objective in RL is to maximize expected future discounted reward. We formulate this objective on a per-state basis recursively as
The overall, state-agnostic objective is the expected per-state objective when states are sampled from interactions with the environment:
Most policy-based algorithms, including REINFORCE (Williams & Peng, 1991) and actor-critic (Konda & Tsitsiklis, 2000), aim to optimize given a parameterized policy.
Path Consistency Learning (PCL). Inspired by Williams & Peng (1991), Nachum et al. (2017) augment the objective in (5) with a discounted entropy regularizer to derive an objective,
Note that the objective can then be re-expressed recursively as,
Nachum et al. (2017) show that the optimal policy for and mutually satisfy a softmax temporal consistency constraint along any sequence of states starting at and a corresponding sequence of actions :
This observation led to the development of the PCL algorithm, which attempts to minimize squared error between the LHS and RHS of (10) to simultaneously optimize parameterized and . Importantly, PCL is applicable to both on-policy and off-policy trajectories.
The prior policy is then replaced with the new policy , and the process is repeated.
Method
where the discounted relative entropy is recursively defined as
This objective attempts to maximize entropy regularized expected reward while maintaining natural proximity to the previous policy. Although previous work has separately proposed to use relative entropy and entropy regularization, we find that the two components serve different purposes, each of which is beneficial: entropy regularization helps improve exploration, while the relative entropy improves stability and allows for a faster learning rate. This combination is a key novelty.
Using the method of Lagrange multipliers, we cast the constrained optimization problem in (13) into maximization of the following objective,
Again, the environment-wide objective is the expected per-state objective when states are sampled from interactions with the environment,
A key technical observation is that the objective has a similar decomposition structure to , and one can cast as an entropy regularized expected reward objective with a set of transformed rewards, i.e.,
Let denote the optimal policy, defined as . As in PCL (Nachum et al., 2017), this optimal policy may be expressed as
where are the softmax state values defined recursively as
This is a single-step temporal consistency which may be extended to multiple steps by further expanding on the RHS using the same identity. Thus, in general we have the following softmax temporal consistency constraint along any sequence of states defined by a starting state and a sequence of actions :
2 Trust-PCL
We propose to train a parameterized policy and value estimate to satisfy the multi-step consistencies in (21). Thus, we define a consistency error for a sequence of states, actions, and rewards sampled from the environment as
We aim to minimize the squared consistency error on every sub-trajectory of length . That is, the loss for a given batch of episodes (or sub-episodes) is
We perform gradient descent on and to minimize this loss. In practice, we have found that it is beneficial to learn the parameter at least as fast as , and accordingly, given a mini-batch of episodes we perform a single gradient update on and possibly multiple gradient updates on (see Appendix for details).
In principle, the mini-batch may be taken from either on-policy or off-policy trajectories. In our implementation, we utilized a replay buffer prioritized by recency. As episodes (or sub-episodes) are sampled from the environment they are placed in a replay buffer and a priority is given to a trajectory equivalent to the current training step. Then, to sample a batch for training, episodes are sampled from the replay buffer proportional to exponentiated priority for some hyperparameter .
3 Automatic Tuning of The Lagrange Multiplier λ𝜆\lambda
The use of a relative entropy regularizer as a penalty rather than a constraint introduces several difficulties. The hyperparameter must necessarily adapt to the distribution of rewards. Thus, must be tuned not only to each environment but also during training on a single environment, since the observed reward distribution changes as the agent’s behavior policy improves. Using a constraint form of the regularizer is more desirable, and others have advocated its use in practice (Schulman et al., 2015) specifically to robustly allow larger updates during training.
To this end, we propose to redirect the hyperparameter tuning from to . Specifically, we present a method which, given a desired hard constraint on the relative entropy defined by , approximates the equivalent penalty coefficient . This is a key novelty of our work and is distinct from previous attempts at automatically tuning a regularizing coefficient, which iteratively increase and decrease the coefficient based on observed training behavior (Schulman et al., 2017b; Heess et al., 2017).
We restrict our analysis to the undiscounted setting with entropy regularizer . Additionally, we assume deterministic, finite-horizon environment dynamics. An additional assumption we make is that the expected KL-divergence over states is well-approximated by the KL-divergence starting from the unique initial state . Although in our experiments these restrictive assumptions are not met, we still found our method to perform well for adapting during training.
In this setting the optimal policy of (14) is proportional to exponentiated scaled reward. Specifically, for a full episode , we have
where and . The normalization factor of is
Experiments
We evaluate Trust-PCL against TRPO on a number of benchmark tasks. We choose TRPO as a baseline since it is a standard algorithm known to achieve state-of-the-art performance on the continuous control tasks we consider (see e.g., leaderboard results on the OpenAI Gym website (Brockman et al., 2016)). We find that Trust-PCL can match or improve upon TRPO’s performance in terms of both average reward and sample efficiency.
We chose a number of control tasks available from OpenAI Gym (Brockman et al., 2016). The first task, Acrobot, is a discrete-control task, while the remaining tasks (HalfCheetah, Swimmer, Hopper, Walker2d, and Ant) are well-known continuous-control tasks utilizing the MuJoCo environment (Todorov et al., 2012).
Trust-PCL is off-policy, so to evaluate its performance we alternate between collecting experience and training on batches of experience sampled from the replay buffer. Specifically, we alternate between collecting steps from the environment and performing a single gradient step based on a batch of size sub-episodes of length from the replay buffer, with a recency weight of on the sampling distribution of the replay buffer. To maintain stability we use and we modified the loss from squared loss to Huber loss on the consistency error. Since our policy is parameterized by a unimodal Gaussian, it is impossible for it to satisfy all path consistencies, and so we found this crucial for stability.
For each of the variants and for each environment, we performed a hyperparameter search to find the best hyperparameters. The plots presented here show the reward achieved during training on the best hyperparameters averaged over the best seeds of randomly seeded training runs. Note that this reward is based on greedy actions (rather than random sampling).
Experiments were performed using Tensorflow (Abadi et al., 2016). Although each training step of Trust-PCL (a simple gradient step) is considerably faster than TRPO, we found that this does not have an overall effect on the run time of our implementation, due to a combination of the fact that each environment step is used in multiple training steps of Trust-PCL and that a majority of the run time is spent interacting with the environment. A detailed description of our implementation and hyperparameter search is available in the Appendix.
2 Results
We present the reward over training of Trust-PCL and TRPO in Figure 1. We find that Trust-PCL can match or beat the performance of TRPO across all environments in terms of both final reward and sample efficiency. These results are especially significant on the harder tasks (Walker2d and Ant). We additionally present our results compared to other published results in Table 1. We find that even when comparing across different implementations, Trust-PCL can match or beat the state-of-the-art.
The most important hyperparameter in our method is , which determines the size of the trust region and thus has a critical role in the stability of the algorithm. To showcase this effect, we present the reward during training for several different values of in Figure 2. As increases, instability increases as well, eventually having an adverse effect on the agent’s ability to achieve optimal reward. Note that standard PCL (Nachum et al., 2017) corresponds to (that is, ). Therefore, standard PCL would fail in these environments, and the use of trust region is crucial.
The main advantage of Trust-PCL over existing trust region methods for continuous control is its ability to learn in an off-policy manner. The degree to which Trust-PCL is off-policy is determined by a combination of the hyparparameters , , and . To evaluate the importance of training off-policy, we evaluate Trust-PCL with a hyperparameter setting that is more on-policy. We set , , and . In this setting, we also use large batches of episodes of length (a total of environment steps per batch). Figure 3 shows the results of Trust-PCL with our original parameters and this new setting. We note a dramatic advantage in sample efficiency when using off-policy training. Although Trust-PCL (on-policy) can achieve state-of-the-art reward performance, it requires an exorbitant amount of experience. On the other hand, Trust-PCL (off-policy) can be competitive in terms of reward while providing a significant improvement in sample efficiency.
One last hyperparameter is , determining the degree of exploration. Anecdotally, we found to not be of high importance for the tasks we evaluated. Indeed many of our best results use . Including had a marginal effect, at best. The reason for this is likely due to the tasks themselves. Indeed, other works which focus on exploration in continuous control have found the need to propose exploration-advanageous variants of these standard benchmarks (Haarnoja et al., 2017; Houthooft et al., 2016).
Conclusion
We have presented Trust-PCL, an off-policy algorithm employing a relative-entropy penalty to impose a trust region on a maximum reward objective. We found that Trust-PCL can perform well on a set of standard control tasks, improving upon TRPO both in terms of average reward and sample efficiency. Our best results on Trust-PCL are able to maintain the stability and solution quality of TRPO while approaching the sample-efficiency of value-based methods (see e.g., Metz et al. (2017)). This gives hope that the goal of achieving both stability and sample-efficiency without trading-off one for the other is attainable in a single unifying RL algorithm.
Acknowledgment
We thank Matthew Johnson, Luke Metz, Shane Gu, and the Google Brain team for insightful comments and discussions.
References
Appendix A Implementation Benefits of Trust-PCL
We have already highlighted the ability of Trust-PCL to use off-policy data to stably train both a parameterized policy and value estimate, which sets it apart from previous methods. We have also noted the ease with which exploration can be incorporated through the entropy regularizer. We elaborate on several additional benefits of Trust-PCL.
Compared to TRPO, Trust-PCL is much easier to implement. Standard TRPO implementations perform second-order gradient calculations on the KL-divergence to construct a Fisher information matrix (more specifically a vector product with the inverse Fisher information matrix). This yields a vector direction for which a line search is subsequently employed to find the optimal step. Compare this to Trust-PCL which employs simple gradient descent. This makes implementation much more straightforward and easily realizable within standard deep learning frameworks.
Even if one replaces the constraint on the average KL-divergence of TRPO with a simple regularization penalty (as in proximal policy gradient methods (Schulman et al., 2017b; Wang et al., 2016)), optimizing the resulting objective requires computing the gradient of the KL-divergence. In Trust-PCL, there is no such necessity. The per-state KL-divergence need not have an analytically computable gradient. In fact, the KL-divergence need not have a closed form at all. The only requirement of Trust-PCL is that the log-density be analytically computable. This opens up the possible policy parameterizations to a much wider class of functions. While continuous control has traditionally used policies parameterized by unimodal Gaussians, with Trust-PCL the policy can be replaced with something much more expressive—for example, mixtures of Gaussians or auto-regressive policies as in Metz et al. (2017).
We have yet to fully explore these additional benefits in this work, but we hope that future investigations can exploit the flexibility and ease of implementation of Trust-PCL to further the progress of RL in continuous control environments.
Appendix B Experimental Setup
We describe in detail the experimental setup regarding implementation and hyperparameter search.
In Acrobot, episodes were cut-off at step . For the remaining environments, episodes were cut-off at step .
Acrobot, HalfCheetah, and Swimmer are all non-terminating environments. Thus, for these environments, each episode had equal length and each batch contained the same number of episodes. Hopper, Walker2d, and Ant are environments that can terminate the agent. Thus, for these environments, the batch size throughout training remained constant in terms of steps but not in terms of episodes.
There exists an additional common MuJoCo task called Humanoid. We found that neither our implementation of TRPO nor Trust-PCL could make more than negligible headway on this task, and so omit it from the results. We are aware that TRPO with the addition of GAE and enough fine-tuning can be made to achieve good results on Humanoid (Schulman et al., 2016). We decided to not pursue a GAE implementation to keep a fair comparison between variants. Trust-PCL can also be made to incorporate an analogue to GAE (by maintaining consistencies at varying time scales), but we leave this to future work.
B.2 Implementation Details
We use fully-connected feed-forward neural networks to represent both policy and value.
The policy is represented by a neural network with two hidden layers of dimension with activations. At time step , the network is given the observation . It produces a vector , which is combined with a learnable (but -agnostic) parameter to parametrize a unimodal Gaussian with mean and standard deviation . The next action is sampled randomly from this Gaussian.
The value network is represented by a neural network with two hidden layers of dimension with activations. At time step the network is given the observation and the component-wise squared observation . It produces a single scalar value.
At each training iteration, both the policy and value parameters are updated. The policy is trained by performing a trust region step according to the procedure described in Schulman et al. (2015).
B.2.2 Trust-PCL Learning
At each training iteration, both the policy and value parameters are updated. The specific updates are slightly different between Trust-PCL (on-policy) and Trust-PCL (off-policy).
For Trust-PCL (off-policy), both the policy and value parameters are updated in a single step using the Adam optimizer with learning rate . For this variant, we also utilize a target value network (lagged at the same rate as the target policy network) to replace the value estimate at the final state for each path. We do not mix between empirical and expected values.
B.3 Hyperparameter Search
We found the most crucial hyperparameters for effective learning in both TRPO and Trust-PCL to be (the constraint defining the size of the trust region) and (the rollout determining how to evaluate the empirical value of a state). For TRPO we performed a grid search over . For Trust-PCL we performed a grid search over . For Trust-PCL we also experimented with the value of , either keeping it at a constant 0 (thus, no exploration) or decaying it from to by a smoothed exponential rate of every 2,500 training iterations.
We fix the discount to for all environments.
Appendix C Pseudocode
A simplified pseudocode for Trust-PCL is presented in Algorithm 1.