Dichotomy of Control: Separating What You Can Control from What You Cannot
Mengjiao Yang, Dale Schuurmans, Pieter Abbeel, Ofir Nachum
Introduction
Offline reinforcement learning (RL) aims to extract an optimal policy solely from an existing dataset of previous interactions (Fujimoto et al., 2019; Wu et al., 2019; Kumar et al., 2020). As researchers begin to scale offline RL to large image, text, and video datasets (Agarwal et al., 2020; Fan et al., 2022; Baker et al., 2022; Reed et al., 2022; Reid et al., 2022), a family of methods known as return-conditioned supervised learning (RCSL), including Decision Transformer (DT) (Chen et al., 2021; Lee et al., 2022) and RL via Supervised Learning (RvS) (Emmons et al., 2021), have gained popularity due to their algorithmic simplicity and ease of scaling. At the heart of RCSL is the idea of conditioning a policy on a specific future outcome, often a return (Srivastava et al., 2019; Kumar et al., 2019; Chen et al., 2021) but also sometimes a goal state or generic future event (Codevilla et al., 2018; Ghosh et al., 2019; Lynch et al., 2020). RCSL trains a policy to imitate actions associated with a conditioning input via supervised learning. During inference (i.e., at evaluation), the policy is conditioned on a desirable high-return or future outcome, with the hope of inducing behavior that can achieve this desirable outcome.
Despite the empirical advantages that come with supervised training (Emmons et al., 2021; Kumar et al., 2021), RCSL can be highly suboptimal in stochastic environments (Brandfonbrener et al., 2022), where the future an RCSL policy conditions on (e.g., return) can be primarily determined by randomness in the environment rather than the data collecting policy itself. Figure 1 (left) illustrates an example, where conditioning an RCSL policy on the highest return observed in the dataset () leads to a policy () that relies on a stochastic transition of very low probability () to achieve the desired return of ; by comparison the choice of is much better in terms of average return, as it surely achieves . The crux of the issue is that the RCSL policy is inconsistent with its conditioning input. Conditioning the policy on a desired return (i.e., ) to act in the environment leads to a distribution of real returns (i.e., ) that is wildly different from the return value being conditioned on. This issue would not have occurred if the policy could also maximize the transition probability that led to the high-return state, but this is not possible as transition probabilities are a part of the environment and not subject to the policy’s control.
A number of works propose a generalization of RCSL, known as future-conditioned supervised learning methods. These techniques have been shown to be effective in imitation learning (Singh et al., 2020; Pertsch et al., 2020), offline Q-learning (Ajay et al., 2020), and online policy gradient (Venuto et al., 2021). It is common in future-conditioned supervised learning to apply a KL divergence regularizer on the latent variable – inspired by variational auto-encoders (VAE) (Kingma & Welling, 2013) and measured with respect to a learned prior conditioned only on past information – to limit the amount of future information captured in the latent variable. It is natural to ask whether this regularizer could remedy the insconsistency of RCSL. Unfortunately, as the KL regularizer makes no distinction between future information that is controllable versus that which is not, such an approach will still exhibit inconsistency, in the sense that the latent variable representation may contain information about the future that is due only to environment stochasticity.
It is clear that the major issue with both RCSL and naïve variational methods is that they make no distinction between stochasticity of the policy (controllable) and stochasticity of the environment (uncontrollable). An optimal policy should maximize over the controllable (actions) and take expectations over uncontrollable (e.g., transitions) as shown in Figure 1 (right). This implies that, under a variational approach, the latent variable representation that a policy conditions on should not incorporate any information that is solely due to randomness in the environment. In other words, while the latent representation can and should include information about future behavior (i.e., actions), it should not reveal any information about the rewards or transitions associated with this behavior.
To this end, we propose a future-conditioned supervised learning framework termed dichotomy of control (DoC), which, in Stoic terms (Shapiro, 2014), has “the serenity to accept the things it cannot change, courage to change the things it can, and wisdom to know the difference.” DoC separates mechanisms within a policy’s control (actions) from those beyond a policy’s control (environment stochasticity). To achieve this separation, we condition the policy on a latent variable representation of the future while minimizing the mutual information between the latent variable and future stochastic rewards and transitions in the environment. By only capturing the controllable factors in the latent variable, DoC can maximize over each action step without also attempting to maximize environment transitions as shown in Figure 1 (right). Theoretically, we show that DoC policies are consistent with their conditioning inputs, ensuring that conditioning on a high-return future will correctly induce high-return behavior. Empirically, we show that DoC can outperform both RCSL and naïve variational methods on highly stochastic environments.
Related Work
Since offline RL algorithms (Fujimoto et al., 2019; Wu et al., 2019; Kumar et al., 2020) can be sensitive to hyper-parameters and difficult to apply in practice (Emmons et al., 2021; Kumar et al., 2021), return-conditioned supervised learning (RCSL) has become a popular alternative, particularly when the environment is deterministic and near-expert demonstrations are available (Brandfonbrener et al., 2022). RCSL learns to predict behaviors (actions) by conditioning on desired returns (Schmidhuber, 2019; Kumar et al., 2019) using an MLP policy (Emmons et al., 2021) or a transformer-based policy that encapsulates history (Chen et al., 2021). Richer information other than returns, such as goals (Codevilla et al., 2018; Ghosh et al., 2019) or trajectory-level aggregates (Furuta et al., 2021), have also been used as inputs to a conditional policy in practice. Our work also conditions policies on richer trajectory-level information in the form of a latent variable representation of the future, with additional theoretical justifications of such conditioning in stochastic environments.
Despite the empirical success of RCSL achieved by DT and RvS, recent work has noted the failure modes in stochastic environments. Paster et al. (2020) and Štrupl et al. (2022) presented counter-examples where online RvS can diverge in stochastic environments. Brandfonbrener et al. (2022) identified near-determinism as a necessary condition for RCSL to achieve optimality guarantees similar to other offline RL algorithms but did not propose a solution for RCSL in stochastic settings. Paster et al. (2022) identified this same issue with stochastic transitions and proposed to cluster offline trajectories and condition the policy on the average cluster returns. However, the approach in Paster et al. (2022) has technical limitations (see Appendix C), does not account for reward stochasticity, and still conditions the policy on (expected) returns, which can lead to undesirable policy-averaging, i.e., a single policy covering two very different behaviors (clusters) that happen to have the same return. Villaflor et al. (2022) also identifies overly optimistic behavior of DT and proposes to use discrete -VAE to induce diverse future predictions a policy can condition on. This approach only differs the issue with stochastic environments to stochastic latent variables, i.e., the latent variables will still contain stochastic environment information that the policy cannot reliably reproduce.
Various works have explored learning a latent variable representation of the future (or past) transitions in offline data via maximum likelihood and use the latent variable to assist planning (Lynch et al., 2020), imitation learning (Kipf et al., 2019; Ajay et al., 2020; Hakhamaneshi et al., 2021), offline RL (Ajay et al., 2020; Zhou et al., 2020), or online RL (Fox et al., 2017; Krishnan et al., 2017; Goyal et al., 2019; Shankar & Gupta, 2020; Singh et al., 2020; Wang et al., 2021; Venuto et al., 2021). These works generally focus on the benefit of increased temporal abstraction afforded by using latent variables as higher-level actions in a hierarchical policy. Villaflor et al. (2022) has introduced latent variable models into RCSL, which is one of the essential tools that enables our method, but they did not incoporate the appropriate constraints which can allow RCSL to effectively combat environment stochasticity, as we will see in our work.
Preliminaries
We consider the problem of learning a decision-making agent to interact with a sequential, finite-horizon environment. At time , the agent observes an initial state determined by the environment. After observing at a timestep , the agent chooses an action . After the action is applied the environment yields an immediate scalar reward and, if , a next state . We use to denote a generic episode generated from interactions with the environment, and use to denote a generic sub-episode, with the understanding that refers to an empty sub-episode. The return associated with an episode is defined as .
We will use to denote the environment. We assume that is determined by a stochastic reward function , stochastic transition function , and unique initial state , so that and during interactions with the environment. Note that these definitions specify a history-dependent environment, as opposed to a less general Markovian environment.
In future- or return-conditioned supervised learning, one uses a fixed training data distribution of episodes (collected by unknown and potentially multiple agents) to learn a policy , where is trained to predict conditioned on the history , the observation , and an additional conditioning variable that may depend on both the past and future of the episode. For example, in return-conditioned supervised learning, policy training minimizes the following objective over :
To apply an RCSL-trained policy during inference — i.e., interacting online with the environment — one must first choose a specific .For simplicitly, we assume is chosen at timestep and held constant throughout an entire episode. As noted in Brandfonbrener et al. (2022), this protocol also encompasses instances like DT (Chen et al., 2021) in which at timestep is the (desired) return summed starting at . For example, one might set to be the maximal return observed in the dataset, in the hopes of inducing a behavior policy which achieves this high return. Using as a shorthand to denote the policy conditioned on a specific , we define the expected return of in as,
Ideally the expected return induced by is close to , i.e., , so that acting according to conditioned on a high return induces behavior which actually achieves a high return. However, RCSL training according to Equation 1 will generally yield policies that are highly inconsistent in stochastic environments, meaning that the achieved returns may be significantly different than (i.e., ). This has been highlighted in various previous works (Brandfonbrener et al., 2022; Paster et al., 2022; Štrupl et al., 2022; Eysenbach et al., 2022; Villaflor et al., 2022), and we provided our own example in Figure 1.
A number of future-conditioned supervised learning approaches propose to learn a stochastic latent variable embedding of the future, , while regularizing with a KL-divergence from a learnable prior conditioned only on the past (Ajay et al., 2020; Venuto et al., 2021; Lynch et al., 2020), thereby minimizing:
One could consider adopting such a future-conditioned objective in RCSL. However, since the KL regularizer makes no distinction between observations the agent can control (actions) from those it cannot (environment stochasticity), the choice of coefficient applied to the regularizer introduces a ‘lose-lose’ trade-off. Namely, as noted in Ajay et al. (2020), if the regularization coefficient is too large (), the policy will not learn diverse behavior (since the KL limits how much information of the future actions is contained in ); while if the coefficient is too small (), the policy’s learned behavior will be inconsistent (in the sense that will contain information of environment stochasticity that the policy cannot reliably reproduce). The discrete -VAE incoporated by Villaflor et al. (2022) with corresponds to this second failure mode.
Dichotomy of Control
In this section, we first propose the DoC objective for learning future-conditioned policies that are guaranteed to be consistent. We then present a practical framework for optimizing DoC’s constrained objective in practice and an inference scheme to enable better-than-dataset behavior via a learned value function and prior.
As elaborated in the prevous section, whether is the return or more generally a stochastic latent variable with distribution , existing RCSL methods fail to satisfy consistency because they insufficiently enforce the type of future information can contain. Our key observation is that should not include any information due to environment stochasticity, i.e., any information about a future that is not already known given the previous history up to that point . Accordingly, we modify the RCSL objective from Equation 1 to incorporate a conditional mutual information constraint between and each pair in the future:
The first part of the DoC objective conditions the policy on a latent variable representation of the future, similar to the first part of the future-conditioned VAE objective in Equation 3. However, unlike Equation 3, the DoC objective enforces a much more precise constraint on , given by the MI constraints in Equation 4.
2 Dichotomy of Control in Practice
To satisfy the mutual information constraints in Equation 4 we transform the MI to a contrastive learning objective. Specifically, for the constraint on and (and similarly on and ) one can derive,
where is some fixed sampling distribution of rewards. In practice, we set to be the marginal distribution of rewards in the dataset. Hence we express the first term of Equation 6 via an optimization over , i.e.,
As is standard in RCSL approaches, the policy learned by DoC requires an appropriate conditioning input to be chosen during inference. To choose a desirable associated with high return, we propose to (1) enumerate or sample a large number of potential values of , (2) estimate the expected return for each of these values of , (3) choose the with the highest associated expected return to feed into the policy. To enable such an inference-time procedure, we need to add two more components to the method formulation: First, a prior distribution from which we will sample a large number of values of ; second, a value function with which we will rank the potential values of . These components are learned by minimizing the following objective:
Note that we apply a stop-gradient to when learning so as to avoid regularizing with the prior. This is unlike the VAE approach, which by contrast advocates for regularizing via the prior. See Algorithm 1 for inference pseudocode (and Appendix D for training pseudocode).
Consistency Guarantees for Dichotomy of Control
A future-conditioned policy and value function are consistent for a specific conditioning input if the expected return of predicted by is equal to the true expected return of in the environment: .
To guarantee consistency of , we will make the following two assumptions:
Given these two assumptions, we can then establish the following consistency guarantee for DoC.
Suppose DoC yields with satisfying the MI constraints:
While the results above are focused on environments and policies that are non-Markovian, one can extend Theorem 4 to Markovian environments and policies. This result is somewhat surprising, as the assignments of to episodes induced by are necessarily history-dependent, and projecting the actions appearing in these clusters to a non-history-dependent policy would seemingly lose important information. However, a Markovian assumption on the rewards and transitions of the environment is sufficient to ensure that no ‘important’ information will be lost, at least in terms of the satisfying requirements for consistency in Definition 1. Alternative notions of consistency are not as generally applicable; see Appendix C.
With these two assumptions, we can then establish the analogue to Theorem 4, which relaxes the dependency on history for both the policy and the MI constraints:
Suppose DoC yields with satisfying the MI constraints:
Experiments
We conducted an empirical evaluation to ascertain the effectiveness of DoC. For this evaluation, we considered three settings: (1) a Bernoulli bandit problem with stochastic rewards, based on a canonical ‘worst-case scenario’ for RCSL (Brandfonbrener et al., 2022); (2) the FrozenLake domain from (Brockman et al., 2016), where the future VAE approach proves ineffective; and finally (3) a modified set of OpenAI Gym (Brockman et al., 2016) environments where we introduced environment stochasticity. In these studies, we found that DoC exhibits a significant advantage over RCSL/DT, and outperforms future VAE when the analogous to “one-step” RL is insufficient. For DT, we use the same implementation and hyperparameters as Chen et al. (2021). Both VAE and DoC are built upon the DT implementation and additionally learn a Gaussian latent variable over succeeding 20 future steps. See experiment details in Appendix E and additional results in Appendix F.
Consider a two-armed bandit as shown in Figure 2 (left). The two arms, , have stochastic rewards drawn from Bernoulli distributions of and , respectively. In the offline dataset, the arm with reward is pulled with probability . When is small, this corresponds to the better arm only being pulled occasionally. Under this setup, , which is highly suboptimal compared to always pulling the optimal arm with reward for .
We train tabular DoC and baselines on 1000 samples where the superior arm with is pulled with probability for . Figure 2 (right) shows that RCSL and percentage BC (filtered by ) always result in policies that are indifferent in the arms, whereas DoC is able to recover the Bayes-optimal performance (dotted line) for all values considered. Future VAE performs similarly to DoC for small values, but is sensitive to the KL regularization coefficient when is close to .
2 Evaluating Stochastic Transitions in FrozenLake
Next, we consider the FrozenLake environment with stochastic transitions where the agent taking an action has probability of moving in the intended direction, and probability of slipping to either of the two sides of the intended direction. We collect trajectories of length using a DQN policy trained in the original environment () which achieves an average return of , and vary during data collection and evaluation to test different levels of stochasticity. We also include uniform actions with probability to lower the performance of the offline data so that BC is highly suboptimal.
Figure 3 presents the visualization (left) and results (right) for this task. When the offline data is closer to being expert (), DT, future VAE, and DoC perform similarly with better performance in more deterministic environments. As the offline dataset becomes more suboptimal (), DoC starts to dominate across all levels of transition stochasticity. When the offline data is highly suboptimal (), DT and future VAE has little advantage over BC, whereas DoC continues to learn policies with reasonable performance.
3 Evaluating Stochastic Gym MuJoCo
We now consider a set of Gym MuJoCo environments including Reacher, Hopper, HalfCheetah, and Humanoid. We additionally consider AntMaze from D4RL (Fu et al., 2020). These environments are deterministic by default, which we modify by introducing time-correlated Gaussian noise to the actions before inputing the action into the physics simulator during data collection and evaluation for all but AntMaze environments. Specifically, the Gaussian noise we introduce to the actions has 0 mean and standard deviation of the form where is the step number and . For AntMaze where the dataset has already been collected in the deterministic environment by D4RL, we add gaussian noise with 0.1 standard deviation to the reward uniformly with probability 0.1 (both to the dataset and during evaluation).
Figure 4 shows the average performance (across 5 seeds) of DT, future VAE, and DoC on these stochastic environments. Both future VAE and DoC generally provide benefits over DT, where the benefit of DoC is more salient in harder environments such as HalfCheetah and Humanoid. We found future VAE to be sensitive to the hyperparameter, and simply using can result in the falure case as shown in Reacher-v2.
Conclusion
Despite the empirical promise of return- or future-conditioned supervised learning (RCSL) with large transformer architectures, environment stochasticity hampers the application of supervised learning to sequential decision making. To address this issue, we proposed to augment supervised learning with the dichotomy of control principle (DoC), guiding a supervised policy to only control the controllable (actions). Theoretically, DoC learns consistent policies, guaranteeing that they achieve the future or return they are conditioned on. Empirically, DoC outperforms RCSL in highly stochastic environments. While DoC still falls short in addressing other RL challenges such as ‘stitching’ (i.e., composing sub-optimal trajectories), we hope that dichotomy of control serves as a stepping stone in solving sequential decision making with large-scale supervised learning.
Thanks to George Tucker for reviewing draft versions of this manuscript. Thanks to Marc Bellemare for help with derivations. Thanks to David Brandfonbrener and Keiran Paster for discussions around stochastic environments. We gratefully acknowledges the support of a Canada CIFAR AI Chair, NSERC and Amii, and support from Berkeley BAIR industrial consortion.
References
Appendix A Proof of Theorem 4
The proof relies on the following lemma, showing that the MI constraints ensure that the observed rewards and dynamics conditioned on in the training data are equal to the rewards and dynamics of the environment.
Suppose yields satisfying the MI constraints:
We show the derivations relevant to reward, with those for next-state being analogous. We start with the definition of mutual information:
and so we immediately have the desired result.
We will further employ the following lemma, which takes us most of the way to proving Theorem 4:
Suppose DoC yields with satisfying the MI constraints:
Moreover, by Lemma 8 we may write the second and third probabilities as
A.1 Theorem Proof
Using Assumption 3, we can express as,
Appendix B Proof of Theorem 7
We begin by proving a result under stricter conditions, namely, when the MI constraints retain the conditioning on history.
Suppose DoC yields with satisfying the MI constraints:
Thus, for any we have
where the first equality is Bayes’ rule, the second equality is due to Equation 39, the third equality is due to Equation 41, and last equality is by definition of (Assumption 6).
Before continuing to the main proof, we present the following analogue to Lemma 8:
Suppose yields satisfying the MI constraints:
The proof is analogous to the proof of Lemma 8.
We can now tackle the proof of Theorem 7. To do so, we start by interpreting the episodes in the training data as coming from a modified Markovian environment . Specifically, we define as an environment with the same state space as but with an action space consisting of tuples , where is an action from the action space of , is a scalar, and is a state from the state space of . We define the reward and transition functions of to be deterministic, so that the reward and next state associated with is and , respectively. This way, we may interpret any episode in as an episode
in the modified environment . Denoting as the training data distribution when interpreted in this way, we note that the MI constraints of Lemma 10 hold, since rewards and transitions are deterministic. Thus, the policy defined as
we have, by definition of ,
In a similar vein, by definition of and Lemma 11 we have,
Appendix C Invalidity of Alternative Consistency Frameworks
Paster et al. (2022) propose a similar but distinct notion of consistency compared to ours (i.e., Definition 1), and claim that it can be achieved with stationary policies in Markovian environments. In this section, we show that this is, in fact, false, supporting the benefits of our framework. We begin by rephrasing Theorem 2.1 of Paster et al. (2022) using our own notation:
Suppose is Markovian and are given such that
A simple counter-example may be constructed by considering the Markovian environment displayed in Figure 5. The environment has three states. The first state gives a choice of two actions (), and each action deterministically transitions to the same second state. The second state again provides a choice of two actions (), and each of these again deterministically transitions to the same terminal state. Thus, episodes in this environment are uniquely determined by choice of . There are four unique episodes:
We now construct as a deterministic function, clustering these four trajectories into two distinct :
Suppose includes with equal probability. Since the environment is deterministic, the conditions of Theorem 2.1 in Paster et al. (2022) are trivially satisfied. Learning a policy with respect to yields
However, it is clear that interacting with in the environment will lead to with non-zero probability, while are never associated with in the data . Contradiction.
Appendix D Pseudocode for DoC training
Appendix E Experiment Details
We use the same hyperparameters as the publically available Decision Transformer (Chen et al., 2021) implementation. For VAE, we additionally learn a future and a prior both parametrized the same as the policy using transformers with context length 20. All models are trained on NVIDIA GPU P100.
E.2 Details of the offline datasets
We train a DQN (Mnih et al., 2013) policy for 100k steps in the original 4x4 FrozenLake Gym environment with stochasticity level . We then modify to simulate environments of different stochasticity levels, while collecting 100 trajectories of maximum length 100 at each level using the trained DQN agent with probability of selecting a random action as opposed to the action output by the DQN agent to emulate offline data with different quality.
We train SAC (Haarnoja et al., 2018) policies on the original set of Gym MuJoCo environments for 100M steps. To simulate stochasticity in these environments, we modify the original Gym MuJoCo environments by introducing noise to the actions before inputting the action to the physics simulator to compute rewards and next states. The noise has 0 mean and standard deviation of the form where is the step number and . We then collect 1000 trajectories of 1000 steps each for all environments except for Reacher (which has 50 steps in each trajectory) in the stochastic version of the environment using the SAC policy to acquire the offline dataset for training.
For the AntMaze task, we use the AntMaze dataset from D4RL (Fu et al., 2020), which contains 1000 trajectories of 1000 steps each. We add gaussian noise with standard deviation 0.1 to the rewards in the dataset uniformly with probability 0.1 to both the offline dataset and during environment evaluation to simulate stochastic rewards from the environment.