Cross-Domain Imitation Learning via Optimal Transport

Arnaud Fickinger, Samuel Cohen, Stuart Russell, Brandon Amos

Introduction

Reinforcement learning (RL) methods have attained impressive results across a number of domains, e.g., Berner et al. (2019); Kober et al. (2013); Levine et al. (2016); Vinyals et al. (2019). However, the effectiveness of current RL method is heavily correlated to the quality of the training reward. Yet for many real-world tasks, designing dense and informative rewards require significant engineering effort. To alleviate this effort, imitation learning (IL) proposes to learn directly from expert demonstrations. Most current IL approaches can be applied solely to the simplest setting where the expert and the agent share the same embodiment and transition dynamics that live in the same state and action spaces. In particular, these approaches require expert demonstrations from the agent domain. Therefore, we might reconsider the utility of IL as it seems to only move the problem, from designing informative rewards to providing expert demonstrations, rather than solving it. However, if we relax the constraining setting of current IL methods, then natural imitation scenarios that genuinely alleviate engineering effort appear. Indeed, not requiring the same dynamics would enable agents to imitate humans and robots with different morphologies, hence widely enlarging the applicability of IL and alleviating the need for in-domain expert demonstrations.

This relaxed setting where the expert demonstrations comes from another domain has emerged as a budding area with more realistic assumptions (Gupta et al., 2017; Liu et al., 2019; Sermanet et al., 2018; Kim et al., 2020; Raychaudhuri et al., 2021) that we will refer to as Cross-Domain Imitation Learning. A common strategy of these works is to learn a mapping between the expert and agent domains. To do so, they require access to proxy tasks where both the expert and the agent act optimally in there respective domains. Under some structural assumptions, the learned map enables to transform a trajectory in the expert domain into the agent domain while preserving the optimality. Although these methods indeed relax the typical setting of IL, requiring proxy tasks heavily restrict the applicability of Cross-Domain IL. For example, it rules out imitating an expert never seen before as well as transferring to a new robot.

In this paper, we relax the assumptions of Cross-Domain IL and propose a benchmark and method that do not need access to proxy tasks. To do so, we depart from the point of view taken by previous work and formalize Cross-Domain IL as an optimal transport problem. We propose a method, that we call Gromov Wasserstein Imitation Learning (GWIL), that uses the Gromov-Wasserstein distance to solve the benchmark. We formally characterize the scenario where GWIL preserves optimality (theorem 1), revealing the possibilities and limitations. The construction of our proxy rewards to optimize optimal transport quantities using RL generalizes previous work that assumes uniform occupancy measures (Dadashi et al., 2020; Papagiannis & Li, 2020) and is of independent interest. Our experiments show that GWIL learns optimal behaviors with a single demonstration from another domain without any proxy tasks in non-trivial continuous control settings.

Related Work

Imitation learning. An early approach to IL is Behavioral Cloning (Pomerleau, 1988; 1991) which amounts to training a classifier or regressor via supervised learning to replicate the expert’s demonstration. Another key approach is Inverse Reinforcement Learning (Ng & Russell, 2000; Abbeel & Ng, 2004; Abbeel et al., 2010), which aims at learning a reward function under which the observed demonstration is optimal and can then be used to train a agent via RL. To bypass the need to learn the expert’s reward function, Ho & Ermon (2016) show that IRL is a dual of an occupancy measure matching problem and propose an adversarial objective whose optimization approximately recover the expert’s state-action occupancy measure, and a practical algorithm that uses a generative adversarial network (Goodfellow et al., 2014). While a number of recent work aims at improving this algorithm relative to the training instability caused by the minimax optimization, Primal Wasserstein Imitation Learning (PWIL) (Dadashi et al., 2020) and Sinkhorn Imitation Learning (SIL) (Papagiannis & Li, 2020) view IL as an optimal transport problem between occupancy measures to completely eliminate the minimax objective and outperforms adversarial methods in terms of sample efficiency. Heess et al. (2017); Peng et al. (2018); Zhu et al. (2018); Aytar et al. (2018) scale imitation learning to complex human-like locomotion and game behavior in non-trivial settings. Our work is an extension of Dadashi et al. (2020); Papagiannis & Li (2020) from the Wasserstein to the Gromov-Wasserstein setting. This takes us beyond limitation that the expert and imitator are in the same domain and into the cross-domain setting between agents that live in different spaces.

