MOPO: Model-based Offline Policy Optimization

Tianhe Yu, Garrett Thomas, Lantao Yu, Stefano Ermon, James Zou, Sergey Levine, Chelsea Finn, Tengyu Ma

Introduction

Recent advances in machine learning using deep neural networks have shown significant successes in scaling to large realistic datasets, such as ImageNet in computer vision, SQuAD in NLP, and RoboNet in robot learning. Reinforcement learning (RL) methods, in contrast, struggle to scale to many real-world applications, e.g., autonomous driving and healthcare , because they rely on costly online trial-and-error. However, pre-recorded datasets in domains like these can be large and diverse. Hence, designing RL algorithms that can learn from those diverse, static datasets would both enable more practical RL training in the real world and lead to more effective generalization.

While off-policy RL algorithms can in principle utilize previously collected datasets, they perform poorly without online data collection. These failures are generally caused by large extrapolation error when the Q-function is evaluated on out-of-distribution actions , which can lead to unstable learning and divergence. Offline RL methods propose to mitigate bootstrapped error by constraining the learned policy to the behavior policy induced by the dataset . While these methods achieve reasonable performances in some settings, their learning is limited to behaviors within the data manifold. Specifically, these methods estimate error with respect to out-of-distribution actions, but only consider states that lie within the offline dataset and do not consider those that are out-of-distribution. We argue that it is important for an offline RL algorithm to be equipped with the ability to leave the data support to learn a better policy for two reasons: (1) the provided batch dataset is usually sub-optimal in terms of both the states and actions covered by the dataset, and (2) the target task can be different from the tasks performed in the batch data for various reasons, e.g., because data is not available or hard to collect for the target task. Hence, the central question that this work is trying to answer is: can we develop an offline RL algorithm that generalizes beyond the state and action support of the offline data?

To approach this question, we first hypothesize that model-based RL methods make a natural choice for enabling generalization, for a number of reasons. First, model-based RL algorithms effectively receive more supervision, since the model is trained on every transition, even in sparse-reward settings. Second, they are trained with supervised learning, which provides more stable and less noisy gradients than bootstrapping. Lastly, uncertainty estimation techniques, such as bootstrap ensembles, are well developed for supervised learning methods and are known to perform poorly for value-based RL methods . All of these attributes have the potential to improve or control generalization. As a proof-of-concept experiment, we evaluate two state-of-the-art off-policy model-based and model-free algorithms, MBPO and SAC , in Figure 1. Although neither method is designed for the batch setting, we find that the model-based method and its variant without ensembles show surprisingly large gains. This finding corroborates our hypothesis, suggesting that model-based methods are particularly well-suited for the batch setting, motivating their use in this paper.

Despite these promising preliminary results, we expect significant headroom for improvement. In particular, because offline model-based algorithms cannot improve the dynamics model using additional experience, we expect that such algorithms require careful use of the model in regions outside of the data support. Quantifying the risk imposed by imperfect dynamics and appropriately trading off that risk with the return is a key ingredient towards building a strong offline model-based RL algorithm. To do so, we modify MBPO to incorporate a reward penalty based on an estimate of the model error. Crucially, this estimate is model-dependent, and does not necessarily penalize all out-of-distribution states and actions equally, but rather prescribes penalties based on the estimated magnitude of model error. Further, this estimation is done both on states and actions, allowing generalization to both, in contrast to model-free approaches that only reason about uncertainty with respect to actions.

The primary contribution of this work is an offline model-based RL algorithm that optimizes a policy in an uncertainty-penalized MDP, where the reward function is penalized by an estimate of the model’s error. Under this new MDP, we theoretically show that we maximize a lower bound of the return in the true MDP, and find the optimal trade-off between the return and the risk. Based on our analysis, we develop a practical method that estimates model error using the predicted variance of a learned model, uses this uncertainty estimate as a reward penalty, and trains a policy using MBPO in this uncertainty-penalized MDP. We empirically compare this approach, model-based offline policy optimization (MOPO), to both MBPO and existing state-of-the-art model-free offline RL algorithms. Our results suggest that MOPO substantially outperforms these prior methods on the offline RL benchmark D4RL as well as on offline RL problems where the agent must generalize to out-of-distribution states in order to succeed.

Related Work

Reinforcement learning algorithms are well-known for their ability to acquire behaviors through online trial-and-error in the environment . However, such online data collection can incur high sample complexity , limit the power of generalization to unseen random initialization , and pose risks in safety-critical settings . These requirements often make real-world applications of RL less feasible. To overcome some of these challenges, we study the batch offline RL setting . While many off-policy RL algorithms can in principle be applied to a batch offline setting, they perform poorly in practice .

Model-free Offline RL. Many model-free batch RL methods are designed with two main ingredients: (1) constraining the learned policy to be closer to the behavioral policy either explicitly or implicitly , and (2) applying uncertainty quantification techniques, such as ensembles, to stabilize Q-functions . In contrast, our model-based method does not rely on constraining the policy to the behavioral distribution, allowing the policy to potentially benefit from taking actions outside of it. Furthermore, we utilize uncertainty quantification to quantify the risk of leaving the behavioral distribution and trade it off with the gains of exploring diverse states.