Transfer learning across domains and morphologies. Work transferring knowledge between different domains in RL typically learns a mapping between the state and action spaces. Ammar et al. (2015) use unsupervised manifold alignment to find a linear map between states that have similar local geometry but assume access to hand-crafted features. More recent work in transfer learning across viewpoint and embodiment mismatch learn a state mapping without handcrafted features but assume access to paired and time-aligned demonstration from both domains (Gupta et al., 2017; Liu et al., 2018; Sermanet et al., 2018). Furthermore, Kim et al. (2020); Raychaudhuri et al. (2021) propose methods to learn a state mapping from unpaired and unaligned tasks. All these methods require proxy tasks, i.e. a set of pairs of expert demonstrations from both domains, which limit the applicability of these methods to real-world settings. Stadie et al. (2017) have proposed to combine adversarial learning and domain confusion to learn a policy in the agent’s domain without proxy tasks but their method only works in the case of small viewpoint mismatch. Zakka et al. (2021) take a goal-driven perspective that seeks to imitate task progress rather than match fine-grained structural details to transfer between physical robots. In contrast, our method does not rely on learning an explicit cross-domain latent space between the agents, nor does it rely on proxy tasks. The Gromov-Wasserstein distance enables us to directly compare the different spaces without a shared space. The existing benchmark tasks we are aware of assume access to a set of demonstrations from both agents whereas the experiments in our paper only assume access to expert demonstrations. Finally, other domain adaptation and transfer learning settings use Gromov-Wasserstein variants, e.g. for transfer between word embedding spaces (Alvarez-Melis & Jaakkola, 2018) and image spaces (Vayer et al., 2020b).

Preliminaries

Gromov-Wasserstein distance. Let (X,dX,μX)(\mathcal{X},d_{\mathcal{X}},\mu_{\mathcal{X}}) and (Y,dY,μY)(\mathcal{Y},d_{\mathcal{Y}},\mu_{\mathcal{Y}}) be two metric measure spaces, where dX,dYd_{\mathcal{X}},d_{\mathcal{Y}} are distances, and μX,μY\mu_{\mathcal{X}},\mu_{\mathcal{Y}} are measures on their respective spacesWe use discrete spaces for readability but show empirical results in continuous spaces.. Optimal transport (Villani, 2009; Peyré et al., 2019) studies how to compare measures. We will use the Gromov-Wasserstein distance (Mémoli, 2011) between metric measure spaces, which has been theoretically generalized and further studied in Sturm (2012); Peyré et al. (2016); Vayer (2020) and is defined by

where U(μX,μY)\mathcal{U}(\mu_{\mathcal{X}},\mu_{\mathcal{Y}}) is the set of couplings between the atoms of the measures defined by

GW\mathcal{GW} compares the structure of two metric measure spaces by comparing the pairwise distances within each space to find the best isometry between the spaces. Figure 1 illustrates this distance in the case of the metric measure spaces (SE×AE,dE,ρπE)(S_{E}\times A_{E},d_{E},\rho_{\pi_{E}}) and (SA×AA,dA,ρπA)(S_{A}\times A_{A},d_{A},\rho_{\pi_{A}}).

Cross-Domain Imitation Learning via Optimal Transport

For a stationary policy π\pi acting on a metric MDP (S,A,R,P,γ,d)(S,A,R,P,\gamma,d), the occupancy measure is:

We compare policies from arbitrarily different MDPs in terms of their occupancy measures.

Given an expert policy πE\pi_{E} and an agent policy πA\pi_{A} acting, respectively, on

We define the Gromov-Wasserstein distance between πE\pi_{E} and πA\pi_{A} as the Gromov-Wasserstein distance between the metric measure spaces (SE×AE,dE,ρπE)(S_{E}\times A_{E},d_{E},\rho_{\pi_{E}}) and (SA×AA,dA,ρπA)(S_{A}\times A_{A},d_{A},\rho_{\pi_{A}}):

We now define an isometry between policies by comparing the distances between the state-action spaces and show that GW\mathcal{GW} defines a distance up to an isometry between the policies. Figure 2 illustrates examples of simple isometric policies.

Two policies πE\pi_{E} and πA\pi_{A} are isometric if there exists a bijection ϕ:supp⁡[ρπE]→supp⁡[ρπA]\phi:\operatorname{supp}[\rho_{\pi_{E}}]\rightarrow\operatorname{supp}[\rho_{\pi_{A}}] that satisfies for all (sE,aE),(sE′,aE′)∈supp⁡[ρπE]2(s_{E},a_{E}),({s_{E}}^{\prime},{a_{E}}^{\prime})\in\operatorname{supp}[\rho_{\pi_{E}}]^{2}:

In other words, ϕ\phi is an isometry between (supp⁡[ρπE],dE)(\operatorname{supp}[\rho_{\pi_{E}}],d_{E}) and (supp⁡[ρπA],dA)(\operatorname{supp}[\rho_{\pi_{A}}],d_{A}).

GW\mathcal{GW} defines a metric on the collection of all isometry classes of policies.

By definition 1, GW(πE,πA)=0\mathcal{GW}(\pi_{E},\pi_{A})=0 if and only if GW((SE,dE,ρπE),(SA,dA,ρπA))=0\mathcal{GW}((S_{E},d_{E},\rho_{\pi_{E}}),(S_{A},d_{A},\rho_{\pi_{A}}))=0. By Mémoli (2011, Theorem 5.1), this is true if and only if there is an isometry that maps supp⁡[ρϕE]\operatorname{supp}[\rho_{\phi_{E}}] to supp⁡[ρϕA]\operatorname{supp}[\rho_{\phi_{A}}]. By definition 2, this is true if and only if πA\pi_{A} and πE\pi_{E} are isometric. The symmetry and triangle inequality follow from Mémoli (2011, Theorem 5.1). ∎

Suppose that there exists four distances dES,dEA,dAS,dAAd_{E}^{S},d_{E}^{A},d_{A}^{S},d_{A}^{A} defined on SES_{E}, AEA_{E}, SAS_{A} and AEA_{E} respectively, and two isometries ϕ:(SE,dES)→(SA,dAS)\phi:(S_{E},d_{E}^{S})\rightarrow(S_{A},d_{A}^{S}) and ψ:(AE,dES)→(AS,dAS)\psi:(A_{E},d_{E}^{S})\rightarrow(A_{S},d_{A}^{S}) such that for all (sE,aE,sE′)∈SE×AE×SE(s_{E},a_{E},s_{E}^{\prime})\in S_{E}\times A_{E}\times S_{E} the three following conditions hold:

Consider an optimal policy πE∗\pi^{*}_{E} in MEM_{E}. Suppose that πGW\pi_{GW} minimizes GW(πE∗,πGW)\mathcal{GW}(\pi^{*}_{E},\pi_{GW}) with

Then πGW\pi_{GW} is isometric to an optimal policy in MAM_{A}.

We first show that ρA∗\rho^{*}_{A} is feasible in MAM_{A}, i.e. there exists a policy πA∗\pi^{*}_{A} acting in MAM_{A} with occupancy measure ρA∗\rho^{*}_{A} (a). Then we show that πA∗\pi^{*}_{A} is optimal in MAM_{A} (b) and is isometric to πE∗\pi^{*}_{E} (c). Finally we show that πGW\pi_{GW} is isometric to πA∗\pi^{*}_{A}, which concludes the proof (d).

(a) Consider sA∈SAs_{A}\in S_{A}. By definition of ρA∗\rho^{*}_{A},

Since ρπE∗\rho_{\pi^{*}_{E}} is feasible in MM, it follows from Puterman (2014, Theorem 6.9.1) that