Model-based Online RL. Our approach builds upon the wealth of prior work on model-based online RL methods that model the dynamics by Gaussian processes , local linear models , neural network function approximators , and neural video prediction models . Our work is orthogonal to the choice of model. While prior approaches have used these models to select actions using planning , we choose to build upon Dyna-style approaches that optimize for a policy , specifically MBPO . See for an empirical evaluation of several model-based RL algorithms. Uncertainty quantification, a key ingredient to our approach, is critical to good performance in model-based RL both theoretically and empirically , and in optimal control . Unlike these works, we develop and leverage proper uncertainty estimates that particularly suit the offline setting.

Concurrent work by Kidambi et al. also develops an offline model-based RL algorithm, MOReL. Unlike MOReL, which constructs terminating states based on a hard threshold on uncertainty, MOPO uses a soft reward penalty to incorporate uncertainty. In principle, a potential benefit of a soft penalty is that the policy is allowed to take a few risky actions and then return to the confident area near the behavioral distribution without being terminated. Moreover, while Kidambi et al. compares to model-free approaches, we make the further observation that even a vanilla model-based RL method outperforms model-free ones in the offline setting, opening interesting questions for future investigation. Finally, we evaluate our approach on both standard benchmarks and domains that require out-of-distribution generalization, achieving positive results in both.

Preliminaries

In the offline RL problem, the algorithm only has access to a static dataset Denv={(s,a,r,s′)}{\mathcal{D}}_{\textup{env}}=\{(s,a,r,s^{\prime})\} collected by one or a mixture of behavior policies πB\pi^{\textup{B}}, and cannot interact further with the environment. We refer to the distribution from which Denv{\mathcal{D}}_{\textup{env}} was sampled as the behavioral distribution.

We now summarize model-based policy optimization (MBPO) , which we build on in this work. MBPO learns a model of the transition distribution T^θ(s′∣s,a)\widehat{T}_{\theta}(s^{\prime}|s,a) parametrized by θ\theta, via supervised learning on the behavorial data Denv{\mathcal{D}_{\text{env}}}. MBPO also learns a model of the reward function in the same manner. During training, MBPO performs kk-step rollouts using T^θ(s′∣s,a)\widehat{T}_{\theta}(s^{\prime}|s,a) starting from state s∈Denvs\in{\mathcal{D}_{\text{env}}}, adds the generated data to a separate replay buffer Dmodel{\mathcal{D}_{\text{model}}}, and finally updates the policy π(a∣s)\pi(a|s) using data sampled from Denv∪Dmodel{\mathcal{D}_{\text{env}}}\cup{\mathcal{D}_{\text{model}}}. When applied in an online setting, MBPO iteratively collects samples from the environment and uses them to further improve both the model and the policy. In our experiments in Table 1, Table 5.2 and Table 1, we observe that MBPO performs surprisingly well on the offline RL problem compared to model-free methods. In the next section, we derive MOPO, which builds upon MBPO to further improve performance.

MOPO: Model-Based Offline Policy Optimization

Unlike model-free methods, our goal is to design an offline model-based reinforcement learning algorithm that can take actions that are not strictly within the support of the behavioral distribution. Using a model gives us the potential to do so. However, models will become increasingly inaccurate further from the behavioral distribution, and vanilla model-based policy optimization algorithms may exploit these regions where the model is inaccurate. This concern is especially important in the offline setting, where mistakes in the dynamics will not be corrected with additional data collection.

For the algorithm to perform reliably, it’s crucial to balance the return and risk: 1. the potential gain in performance by escaping the behavioral distribution and finding a better policy, and 2. the risk of overfitting to the errors of the dynamics at regions far away from the behavioral distribution. To achieve the optimal balance, we first bound the return from below by the return of a constructed model MDP penalized by the uncertainty of the dynamics (Section 4.1). Then we maximize the conservative estimation of the return by an off-the-shelf reinforcement learning algorithm, which gives MOPO, a generic model-based off-policy algorithm (Section 4.2). We discuss important practical implementation details in Section 4.3.

Our key idea is to build a lower bound for the expected return of a policy π\pi under the true dynamics and then maximize the lower bound over π\pi. A natural estimator for the true return ηM(π)\eta_{M}(\pi) is ηM^(π)\eta_{\widehat{M}}(\pi), the return under the estimated dynamics. The error of this estimator depends on, potentially in a complex fashion, the error of M^\widehat{M}, which may compound over time. In this subsection, we characterize how the error of M^\widehat{M} influences the uncertainty of the total return. We begin by stating a lemma (adapted from ) that gives a precise relationship between the performance of a policy under dynamics TT and dynamics T^\widehat{T}. (All proofs are given in Appendix B.)

Here and throughout the paper, we view TT as the real dynamics and T^\widehat{T} as the learned dynamics. We observe that the quantity GM^π(s,a)G^{\pi}_{\widehat{M}}(s,a) plays a key role linking the estimation error of the dynamics and the estimation error of the return. By definition, we have that GM^π(s,a)G^{\pi}_{\widehat{M}}(s,a) measures the difference between MM and M^\widehat{M} under the test function VπV^{\pi} — indeed, if M=M^M=\widehat{M}, then GM^π(s,a)=0G^{\pi}_{\widehat{M}}(s,a)=0. By equation (1), it governs the differences between the performances of π\pi in the two MDPs. If we could estimate GM^π(s,a)G^{\pi}_{\widehat{M}}(s,a) or bound it from above, then we could use the RHS of (1) as an upper bound for the estimation error of ηM(π)\eta_{M}(\pi). Moreover, equation (2) suggests that a policy that obtains high reward in the estimated MDP while also minimizing GM^πG^{\pi}_{\widehat{M}} will obtain high reward in the real MDP.

where dFd_{\mathcal{F}} is the integral probability metric (IPM) defined by F\mathcal{F}. IPMs are quite general and contain several other distance measures as special cases . Depending on what we are willing to assume about VMπV^{\pi}_{M}, there are multiple options to bound GM^πG^{\pi}_{\widehat{M}} by some notion of error of T^\widehat{T}, discussed in greater detail in Appendix A:

(i) If F={f:∥f∥∞≤1}\mathcal{F}=\{f:\|f\|_{\infty}\leq 1\}, then dFd_{\mathcal{F}} is the total variation distance. Thus, if we assume that the reward function is bounded such that ∀(s,a), ∣r(s,a)∣≤rmax⁡\forall(s,a),~{}|r(s,a)|\leq r_{\max}, we have ∥Vπ∥∞≤∑t=0∞γtrmax⁡=rmax⁡1−γ\|V^{\pi}\|_{\infty}\leq\sum_{t=0}^{\infty}\gamma^{t}r_{\max}=\frac{r_{\max}}{1-\gamma}, and hence

(ii) If F\mathcal{F} is the set of 1-Lipschitz function w.r.t. to some distance metric, then dFd_{\mathcal{F}} is the 1-Wasserstein distance w.r.t. the same metric. Thus, if we assume that VMπV^{\pi}_{M} is LvL_{v}-Lipschitz with respect to a norm ∥⋅∥\|\cdot\|, it follows that

Note that when T^\widehat{T} and TT are both deterministic, then W1(T^(s,a),T(s,a))=∥T^(s,a)−T(s,a)∥W_{1}(\widehat{T}(s,a),T(s,a))=\|\widehat{T}(s,a)-T(s,a)\| (here T(s,a)T(s,a) denotes the deterministic output of the model TT).

Approach (ii) has the advantage that it incorporates the geometry of the state space, but at the cost of an additional assumption which is generally impossible to verify in our setting. The assumption in (i), on the other hand, is extremely mild and typically holds in practice. Therefore we will prefer (i) unless we have some prior knowledge about the MDP. We summarize the assumptions and the inequalities in the options above as follows.

Assume a scalar cc and a function class F\mathcal{F} such that VMπ∈cFV^{\pi}_{M}\in c\mathcal{F} for all π\pi.

As a direct corollary of Assumption 4.2 and equation (3), we have

Concretely, option (i) above corresponds to c=rmax⁡/(1−γ)c=r_{\max}/(1-\gamma) and F={f:∥f∥∞≤1}\mathcal{F}=\{f:\|f\|_{\infty}\leq 1\}, and option (ii) corresponds to c=Lvc=L_{v} and \mathcal{F}=\{f:\text{fis 1-Lipschitz}\}. We will analyze our framework under the assumption that we have access to an oracle uncertainty quantification module that provides an upper bound on the error of the model. In our implementation, we will estimate the error of the dynamics by heuristics (see sections 4.3 and D).

2 Policy optimization on uncertainty-penalized MDPs

Motivated by (7), we optimize the policy on the uncertainty-penalized MDP M~\widetilde{M} in Algorithm 1.

Theoretical Guarantees for MOPO. We will theoretical analyze the algorithm by establishing the optimality of the learned policy π^\hat{\pi} among a family of policies. Let π⋆\pi^{\star} be the optimal policy on MM and πB\pi^{\textup{B}} be the policy that generates the batch data. Define ϵu(π)\epsilon_{u}(\pi) as