By conditions 4 and 5 and by definition of ρA∗\rho^{*}_{A},

Therefore, by Puterman (2014, Theorem 6.9.1), ρA∗\rho^{*}_{A} is feasible in MAM_{A}, i.e. there exists a policy πA∗\pi^{*}_{A} acting in MAM_{A} with occupancy measure ρA∗\rho^{*}_{A}.

(b) By condition 5 and definition of ρA∗\rho^{*}_{A}, the expected return of πA∗\pi^{*}_{A} in MAM_{A} is then

Consider any policy πA\pi_{A} in M′M^{\prime}. By condition 5, the expected return of πA\pi_{A} is

Using the same arguments that we used to show that ρA∗\rho^{*}_{A} is feasible in M′M^{\prime}, we can show that

is feasible in MM. It follows by optimality of πE∗\pi^{*}_{E} in MM that

It follows that πA∗\pi^{*}_{A} is optimal in M′M^{\prime}.

is an isometry between (SE×AE,dE)(S_{E}\times A_{E},d_{E}) and (SA×AA,dA)(S_{A}\times A_{A},d_{A}), where dEd_{E} and dAd_{A} and given, resp., by

Therefore by definition of ρA∗\rho^{*}_{A}, πA∗\pi^{*}_{A} is isometric to πE∗\pi^{*}_{E}.

(d) Recall from the statement of the theorem that πGW\pi_{GW} is a minimizer of GW(πE∗,πGW)\mathcal{GW}(\pi^{*}_{E},\pi_{GW}). Since πA∗\pi^{*}_{A} is isometric to πE∗\pi^{*}_{E}, it follows from prop. 1 that GW(πE∗,πA∗)=0\mathcal{GW}(\pi^{*}_{E},\pi^{*}_{A})=0. Therefore GW(πE∗,πGW)\mathcal{GW}(\pi^{*}_{E},\pi_{GW}) must be 0. By prop. 1, it follows that there exists an isometry

Notice that χ∘ξ−1∣supp⁡[ρA∗]\chi\circ\xi^{-1}|_{\operatorname{supp}[\rho^{*}_{A}]} is an isometry from (supp⁡[ρA∗],dA)(\operatorname{supp}[\rho^{*}_{A}],d_{A}) to (supp⁡[ρπGW],dA)(\operatorname{supp}[\rho_{\pi_{GW}}],d_{A}). It follows that πGW\pi_{GW} is isometric to πA∗\pi^{*}_{A}, an optimal policy in MAM_{A}, which concludes the proof. ∎

Theorem 1 shows the possibilities and limitations of our method. It shows that our method can recover optimal policies even though arbitrary isometries are applied to the state and action spaces of the expert’s domain. Importantly, we don’t need to know the isometries, hence our method is applicable to a wide range of settings. We will show empirically that our method produces strong results in other settings where the environment are not isometric and don’t even have the same dimension. However, a limitation of our method is that it recovers optimal policy only up to isometries. We will see that in practice, running our method on different seeds enables to find an optimal policy in the agent’s domain.

2 Gromov-Wasserstein Imitation Learning

Minimizing GW\mathcal{GW} between an expert and agent requires derivatives through the transition dynamics, which we typically don’t have access to. We introduce a reward proxy suitable for training an agent’s policy that minimizes GW\mathcal{GW} via RL. Figure 1 illustrates the method. For readability, we combine expert state and action variables (sE,aE)(s_{E},a_{E}) into single variables zEz_{E}, and similarly for agent state-action pairs. Also, we define ZE=SE×AEZ_{E}=S_{E}\times A_{E} and ZA=SA×AAZ_{A}=S_{A}\times A_{A}.

where u⋆u^{\star} is the coupling minimizing objective 1.

The agent’s policy πA\pi_{A} trained with rGWr_{\mathcal{GW}} minimizes GW(πE,πA)\mathcal{GW}(\pi_{E},\pi_{A}).

where Θ\Theta is the set of is the set of couplings between the atoms of the uniform measures defined by

In this case the reward is given for every state-action pairs in the trajectory by:

where θ⋆\theta^{\star} is the coupling minimizing objective 6.

In practice we drop the factor TAT_{A} because it is the same for every state-action pairs in the trajectory.

The construction of our reward proxy is defined for any occupancy measure and extends to previous work optimizing optimal transport quantities via RL that assumes uniform occupancy measure in the form of a trajectory to bypass the need for derivatives through the transition dynamics (Dadashi et al., 2020; Papagiannis & Li, 2020).

Computing the pseudo-rewards. We compute the Gromov-Wasserstein distance using Peyré et al. (2016, Proposition 1) and its gradient using Peyré et al. (2016, Proposition 2). To compute the coupling minimizing 6, we use the conditional gradient method as discussed in Ferradans et al. (2013).

Optimizing the pseudo-rewards. The pseudo-rewards we obtain from GW\mathcal{GW} for the imitation agent enable us to turn the imitation learning problem into a reinforcement learning problem (Sutton & Barto, 2018) to find the optimal policy for the Markov decision process induced by the pseudo-rewards. We consider agents with continuous state-action spaces and thus do policy optimization with the soft actor-critic algorithm (Haarnoja et al., 2018). Algorithm 1 sums up GWIL in the case where a single expert trajectory is given to approximate the expert occupancy measure.

Experiments

We propose a benchmark set for cross-domain IL methods consisting of 3 tasks and aiming at answering the following questions:

Does GWIL recover optimal behaviors when the agent domain is a rigid transformation of the expert domain? Yes, we demonstrate this with the maze in sect. 5.1.

Can GWIL recover optimal behaviors when the agent has different state and action spaces than the expert? Yes, we show in sect. 5.2 for slightly different state-action spaces between the cartpole and pendulum, and in sect. 5.3 for significantly different spaces between a walker and cheetah.

To answer these three questions, we use simulated continuous control tasks implemented in Mujoco (Todorov et al., 2012) and the DeepMind control suite (Tassa et al., 2018). We include videos of learned policies on our project sitehttps://arnaudfickinger.github.io/gwil/. In all settings we use the Euclidean metric within the expert and agent spaces for dEd_{E} and dAd_{A}.

We evaluate the capacity of IL methods to transfer to rigid transformation of the expert domain by using the PointMass Maze environment from Hejna et al. (2020). The agent’s domain is obtained by applying a reflection to the expert’s maze. This task satisfies the condition of theorem 1 with ϕ\phi being the reflection through the central horizontal plan and ψ\psi being the reflection through the xx-axis in the action space. Therefore by theorem 1, the agent’s optimal policy should be isometric to the policy trained using GWIL. By looking at the geometry of the maze, it is clear that every policy in the isometry class of an optimal policy is optimal. Therefore we expect GWIL to recover an optimal policy in the agent’s domain. Figure 3 shows that GWIL indeed recovers an optimal policy.

2 Agent and the expert have slightly different state and action spaces

We evaluate here the capacity of IL methods to transfer to transformation that does not have to be rigid but description map should still be apparent by looking at the domains. A good example of such transformation is the one between the pendulum and cartpole. The pendulum is our expert’s domain while cartpole constitutes our agent’s domain. The expert is trained on the swingup task. Even though the transformation is not rigid, GWIL is able to recover the optimal behavior in the agent’s domain as shown in fig. 4. Notice that pendulum and cartpole do not have the same state-action space dimension: The pendulum has 3 dimensions while the cartpole has 5 dimensions. Therefore GWIL can indeed be applied to transfer between problems with different dimension.

3 Agent and the expert have significantly different state and action spaces

We evaluate here the capacity of IL methods to transfer to non-trivial transformation between domains. A good example of such transformation is two arbitrarily different morphologies from the DeepMind Control Suite such as the cheetah and walker. The cheetah constitutes our expert’s domain while the walker constitutes our agent’s domain. The expert is trained on the run task.