Note that ϵu\epsilon_{u} depends on T^\widehat{T}, but we omit this dependence in the notation for simplicity. We observe that ϵu(π)\epsilon_{u}(\pi) characterizes how erroneous the model is along trajectories induced by π\pi. For example, consider the extreme case when π=πB\pi=\pi^{\textup{B}}. Because T^\widehat{T} is learned on the data generated from πB\pi^{\textup{B}}, we expect T^\widehat{T} to be relatively accurate for those (s,a)∼ρT^πB(s,a)\sim\rho^{\pi^{\textup{B}}}_{\widehat{T}}, and thus u(s,a)u(s,a) tends to be small. Thus, we expect ϵu(πB)\epsilon_{u}(\pi^{\textup{B}}) to be quite small. On the other end of the spectrum, when π\pi often visits states out of the batch data distribution in the real MDP, namely ρTπ\rho^{\pi}_{T} is different from ρTπB\rho^{\pi^{\textup{B}}}_{T}, we expect that ρT^π\rho^{\pi}_{\widehat{T}} is even more different from the batch data and therefore the error estimates u(s,a)u(s,a) for those (s,a)∼ρT^π(s,a)\sim\rho^{\pi}_{\widehat{T}} tend to be large. As a consequence, we have that ϵu(π)\epsilon_{u}(\pi) will be large.

For δ≥δmin⁡:=min⁡πϵu(π)\delta\geq\delta_{\min}:=\min_{\pi}\epsilon_{u}(\pi), let πδ\pi^{\delta} be the best policy among those incurring model error at most δ\delta:

The main theorem provides a performance guarantee on the policy π^\hat{\pi} produced by MOPO.

Under Assumption 4.2 and 4.3, the learned policy π^\hat{\pi} in MOPO (Algorithm 1) satisfies

In particular, for all δ≥δmin⁡\delta\geq\delta_{\min},

Interpretation: One consequence of (10) is that ηM(π^)≥ηM(πB)−2λϵu(πB)\eta_{M}(\hat{\pi})\geq\eta_{M}(\pi^{\textup{B}})-2\lambda\epsilon_{u}(\pi^{\textup{B}}). This suggests that π^\hat{\pi} should perform at least as well as the behavior policy πB\pi^{\textup{B}}, because, as argued before, ϵu(πB)\epsilon_{u}(\pi^{\textup{B}}) is expected to be small.

Equation (11) tells us that the learned policy π^\hat{\pi} can be as good as any policy π\pi with ϵu(π)≤δ\epsilon_{u}(\pi)\leq\delta, or in other words, any policy that visits states with sufficiently small uncertainty as measured by u(s,a)u(s,a). A special case of note is when δ=ϵu(π⋆)\delta=\epsilon_{u}(\pi^{\star}), we have ηM(π^)≥ηM(π⋆)−2λϵu(π⋆)\eta_{M}(\hat{\pi})\geq\eta_{M}(\pi^{\star})-2\lambda\epsilon_{u}(\pi^{\star}), which suggests that the suboptimality gap between the learned policy π^\hat{\pi} and the optimal policy π⋆\pi^{\star} depends on the error ϵu(π⋆)\epsilon_{u}(\pi^{\star}). The closer ρT^π⋆\rho^{\pi^{\star}}_{\widehat{T}} is to the batch data, the more likely the uncertainty u(s,a)u(s,a) will be smaller on those points (s,a)∼ρT^π⋆(s,a)\sim\rho^{\pi^{\star}}_{\widehat{T}}. On the other hand, the smaller the uncertainty error of the dynamics is, the smaller ϵu(π⋆)\epsilon_{u}(\pi^{\star}) is. In the extreme case when u(s,a)=0u(s,a)=0 (perfect dynamics and uncertainty quantification), we recover the optimal policy π⋆\pi^{\star}.

Second, by varying the choice of δ\delta to maximize the RHS of Equation (11), we trade off the risk and the return. As δ\delta increases, the return ηM(πδ)\eta_{M}(\pi^{\delta}) increases also, since πδ\pi^{\delta} can be selected from a larger set of policies. However, the risk factor 2λδ2\lambda\delta increases also. The optimal choice of δ\delta is achieved when the risk balances the gain from exploring policies far from the behavioral distribution. The exact optimal choice of δ\delta may depend on the particular problem. We note δ\delta is only used in the analysis, and our algorithm automatically achieves the optimal balance because Equation (11) holds for any δ\delta.

3 Practical implementation

Now we describe a practical implementation of MOPO motivated by the analysis above. The method is summarized in Algorithm 2 in Appendix C, and largely follows MBPO with a few key exceptions.

Following MBPO, we model the dynamics using a neural network that outputs a Gaussian distribution over the next state and rewardIf the reward function is known, we do not have to estimate the reward. The theory in Sections 4.1 and 4.2 applies to the case where the reward function is known. To extend the theory to an unknown reward function, we can consider the reward as being concatenated onto the state, so that the admissible error estimator bounds the error on (s′,r)(s^{\prime},r), rather than just s′s^{\prime}.: T^θ,ϕ(st+1,r∣st,at)=N(μθ(st,at),Σϕ(st,at))\widehat{T}_{\theta,\phi}(s_{t+1},r|s_{t},a_{t})=\mathcal{N}(\mu_{\theta}(s_{t},a_{t}),\Sigma_{\phi}(s_{t},a_{t})). We learn an ensemble of NN dynamics models {T^θ,ϕi=N(μθi,Σϕi)}i=1N\{\widehat{T}^{i}_{\theta,\phi}=\mathcal{N}(\mu^{i}_{\theta},\Sigma^{i}_{\phi})\}_{i=1}^{N}, with each model trained independently via maximum likelihood.

We treat the penalty coefficient λ\lambda as a user-chosen hyperparameter. Since we do not have a true admissible error estimator, the value of λ\lambda prescribed by the theory may not be an optimal choice in practice; it should be larger if our heuristic u(s,a)u(s,a) underestimates the true error and smaller if uu substantially overestimates the true error.

Experiments

In our experiments, we aim to study the follow questions: (1) How does MOPO perform on standard offline RL benchmarks in comparison to prior state-of-the-art approaches? (2) Can MOPO solve tasks that require generalization to out-of-distribution behaviors? (3) How does each component in MOPO affect performance?

Question (2) is particularly relevant for scenarios in which we have logged interactions with the environment but want to use those data to optimize a policy for a different reward function. To study (2) and challenge methods further, we construct two additional continuous control tasks that demand out-of-distribution generalization, as described in Section 5.2. To answer question (3), we conduct a complete ablation study to analyze the effect of each module in MOPO in Appendix D. For more details on the experimental set-up and hyperparameters, see Appendix G. For more details on the experimental set-up and hyperparameters, see Appendix G. The code is available onlineCode is released at https://github.com/tianheyu927/mopo..

We compare against several baselines, including the current state-of-the-art model-free offline RL algorithms. Bootstrapping error accumulation reduction (BEAR) aims to constrain the policy’s actions to lie in the support of the behavioral distribution . This is implemented as a constraint on the average MMD between π(⋅ ∣ s)\pi(\cdot\,|\,s) and a generative model that approximates πB(⋅ ∣ s)\pi^{\textup{B}}(\cdot\,|\,s). Behavior-regularized actor critic (BRAC) is a family of algorithms that operate by penalizing the value function by some measure of discrepancy (KL divergence or MMD) between π(⋅ ∣ s)\pi(\cdot\,|\,s) and πB(⋅ ∣ s)\pi^{\textup{B}}(\cdot\,|\,s) . BRAC-v uses this penalty both when updating the critic and when updating the actor, while BRAC-p uses this penalty only when updating the actor and does not explicitly penalize the critic.

To answer question (1), we evaluate our method on a large subset of datasets in the D4RL benchmark based on the MuJoCo simulator , including three environments (halfcheetah, hopper, and walker2d) and four dataset types (random, medium, mixed, medium-expert), yielding a total of 12 problem settings. We also perform empirical evaluations on non-MuJoCo environments in Appendix F. The datasets in this benchmark have been generated as follows: random: roll out a randomly initialized policy for 1M steps. medium: partially train a policy using SAC, then roll it out for 1M steps. mixed: train a policy using SAC until a certain (environment-specific) performance threshold is reached, and take the replay buffer as the batch. medium-expert: combine 1M samples of rollouts from a fully-trained policy with another 1M samples of rollouts from a partially trained policy or a random policy.

Results are given in Table 1. MOPO is the strongest by a significant margin on all the mixed datasets and most of the medium-expert datasets, while also achieving strong performance on all of the random datasets. MOPO performs less well on the medium datasets. We hypothesize that the lack of action diversity in the medium datasets make it more difficult to learn a model that generalizes well. Fortunately, this setting is one in which model-free methods can perform well, suggesting that model-based and model-free approaches are able to perform well in complementary settings.

2 Evaluation on tasks requiring out-of-distribution generalization

To answer question (2), we construct two environments halfcheetah-jump and ant-angle where the agent must solve a task that is different from the purpose of the behavioral policy. The trajectories of the batch data in the these datasets are from policies trained for the original dynamics and reward functions HalfCheetah and Ant in OpenAI Gym which incentivize the cheetach and ant to move forward as fast as possible. Note that for HalfCheetah, we set the maximum velocity to be 33. Concretely, we train SAC for 1M steps and use the entire training replay buffer as the trajectories for the batch data. Then, we assign these trajectories with new rewards that incentivize the cheetach to jump and the ant to run towards the top right corner with a 30 degree angle. Thus, to achieve good performance for the new reward functions, the policy need to leave the observational distribution, as visualized in Figure 2. We include the exact forms of the new reward functions in Appendix G. In these environments, learning the correct behaviors requires leaving the support of the data distribution; optimizing solely within the data manifold will lead to sub-optimal policies.

In Table 2, we show that MOPO significantly outperforms the state-of-the-art model-free approaches. In particular, model-free offline RL cannot outperform the best trajectory in the batch dataset, whereas MOPO exceeds the batch max by a significant margin. This validates that MOPO is able to generalize to out-of-distribution behaviors while existing model-free methods are unable to solve those challenges. Note that vanilla MBPO performs much better than SAC in the two environments, consolidating our claim that vanilla model-based methods can attain better results than model-free methods in the offline setting, especially where generalization to out-of-distribution is needed. The visualization in Figure 2 suggests indeed the policy learned MOPO can effectively solve the tasks by reaching to states unseen in the batch data. Furthermore, we test the limit of the generalization abilities of MOPO in these environments and the results are included in Appendix E.