Although the mapping between these two domains is not trivial, minimizing the Gromov-Wasserstein solely enables the walker to interestingly learn to move backward and forward by imitating a cheetah. Since the isometry class of the optimal policy – moving forward– of the cheetah and walker contains a suboptimal element –moving backward–, we expect GWIL to recover one of these two trajectories. Indeed, depending on the seed used, GWIL produces a cheetah-imitating walker moving forward or a cheetah-imitating walker moving backward, as shown in fig. 5.

Conclusion

Our work demonstrates that optimal transport distances are a useful foundational tool for cross-domain imitation across incomparable spaces. Future directions include exploring:

Scaling to more complex environments and agents towards the goal of transferring the structure of many high-dimensional demonstrations of complex tasks into an agent.

The use of GW\mathcal{GW} to help agents explore in extremely sparse-reward environments when we have expert demonstrations available from other agents.

How GW\mathcal{GW} compares to other optimal transport distances that work apply between two metric MDPs, such as Alvarez-Melis et al. (2019), that have more flexibility over how the spaces are connected and what invariances the coupling has.

Metrics aware of the MDP’s temporal structure such as Zhou & Torre (2009); Vayer et al. (2020a); Cohen et al. (2021) that build on dynamic time warping (Müller, 2007). The Gromov-Wasserstein ignores the temporal information and ordering present within the trajectories.

References

Appendix A Optimization of the proxy reward

In this section we show that the proxy reward introduced in equation 7 constitutes a learning signal that is easy to optimize using standards RL algorithms. Figure 6 shows proxy reward curves across 5 different seeds for the 3 environments. We observe that in each environment the SAC learner converges quickly and consistently to the asymptotic episodic return. Thus there is reason to think that the proxy reward introduced in equation 7 will be similarly easy to optimize in other cross-domain imitation settings.

Appendix B Transfer to sparse-reward environments

In this section we show that GWIL can be used to facilitate learning in sparse-reward environments when the learner has only access to one expert demonstration from another domain. We compare GWIL to a baseline learner having access to a single demonstration from the same domain and minimizing the Wasserstein distance, as done in Dadashi et al. (2020). In these experiments, both agents are given a sparse reward signal in addition to their respective optimal transport proxy reward. We perform experiments in two sparse-reward environment. In the first environment, the agent controls a point mass in a maze and obtain a non-zero reward only if it reaches the end of the maze. In the second environment, which is a sparse version of cartpole, the agent controls a cartpole and obtains a non-zero reward only if he can maintain the cartpole up for 10 consecutive time steps. Note that a SAC agent fails to learn any meaningful behavior in both environments. Figure 7 shows that GWIL is competitive with the baseline learner in the sparse maze environment even though GWIL has only access to a demonstration from another domain, while the baseline learner has access to a demonstration from the same domain. Thus there is reason to think that GWIL efficiently and reliably extracts useful information from the expert domain and hence should work well in other cross-domain imitation settings.

Appendix C Scalability of GWIL

In this section we show that our implementation of GWIL offers good performance in terms of wall-clock time. Note that the bottleneck of our method is in the computation of the optimal coupling which only depends on the number of time steps in the trajectories, and not on the dimension of the expert and the agent. Hence our method naturally scales with the dimension of the problems. Furthermore, while we have not used any entropy regularizer in our experiments, entropy regularized methods have been introduced to enable Gromov-Wasserstein to scale to demanding machine learning tasks and can be easily incorporated into our code to further improve the scalability. Figure 8 compares the time taken by GWIL in the maze with the time taken by the baseline learner introduced in the previous section. It shows that imitating with Gromov-Wasserstein requires the same order of time than imitating with Wasserstein. Figure 9 compares the wall-clock time taken by a walker imitating a cheetah using GWIL to reach a walking speed (i.e., a horizontal velocity of 1) and the wall-clock time taken by a SAC walker trained to run. It shows that a GWIL walker imitating a cheetah reaches a walking speed faster than a SAC agent trained to run. Even though the SAC agent is optimizing for standing in addition to running, it was not obvious that GWIL could compete with SAC in terms of wall-clock time. These results gives hope that GWIL has the potential to scale to more complex problems (possibly with an additional entropy regularizer) and be a useful way to learn by analogy.