Conclusion

In this paper, we studied model-based offline RL algorithms. We started with the observation that, in the offline setting, existing model-based methods significantly outperform vanilla model-free methods, suggesting that model-based methods are more resilient to the overestimation and overfitting issues that plague off-policy model-free RL algorithms. This phenomenon implies that model-based RL has the ability to generalize to states outside of the data support and such generalization is conducive for offline RL. However, online and offline algorithms must act differently when handling out-of-distribution states. Model error on out-of-distribution states that often drives exploration and corrective feedback in the online setting can be detrimental when interaction is not allowed. Using theoretical principles, we develop an algorithm, model-based offline policy optimization (MOPO), which maximizes the policy on a MDP that penalizes states with high model uncertainty. MOPO trades off the risk of making mistakes and the benefit of diverse exploration from escaping the behavioral distribution. In our experiments, MOPO outperforms state-of-the-art offline RL methods in both standard benchmarks and out-of-distribution generalization environments.

Our work opens up a number of questions and directions for future work. First, an interesting avenue for future research to incorporate the policy regularization ideas of BEAR and BRAC into the reward penalty framework to improve the performance of MOPO on narrow data distributions (such as the “medium” datasets in D4RL). Second, it’s an interesting theoretical question to understand why model-based methods appear to be much better suited to the batch setting than model-free methods. Multiple potential factors include a greater supervision from the states (instead of only the reward), more stable and less noisy supervised gradient updates, or ease of uncertainty estimation. Our work suggests that uncertainty estimation plays an important role, particularly in settings that demand generalization. However, uncertainty estimation does not explain the entire difference nor does it explain why model-free methods cannot also enjoy the benefits of uncertainty estimation. For those domains where learning a model may be very difficult due to complex dynamics, developing better model-free offline RL methods may be desirable or imperative. Hence, it is crucial to conduct future research on investigating how to bring model-free offline RL methods up to the level of the performance of model-based methods, which would require further understanding where the generalization benefits come from.

Broader Impact

MOPO achieves significant strides in offline reinforcement learning, a problem setting that is particularly scalable to real-world settings. Offline reinforcement learning has a number of potential application domains, including autonomous driving, healthcare, robotics, and is notably amenable to safety-critical settings where online data collection is costly. For example, in autonomous driving, online interaction with the environment runs the risk of crashing and hurting people; offline RL methods can significantly reduce that risk by learning from a pre-recorded driving dataset collected by a safe behavioral policy. Moreover, our work opens up the possibility of learning policies offline for new tasks for which we do not already have expert data.

However, there are still risks associated with applying learned policies to high-risk domains. We have shown the benefits of explicitly accounting for error, but without reliable out-of-distribution uncertainty estimation techniques, there is a possibility that the policy will behave unpredictably when given a scenario it has not encountered. There is also the challenge of reward design: although the reward function will typically be under the engineer’s control, it can be difficult to specify a reward function that elicits the desired behavior and is aligned with human objectives. Additionally, parametric models are known to be susceptible to adversarial attacks, and bad actors can potentially exploit this vulnerability. Advances in uncertainty quantification, human-computer interaction, and robustness will improve our ability to apply learning-based methods in safety-critical domains.

Supposing we succeed at producing safe and reliable policies, there is still possibility of negative societal impact. An increased ability to automate decision-making processes may reduce companies’ demand for employees in certain industries (e.g. manufacturing and logistics), thereby affecting job availability. However, historically, advances in technology have also created new jobs that did not previously exist (e.g. software engineering), and it is unclear if the net impact on jobs will be positive or negative.

Despite the aforementioned risks and challenges, we believe that offline RL is a promising setting with enormous potential for automating and improving sequential decision-making in highly impactful domains. Currently, much additional work is needed to make offline RL sufficiently robust to be applied in safety-critical settings. We encourage the research community to pursue further study in uncertainty estimation, particularly considering the complications that arise in sequential decision problems.

Acknowledgments and Disclosure of Funding

We thank Michael Janner for help with MBPO and Aviral Kumar for setting up BEAR and D4RL. TY is partially supported by Intel Corporation. CF is a CIFAR Fellow in the Learning in Machines and Brains program. TM and GT are also partially supported by Lam Research, Google Faculty Award, SDSI, and SAIL.

References

Appendix A Reminders about integral probability metrics

Let (X,Σ)(\mathcal{X},\Sigma) be a measurable space. The integral probability metric associated with a class F\mathcal{F} of (measurable) real-valued functions on X\mathcal{X} is defined as

where PP and QQ are probability measures on X\mathcal{X}. We note the following special cases:

If F={f:∥f∥∞≤1}\mathcal{F}=\{f:\|f\|_{\infty}\leq 1\}, then dFd_{\mathcal{F}} is the total variation distance

If F\mathcal{F} is the set of 1-Lipschitz function w.r.t. to some cost function (metric) cc on X\mathcal{X}, then dFd_{\mathcal{F}} is the 1-Wasserstein distance w.r.t. the same metric:

where Γ(P,Q)\Gamma(P,Q) denotes the set of all couplings of PP and QQ, i.e. joint distributions on X2\mathcal{X}^{2} which have marginals PP and QQ.

If F={f:∥f∥H≤1}\mathcal{F}=\{f:\|f\|_{\mathcal{H}}\leq 1\} where H\mathcal{H} is a reproducing kernel Hilbert space with kernel kk, then dFd_{\mathcal{F}} is the maximum mean discrepancy:

where X,X′∼PX,X^{\prime}\sim P and Y,Y′∼QY,Y^{\prime}\sim Q.

In the context of Section 4.1, we have (at least) the following instantiations of Assumption 4.2:

Assume the reward is bounded by rmax⁡r_{\max}. Then (since ∥VMπ∥∞≤rmax⁡1−γ\|V^{\pi}_{M}\|_{\infty}\leq\frac{r_{\max}}{1-\gamma})

This corresponds to c=rmax⁡1−γc=\frac{r_{\max}}{1-\gamma} and F={f:∥f∥∞≤1}\mathcal{F}=\{f:\|f\|_{\infty}\leq 1\}.

Assume VMπV^{\pi}_{M} is LvL_{v}-Lipschitz. Then

This corresponds to c=Lvc=L_{v} and \mathcal{F}=\{f:\text{fisis1-Lipschitz}\}.

Assume ∥VMπ∥H≤ν\|V^{\pi}_{M}\|_{\mathcal{H}}\leq\nu. Then

This corresponds to c=νc=\nu and F={f:∥f∥H≤1}\mathcal{F}=\{f:\|f\|_{\mathcal{H}}\leq 1\}.

Appendix B Proofs

We provide a proof for Lemma 4.1 for completeness. The proof is essentially the same as that for [44, Lemma 4.3].

Let WjW_{j} be the expected return when executing π\pi on T^\widehat{T} for the first jj steps, then switching to TT for the remainder. That is,

Note that W0=ηM(π)W_{0}=\eta_{M}(\pi) and W∞=ηM^(π)W_{\infty}=\eta_{\widehat{M}}(\pi), so

where RjR_{j} is the expected return of the first jj time steps, which are taken with respect to T^\widehat{T}. Then

We first note that a two-sided bound follows from Lemma 4.1:

Appendix C MOPO Practical Algorithm Outline

We outline the practical MOPO algorithm in Algorithm 2.

Appendix D Ablation Study

To answer question (3), we conduct a thorough ablation study on MOPO. The main goal of the ablation study is to understand how the choice of reward penalty affects performance. We denote no ens. as a method without model ensembles, ens. pen. as a method that uses model ensemble disagreement as the reward penalty, no pen. as a method without reward penalty, and true pen. as a method using the true model prediction error ∥T^(s,a)−T(s,a)∥\|\widehat{T}(s,a)-T(s,a)\| as the reward penalty. Note that we include true pen. to indicate the upper bound of our approach. Also, note that no ens. measures disagreement among the ensemble: precisely, if the models’ mean predictions are denoted μ1,…,μN\mu_{1},\dots,\mu_{N}, we compute the average μˉ=1/N∑i=1Nμi\bar{\mu}=1/N\sum_{i=1}^{N}\mu_{i} and then take max⁡i∥μi−μˉ∥\max_{i}\|\mu_{i}-\bar{\mu}\| as the ensemble penalty.

The results of our study are shown in Table 3. For different reward penalty types, reward penalties based on learned variance perform comparably to those based on ensemble disagreement in D4RL environments while outperforming those based on ensemble disagreement in out-of-distribution domains. Both reward penalties achieve significantly better performances than no reward penalty, indicating that it is imperative to consider model uncertainty in batch model-based RL. Methods that uses oracle uncertainty obtain slightly better performance than most of our methods. Note that MOPO even attains the best results on halfcheetah-jump. Such results suggest that our uncertainty quantification on states is empirically successful, since there is only a small gap. We believe future work on improving uncertainty estimation may be able to bridge this gap further. Note that we do not report the results of methods with oracle uncertainty on walker2d-mixed and ant-angle as we are not able to get the true model error from the simulator based on the pre-recorded dataset.

In general, we find that performance differences are much larger for halfcheetah-jump and ant-angle than the D4RL halfcheetah-mixed and walker2d-mixed datasets, likely because halfcheetah-jump and ant-angle requires greater generalization and hence places more demands on the accuracy of the model and uncertainty estimate.

Finally, we perform another ablation study on the choice of the reward penalty. We consider the umean(s,a)=1N∑i=1N∥Σϕi(s,a)∥Fu^{\text{mean}}(s,a)=\frac{1}{N}\sum_{i=1}^{N}\|\Sigma^{i}_{\phi}(s,a)\|_{\text{F}}, the average standard deviation of the learned models in the ensemble, as the reward penalty instead of the max standard deviation as used in MOPO. We denote the variant of MOPO with the average learned standard deviation as MOPO, avg. var.. We compare MOPO to MOPO, avg. var. in the halfcheetah-jump domain. MOPO achieves 4140.6±\pm88 average return while MOPO, avg. var. achieves 4166.3±\pm228.8 where the results are averaged over 3 random seeds. The two methods did similarly, suggesting that using either mean variance or max variance would be a reasonable choice for penalizing uncertainty.

Appendix E Empirical results on generalization capabilities

We conduct experiments in ant-angle to show the limit of MOPO’s generalization capabilties. As shown in Table 4, we show that MOPO generalizes to Ant running at a 45∘45^{\circ} angle (achieving almost buffer max score), beyond the 30∘30^{\circ} shown in the paper, while failing to generalize to a 6060 and 90∘90^{\circ} degree angle. This suggests that if the new task requires to explore states that are completely out of the data support, i.e. the buffer max and buffer mean both fairly bad, MOPO is unable to generalize.

Appendix F Experiments on HIV domains

Beyond continous control tasks in MuJoCo, we test MOPO on an HIV treatment simulator slightly modified from the one in the whynot package. The task simulates the sequential decision making in HIV treatment, which involves determining the amounts of two anti-HIV drugs to be administered to the patient in order to maximize the immune response and minimize the amount of virus. The agent observes both of those quantities as well as the (log) number of infected and uninfected T cells and macrophages.

We evaluated MOPO with the data generated from the first 200k steps of training an online SAC agent on this environment. We show results in Table 5, where MOPO outperforms BEAR and achieves almost the buffer max score.

Appendix G Experiment Details

For halfcheetah-jump, the reward function that we use to train the behavioral policy is r(s,a)=max⁡{vx,3}−0.1∗∥a∥22r(s,a)=\max\{v_{x},3\}-0.1*\|a\|_{2}^{2} where vxv_{x} denotes the velocity along the x-axis. After collecting the offline dataset, we relabel the reward function to r(s,a)=max⁡{vx,3}−0.1∗∥a∥22+15∗(z−init z)r(s,a)=\max\{v_{x},3\}-0.1*\|a\|_{2}^{2}+15*(z-\text{init z}) where zz denotes the z-position of the half-cheetah and init z denotes the initial z-position.

For ant-angle, the reward function that we use to train the behavioral policy is r(s,a)=vx−control costr(s,a)=v_{x}-\text{control cost}. After collecting the offline dataset, we relabel the reward function to r(s,a)=vx⋅cos⁡π6+vy⋅sin⁡π6−control costr(s,a)=v_{x}\cdot\cos\frac{\pi}{6}+v_{y}\cdot\sin\frac{\pi}{6}-\text{control cost} where vxv_{x}, vyv_{y} denote the velocity along the x,yx,y-axis respectively.

For both out-of-distribution environments, instead of sampling actions from the learned policy during the model rollout (line 10 in Algorithm 2), we sample random actions from Unif\text{Unif}, which achieves better performance empirically. One potential reason is that using random actions during model rollouts leads to better exploration of the OOD states.

G.2 Hyperparameters

Here we list the hyperparameters used in the experiments.

For the D4RL datasets, the rollout length hh and penalty coefficient λ\lambda are given in Table 6. We search over (h,λ)∈{1,5}2(h,\lambda)\in\{1,5\}^{2} and report the best final performance, averaged over 3 seeds. The only exceptions are halfcheetah-random and walker2d-medium-expert, where other penalty coefficients were found to work better.

For the out-of-generalization tasks, we use rollout length 55 for halfcheetah-jump and 2525 for ant-angle, and penalty coefficient 11 for halfcheetah-jump and 22 for ant-angle.

Across all domains, we train an ensemble of 77 models and pick the best 55 models based on their prediction error on a hold-out set of 10001000 transitions in the offline dataset. Each of the model in the ensemble is parametrized as a 4-layer feedforward neural network with 200200 hidden units and after the last hidden layer, the model outputs the mean and variance using a two-head architecture. Spectral normalization is applied to all layers except the head that outputs the model variance.

For the SAC updates, we sample a batch of 256256 transitions, 5%5\% of them from Denv{\mathcal{D}_{\text{env}}} and the rest of them from Dmodel{\mathcal{D}_{\text{model}}}. We also perform ablation studies on the percentage of the real data in a batch for MOPO. For simplicity, we use MBPO, which essentially MOPO without reward penalty, for this ablation study. We tried to train MBPO with data all sampled from Dmodel{\mathcal{D}_{\text{model}}} and no data from Denv{\mathcal{D}_{\text{env}}} and compare the performance to MBPO with 5%5\% of data from Denv{\mathcal{D}_{\text{env}}} on all 12 settings in the D4RL benchmark. We find that the performances of both methods are not significantly distinct: no-real-data MBPO outperforms 5%5\%-real-data MBPO on 6 out of 12 tasks and lies within one SD of 5%5\%-real-data MBPO on 9 out of 12 tasks.