G ENERALIZED D ECISION T RANSFORMER FOR O FFLINE H INDSIGHT I NFORMATION M ATCHING
A BSTRACT
How to extract as much learning signal from each trajectory data has been a key problem in reinforcement learning (RL), where sample inefﬁciency has posed serious challenges for practical applications.
Recent works have shown that using expressive policy function approximators and conditioning on future trajectory information – such as future states in hindsight experience replay (HER) or returnsto-go in Decision Transformer (DT) – enables efﬁcient learning of multi-task policies, where at times online RL is fully replaced by ofﬂine behavioral cloning (BC), e.g. sequence modeling.
We demonstrate that all these approaches are doing hindsight information matching (HIM) – training policies that can output the rest of trajectory that matches some statistics of future state information. We present
Generalized Decision Transformer (GDT) for solving any HIM problem, and show how different choices for the feature function and the anti-causal aggregator not only recover DT as a special case, but also lead to novel Categorical DT (CDT) and Bi-directional DT (BDT) for matching different statistics of the future. For evaluating CDT and BDT, we deﬁne ofﬂine multi-task state-marginal matching (SMM) and imitation learning (IL) as two generic HIM problems, propose a
Wasserstein distance loss as a metric for both, and empirically study them on MuJoCo continuous control benchmarks.
Categorical DT, which simply replaces anti-causal summation with anti-causal binning in DT, enables arguably the ﬁrst effective ofﬂine multi-task SMM algorithm that generalizes well to unseen (and even synthetic) multi-modal reward or state-feature distributions.
Bi-directional DT, which uses an anti-causal second transformer as the aggregator, can learn to model any statistics of the future and outperforms DT variants in ofﬂine multi-task IL, i.e. one-shot IL. Our generalized formulations from HIM and GDT greatly expand the role of powerful sequence modeling architectures in modern RL.
I NTRODUCTION
Reinforcement learning (RL) suffers from the problem of sample inefﬁciency, and a central question is how to extract as much learning signals, or constraint equations (Pong et al., 2018;
Tu & Recht, 2019; Dean et al., 2020), from each trajectory data as possible.
As dynamics transitions and Bellman equation provide a rich source of supervisory objectives and constraints, many algorithms combined model-free with model-based, and policy-based with value-based in order to achieve maximal sample efﬁciency, while approximately preserving stable, unbiased policy learning (Heess et al., 2015;
Gu et al., 2016; 2017; Buckman et al., 2018; Pong et al., 2018; Tu & Recht, 2019).
Orthogonal to these, in the recent years we have seen a number of algorithms that are derived from different motivations and frameworks, but share the following common trait: they use future trajectory information τ t : T to accelerate optimization of a contextual policy π ( a t | s t , z ) with context z with respect to a parameterized reward function r ( s t , a t , z ) (see Section 3 for notations).
These hindsight algorithms have enabled Q-learning with sparse rewards (Andrychowicz et al., 2017), temporally-extended model-based RL with Q-function (Pong et al., 2018), mastery of 6-DoF object manipulation in cluttered scenes from human play (Lynch et al., 2019), efﬁcient multi-task
RL (Eysenbach et al., 2020; Li et al., 2020), ofﬂine self-supervised discovery of manipulation primitives from pixels (Chebotar et al., 2021), and ofﬂine RL using return-conditioned supervised learning with transformers (Chen et al., 2021a; Janner et al., 2021).
We derive a generic problem formulation covering all these variants, and observe that this hindsight information matching (HIM) framework, with behavioral cloning (BC) as the learning objective , can learn a conditional policy to generate trajectories that each satisfy any properties, including distributional.
Given this insight and recent casting of RL as sequence modeling (Chen et al., 2021a; Janner et al., 2021), we propose Generalized Decision Transformer (GDT), a family of algorithms for future information matching using hindsight behavioral cloning with transformers , and greatly expand the applicability of transformers and other powerful sequential modeling architectures within RL with only small architectural changes to DT .
In summary, our key contributions are:
• We introduce hindsight information matching (HIM) (Section 4, Table 1) as a unifying view of existing hindsight-inspired algorithms, and Generalized Decision Transformers (GDT) as a generalization of DT for RL as sequence modeling to solve any HIM problem (Figure 1). • Inspired by distribution RL (Bellemare et al., 2017; Dabney et al., 2018) and state-marginal matching (SMM)
(Lee et al., 2020; Ghasemipour et al., 2020; Gu et al., 2021), we deﬁne ofﬂine multi-task SMM problems, propose Categorical DT (CDT) (Section 5), validate its empirical performance to match feature distributions (even generalizing to a synthetic bi-modal target distribution at times), and construct the ﬁrst benchmark tasks for ofﬂine multi-task SMM.
• Inspired by one-shot imitation learning (Duan et al., 2017; Finn et al., 2017; Dasari & Gupta, 2020), we deﬁne ofﬂine multi-task imitation learning (IL) , propose a Wasserstein-distance evaluation metric, develop Bi-directional DT (BDT) as a fully expressive variant of GDT (Section 5) and demonstrate BDT’s competitive performance at ofﬂine multi-task IL. [Table] [Figure]
R ELATED W ORK
Hindsight Reinforcement Learning and Behavior Cloning Hindsight techniques (Kaelbling, 1993; Andrychowicz et al., 2017; Pong et al., 2018) have revolutionized off-policy optimization with respect to parameterized reward functions.
Two key insights were (1) for off-policy algorithms such as Q-learning (Mnih et al., 2015; Gu et al., 2016) and actor-critic methods (Lillicrap et al., 2016; Haarnoja et al., 2018; Fujimoto et al., 2018; Furuta et al., 2021a), the same transition samples can be used to learn with respect to any reward parameters, as long as the reward function is re-computable, i.e. “relabel”-able, like goal reaching rewards, and (2) if policy or Q-functions are smooth with respect to the reward parameter, generalization can speed up learning even with respect to “unexplored” rewards.
In goal-based RL where future states can inform “optimal” reward parameters with respect to the transitions’ actions, hindsight methods were applied successfully to enable effective training of goal-based Q-function for sparse rewards (Andrychowicz et al., 2017), derive exact connections between Q-learning and classic model-based RL (Pong et al., 2018), dataefﬁcient off-policy hierarchical RL (Nachum et al., 2018), multi-task RL (Eysenbach et al., 2020; Li et al., 2020), ofﬂine RL (Chebotar et al., 2021), and more (Eysenbach et al., 2021; Choi et al., 2021;
Ren et al., 2019; Zhao & Tresp, 2018; Ghosh et al., 2021; Nasiriany et al., 2021).
Additionally, Lynch et al.
and Gupta et al.
(2018) have shown that often BC is sufﬁcient for learning generalizable parameterized policies, due to rich positive examples from future states, and most recently Chen et al.
(2021a) and Janner et al.
(2021), when combined with powerful transformer architectures (Vaswani et al., 2017), it produced state-of-the-art ofﬂine RL and goal-based RL results.
Lastly, while motivated from alternative mathematical principles and not for parameterized objectives, future state information was also explored as ways of reducing variance or improving estimations for generic policy gradient methods (Pinto et al., 2017; Guo et al., 2021; Venuto et al., 2021).
Distributional Reinforcement Learning and State-Marginal Matching
Modeling the full distribution of returns instead of the averages led to the development of distributional RL algorithms (Bellemare et al., 2017;
Dabney et al., 2018; 2020; Castro et al., 2018; Barth-Maron et al., 2018) such as Categorical Q-learning (Bellemare et al., 2017).
While our work shares techniques such as discretization and binning, these works focus on optimizing a non-conditional reward-maximizing RL policy and therefore our problem deﬁnition is closer to that of state-marginal matching algorithms (Hazan et al., 2019; Lee et al., 2020;
Ghasemipour et al., 2020; Gu et al., 2021), or equivalently inverse RL algorithms (Ziebart et al., 2008; Ho & Ermon, 2016;
Finn et al., 2016; Fu et al., 2018; Ghasemipour et al., 2020) whose connections to feature-expectation matching have been long discussed (Abbeel & Ng, 2004).
However, those are often exclusively online algorithms even sample-efﬁcient variants (Kostrikov et al., 2019), since density-ratio estimations with either discriminative (Ghasemipour et al., 2020) or generative (Lee et al., 2020) approach requires on-policy samples, with a rare exception of Kostrikov et al.
Building on the success of DT and brute-force hindsight imitation learning, our Categorical DT is to the best our knowledge the ﬁrst method that benchmarks ofﬂine state-marginal matching problem in the multi-task settings.
RL and Imitation Learning as Sequence Modeling When scaled to the extreme levels of data and computing, sequence models such as transformers (Vaswani et al., 2017) can train models to master an impressive range of capabilities in natural language processing and computer vision (Devlin et al., 2019;
Radford et al., 2019; Brown et al., 2020; Radford et al., 2021;
Ramesh et al., 2021; Chen et al., 2021b; Bommasani et al., 2021; Dosovitskiy et al., 2020).
Comparing to their popularity in other areas, the adoption of transformers or architectural innovations in RL have been slow, partially due the difﬁculty of using transformers over temporal scales for online RL (Parisotto et al., 2020).
Recent successes have focused on processing variable-length per-timestep information such as morphology (Kurin et al., 2021), sensory information (Tang & Ha, 2021), one-shot or few-shot imitation learning (Dasari & Gupta, 2020), or leveraged ofﬂine learning (Chen et al., 2021a; Janner et al., 2021).
Our formulation enables sequence modeling to solve novel RL problems such as statemarginal matching with minimal architectural modiﬁcations to DT, greatly expanding the impacts of transformers and other powerful sequence models in RL.
P RELIMINARIES
We consider a Markov Decision Process (MDP) deﬁned by the tuple of action space A , state space
S , transition probability function p ( s (cid:48) | s, a ) , initial state distribution p ( s 0 ) , reward function r ( s, a ) , and discount factor γ ∈ (0 , 1] .
In deep RL, a policy that maps the state space to the action space is parameterized by the function approximators, π θ ( a | s ) 1 .
The RL objective is given by:
[Equation]
where p πt ( s ) = (cid:82)(cid:82) s 0: t ,a 0: t − 1 (cid:81) t p ( s t | s t − 1 , a t − 1 ) π ( a t | s t ) and ρ π ( s ) = (1 − γ ) (cid:80) t (cid:48)
γ t (cid:48) p πt (cid:48) ( s t (cid:48) = s ) are short-hands for time-aligned and time-aggregated state marginal distributions following policy π .
3. S TATE M ARGINAL M ATCHING
State marginal matching (SMM) (Lee et al., 2020; Hazan et al., 2019; Ghasemipour et al., 2020) has been recently studied as an alternative problem speciﬁcation in RL, where instead of stationary-reward maximization, the objective is to ﬁnd a policy minimizing the divergence D between its state marginal distribution
ρ π ( s ) to a given target distribution p ∗ ( s ) 2 :
[Equation]
where D is a divergence measure such as Kullback-Leibler (KL) divergence (Lee et al., 2020;
Fu et al., 2018) or, more generally, some f -divergences (Ghasemipour et al., 2020).
For the target distribution p ∗ ( s ) , Lee et al.
(2020) set a uniform distribution to enhance the exploration over the entire state space; Ghasemipour et al.
(2020) and Gu et al.
(2021) set through scripted distribution sketches to generate desired behaviors; and adversarial inverse RL methods (Ho & Ermon, 2016;
Fu et al., 2018; Ghasemipour et al., 2020; Kostrikov et al., 2020) set as the expert data for imitation learning.
Notably, unlike the RL objective in Eq.1, SMM objectives like Eq.2 no longer depend on task rewards and are only functions of state transition dynamics and target state distribution.
3. P ARAMETERIZED RL O BJECTIVES
Lastly, we discuss the basis for methods like HER and TDM (Andrychowicz et al., 2017; Pong et al., 2018), LfP (Lynch et al., 2019), and return-conditioned or upside-down RL (Srivastava et al., 2019; Kumar et al., 2019; Chen et al., 2021a; Janner et al., 2021): parameterized RL objectives.
Given parameterized reward functions with parameter z ∈ Z , a conditional policy π ( a | s, z ) is learned with respect to multiple values of z simultaneously weighted by p ( z ) .
As examples, the RL objective in Eq.1 becomes:
[Equation]
where the state marginal ρ πz is from rolling out a conditioned policy π ( ·|· , z ) .
These can be considered as a special case of contextual MDPs (Jiang et al., 2017) and are all multi-task RL problems.
H INDSIGHT I NFORMATION M ATCHING
We show how HER and TDM (Andrychowicz et al., 2017; Pong et al., 2018), LfP (Lynch et al., 2019), hindsight multi-task RL (Li et al., 2020;
Eysenbach et al., 2020), and return-conditioned or upside-down RL (Srivastava et al., 2019; Kumar et al., 2019; Chen et al., 2021a; Janner et al., 2021) all belong to hindsight algorithms with a shared idea of using future state information to automatically mine for positive, or “optimal”, examples with respect to certain contextual parameter values , where these examples can accelerate RL or be used for behavior cloning (BC), i.e. supervised learning.
We start by deﬁning additional notations.
Given a partial trajectory from state s t as τ t = { s t , a t , s t +1 , a t +1 , . . .
} , we deﬁne its information statistics as I ( τ t ) .
I ( τ t ) could be any function of a trajectory that captures some statistical properties in state-space or trajectory-space, such as sufﬁcient statistics of a distribution, like mean, variance or higher-order moments (Wainwright & Jordan, 2008).
For convenience, we further deﬁne the notion of a feature function Φ( · , · ) : S ×
A → F 5 , where the trajectory is then noted as τ Φ t = { φ t , φ t +1 , . .
. , φ T } , φ t =
Φ( s t , a t ) ∈ F and the information statistics as I Φ ( τ t ) . Φ in practice deﬁne stateaction-marginal ( s a ( s ) π ( a | s ) and the exact same algorithms apply.
There is a rich literature on one-shot, or few- meta learning.
For closer connections to parameterized policies and relabeling, we mainly discuss metric-based (or amortization-based) methods (Duan et al., 2016), opposed to gradient- approaches (Finn et al., 2017). DisCo RL (Nasiriany et al., 2021) conditions on a parameterized goal distribution and uses hindsight techniques; however, their RL objective in Equation 1 E s ∼ ρ πz ( s ) [log p ∗ z ( s )] , in contrast to a proper divergence objective like in Ghasemipour et al. (2020), is missing the H ( ρ πz ( s )) entropy term and is essentially just solving for parameterized stationary reward maximization, as also stated in their Remark 1.
Recent mutual information maximization or empowerment methods (Eysenbach et al., 2019; Sharma et al., 2020; Choi et al., 2021) also make similar assumptions; see Gu et al.
(2021) for more details.
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure] [Table] [Figure] [Table]
[Figure]
[Table] can be an identity function, the reward function r ( s, a ) , sub-dimensions of s (e.g. xy-velocities), or a generic parameterized function (e.g. auto-encoder).
Generalizing reward-centric intuitions in DT (Chen et al., 2021a), we deﬁne information matching (IM) problems as learning a conditional policy π ( a | s, z ) whose trajectory rollouts satisfy some desired information statistics value z :
[Equation]
An important observation for the IM objective (Eq.4) is that for any given trajectory τ , setting z ∗ =
I Φ ( τ ) will minimize the inner term divergence D =
and therefore τ states and actions are optimal with respect to z
= z ∗ and samples of ( τ i , z ∗ i ) can be used to accelerate RL or do BC .
We call these algorithms hindsight information matching (HIM) algorithms. Table 1, which classiﬁes prior methods into effectively four categories based on I Φ ( τ ) , leads us to have the following insights around HIM algorithms:
• New HIM algorithms can be proposed by simply changing I Φ ( τ ) , as we did to propose Categorical DT for (5) distribution-based.
• Given a choice of I Φ ( τ ) , new HIM algorithms can be proposed by changing implementation details (Furuta et al., 2021a), such as using “RL" or “BC" as algorithm type , doing “Online” or “Ofﬂine” training (Levine et al., 2020), and network architectures . All “Ofﬂine” “BC” methods could be adopted easily to “Online” learning through recursive data collections (Ghosh et al., 2021; Kumar et al., 2019; Matsushima et al., 2021).
• Only (1) goal-based and (2) multi-task can use “RL” as algorithm type , while all four, plus our (5) distribution-based, can use “BC”, because “RL” requires optimizing Eq.
4 with respect to the policy, which gets non-trivial for some choices of I Φ ( τ ) ; e.g. (3-5) return-based, full trajectory imitation, or distribution-based. “BC” bypasses the need to solve Eq. 4 and therefore is universally applicable to any I Φ ( τ ) or HIM algorithm 6 .
G ENERALIZED D ECISION T RANSFORMER
Following the insights in Section 4, we introduce Generalized Decision Transformer (GDT) , which generalizes DT (Chen et al., 2021a) based on different choices of I Φ ( τ ) , as described in Figure 1 and the last rows of Table 1. We chose DT as the base model since it is a simple model that uses “BC” as the algorithm type and “Transformer” as the architecture. The choice of “BC” is a must, so we can tractably train GDT with respect to any I Φ ( τ ) or HIM problem.
The choice for the architecture is more ﬂexible; however, we decided to use transformers (Vaswani et al., 2017) in this work due to their enormous scaling successes in language and vision domains (Dosovitskiy et al., 2020;
Brown et al., 2020; Ramesh et al., 2021).
See Algorithm 1 (in Appendix F) for the full pseudocode. While GDT in Figure 1 can lead to different algorithms depending on different choices of the feature function Φ( s, a ) and the anti-causal aggregator (which together determine I Φ ( τ ) ), in this work we focus our empirical studies on the following two variants: Categorical DT (CDT) and Bi-directional DT (BDT).
Before proceeding to deﬁne CDT and BDT, we ﬁrst concretely deﬁne the tasks they are designed to solve, namely: ofﬂine multi-task state-marginal matching (SMM) , and ofﬂine multi-task imitation learning (IL) . Given the intrinsic connection or equivalence between distribution matching and IL (Ghasemipour et al., 2020), these two separate terminologies may seem redundant.
However, inspired by the initial papers studying SMM problems (Lee et al., 2020; Ghasemipour et al., 2020) which qualitatively evaluates distribution matching results in speciﬁed state dimensions (e.g. xypositions), we deﬁne the imitation task as ofﬂine multi-task SMM if speciﬁc Φ is given, and as ofﬂine multi-task IL if Φ is an identity (i.e. φ = s ) or learned (e.g. auto-encoder). We essentially view IL as SMM evaluation on full state. Given these deﬁnition, we also deﬁne a single metric for both ofﬂine multi-task SMM/IL: typical IL assumes some availability of task reward or success evaluation, and indirectly measure the quality of imitation through it (Ho & Ermon, 2016; Fu et al., 2018).
Instead, again grounding on its connection to distribution matching (Ghasemipour et al., 2020), we propose a Wasserstein loss between statemarginal and target distributions as SMM-inspired metrics for evaluating ofﬂine multi-task SMM or
IL tasks. However, it is often intractable to measure such loss for full state or even for some state dimensions analytically because both state-marginal and target distributions can be non-parametric and we cannot access their densities. In practice, we empirically estimate it employing the binning of the feature space we speciﬁed. More discussions are included in Appendix C.
Inspired by the recent successes in distributional RL (Bellemare et al., 2017; Dabney et al., 2018; 2020), ofﬂine RL (Fujimoto et al., 2019; Jaques et al., 2020; Ghasemipour et al., 2021; Fujimoto & Gu, 2021) and state-marginal matching (Lee et al., 2020; Ghasemipour et al., 2020; Gu et al., 2021), we introduce Categorical DT (CDT) for ofﬂine state-marginal matching (SMM) problem in Section 5.1. Following the prior works (Bellemare et al., 2017; Furuta et al., 2021b), we assume low-dimensional Φ , e.g. rewards or state dimensions like xyz-velocities, and employ the discretization of feature spaces to form categorical approximations of continuous distributions.
To compute z ∗ t = I Φ ( τ t : T ) for all timesteps t given a trajectory τ 1: T , we use similar recursive Bellman-like computation inspired by Bellemare et al.
(2017) (see Appendix F for the details).
To the best of our knowledge, this is the ﬁrst paper to study ofﬂine multi-task SMM and propose an effective algorithm for it. 5. D ECISION T RANSFORMER WITH L EARNED Φ While CDT assumes some low-dimensional Φ is provided for tractable binning and distribution approximation, we also study cases where Φ or r is not provided, and instead Φ is learned through auto-encoding (Hinton & Salakhutdinov, 2006;
Bengio et al., 2012)
(DT-AE) or contrastive (van den Oord et al., 2018; Srinivas et al., 2020; Yang & Nachum, 2021) (DT-CPC) losses for DT (see Appendix G for the details).
In this case, CDT is unnecessary because if Φ learns sufﬁcient features of s , matching their means, i.e. moments , through DT is enough to match any distribution to an arbitrary precision (Wainwright & Jordan, 2008; Li et al., 2015). Since Φ is differentiable with respect to DT’s action-prediction losses, we also compare DT-E2E, where we learn Φ through end-to-end differentiation.
As Section 5.1 deﬁnes, these methods do ofﬂine multi-task SMM with full state, or ofﬂine multi-task IL, a similar objective to state-marginal matching or adversarial inverse RL (Ho & Ermon, 2016; Ghasemipour et al., 2020) in online RL. To the best of our knowledge, this is the ﬁrst ofﬂine multi-task IL method that explicitly accounts for SMM through architectural bottlenecks.
The absence of given Φ could be tackled with learning not only parameterized Φ as in Section 5.3, but also a parameterized aggregator. Building on the connection to one-shot imitation learning (Duan et al., 2017), we provide another natural extension of DT under GDT framework called Bi-directional
Decision Transformer (BDT) , which assumes an identity Φ , and learns representation within the aggregator, in this case a second (anti-causal) transformer (Radford et al., 2018) that takes a reverseorder state sequence as an input.
See Algorithm 1 in Appendix F for the pseudocode, and Appendix D for further comments on the connection to one-shot or meta learning.
While we found some positive results for even simple unsupervised regularizer approaches (e.g. DT-AE), we observe BDT could achieve substantially better ofﬂine multi-task IL results than DT- X variants in Section 5.3.
E XPERIMENTS
We empirically investigate the following questions:
• (SMM) Can CDT match unseen reward distributions?
• (SMM) Can CDT match and generalize to unseen 1D/2D state-feature distributions? • (SMM) Can CDT match unseen synthesized state-feature distributions?
• (IL) Can BDT perform ofﬂine one-shot imitation learning in full state?
We experiment on the OpenAI Gym, MuJoCo tasks (HalfCheetah, Hopper, Walker2d, Ant-v3), a common benchmark for continuous control (Brockman et al., 2016; Todorov et al., 2012).
Through the experiments, we use medium-expert datasets in D4RL (Fu et al., 2020) to ensure the decent data coverage.
We sort all the trajectories by their cumulative rewards, hold out ﬁve best trajectories and ﬁve 50 percentile trajectories as a test set (10 trajectories in total), and use the rest as a train set. We report the results averaged over 20 rollouts every 4 random seed.
We share our implementation to ensure the reproducibility 8 .
As discussed in Section 5.1 and Appendix C, we evaluate CDT/BDT with approximate distribution matching objective: Wasserstein-1 distance between categorical distributions of features in rollouts or target trajectories.
We compare CDT to DT, Meta-BC, and FOCAL (Li et al., 2021), a metric-based ofﬂine meta RL method, as baselines.
While Meta-BC and FOCAL does not solve the ofﬂine distribution matching problem directly, they provide decent baseline performance since their ofﬂine one-shot adaptation to the given target trajectories could deal with it (see Appendix B for the details).
6. R EWARD AND S TATE - FEATURE M ATCHING
First, we evaluate whether CDT could match its rollout to the target distribution.
We choose reward and state-feature, such as x-velocity of the agents, as feature spaces to match.
To specify the target distributions during the evaluation, we feed the categorical representation of the target to CDT. As the same as the reward case, DT takes the summation of the state-feature over a trajectory as an input.
We quantitatively compare CDT against baselines (Table 2) in x-velocity case, where CDT shows better matching results to the target distributions unseen during training. We provide the reward distribution results and the visualization in Appendix E.1, where CDT performs very well in all cases.
To test the generalization additionally, we intervene the target distributions by (1) shifting the target distributions in the test set by constant offsets, and (2) synthesizing novel distributions via python scripts.
See Appendix E.7 and E.8 for the results.
Furthermore, to investigate the scalability of CDT to multi-dimensional state-features, we experiment 2D state-feature distribution matching (xy-velocities on Ant) in Appendix E.3, where CDT outperforms other baselines.
[Table] See
The performance of ofﬂine methods in RL is often restricted by the coverage or quality of datasets. While we demonstrate CDT can perform ofﬂine state-marginal matching to unseen target distributions in Section 6.1, the standard ofﬂine datasets might not be diverse enough to observe the generalization since those are collected by single-task reward-maximization policies.
To test the generalization to more diverse behaviors, we investigate the following tasks: (1) z-velocity distribution matching with synthesized bi-modal behavior and (2) cheetah-velocity matching problem from meta RL/IL literature (Rakelly et al., 2019; Li et al., 2021; Fakoor et al., 2020) 6.2. S YNTHESIZING U NSEEN B I -M ODAL D ISTRIBUTION
To generate diverse behaviors for z-axis, we obtain the expert cheetah that backﬂips towards -x direction by modifying reward function (see Appendix E.4 for the details).
Combining expert backﬂipping trajectories and expert running forward trajectories from D4RL dataset, we construct a novel dataset with diverse behaviors.
We experiment the ofﬂine SMM with not only each uni-modal behavior (backﬂipping or running forward), but also synthesized bi-modal behavior; running forward ﬁrst, then backﬂipping during a single rollout, using patchworked target trajectories.
Table 3 and Figure 2 (a) show that CDT successfully matches the distribution to both uni-modal (running forward or backﬂipping) and synthesized bi-modal distributions better than DT and FOCAL, and is comparable to Meta-BC that originally designed to deal with such multi-task settings.
Due to the difﬁculty for RL algorithms to maximize Eq. 4, FOCAL struggles to solve the ofﬂine multi-task
SMM, even though FOCAL uses the same context embedding as Meta-BC. The bi-modal behavior learned by CDT can be seen at https://sites.google.com/view/generalizeddt .
[Table]
[Table]
bi-modal traj Target CDT DT (a) Z-Velocity −1 0 1 2 3 4 0.0 0.
P r o b a b ili t y x-vel = 0. −1 0 1 2 3 4 0.0 0.
x-vel = 1.
−1 0 1 2 3 4 0.0 0. x-vel = 2. −1 0 1 2 3 4 0.0 0.
P r o b a b i li
t y x-vel = 0. −1 0 1 2 3 4 0.0 0. x-vel = 1. −1 0 1 2 3 4 0.0 0.
x-vel = 2. Target CDT
DT (b) Unseen Cheetah-Velocity
6.2. D IVERSE U NSEEN D ISTRIBUTION FROM M ETA L EARNING T ASK
Generalization to unknown target demonstrations or tasks has been actively investigated in meta or one-shot RL/IL literature (Duan et al., 2016; Wang et al., 2016).
To verify the generalization of CDT to diverse behaviors, we adopt the cheetah-velocity task; a popular task in meta RL/IL
(Rakelly et al., 2019; Li et al., 2021; Fakoor et al., 2020), where the cheetah tries to run with the speciﬁed velocity.
We prepare 31 target x-velocities; taken from [0.0, 3.0], uniformly spaced at 0.1 intervals, and hold out { 0 . 5 , 1 . 5 , 2 . 5 } as a test set.
See Appendix E.5 for the dataset generation.
Table 4 and Figure 2 (b) reveal that CDT outperforms DT or FOCAL, and is slightly better than MetaBC through the distribution matching evaluation, which implies CDT could solve ofﬂine multi-task
SMM generalizing to the unknown target trajectories, given sufﬁciently diverse ofﬂine datasets.
[Table]
6. O NE - SHOT D ISTRIBUTION M ATCHING IN F ULL S TATE
Lastly
[Table]
we investigate BDT for ofﬂine multi-task IL, where we do not observe rewards nor state features explicitly.
Instead, target full state trajectories that the agents are expected to mimic is given.
We compare BDT against parameterized Φ variants; DT-AE, -CPC
[Table]
and -E2E discussed in Section 5.3.
We consider three strategies to train the encoder for DT-AE and -CPC: training with only unsupervised loss, training with unsupervised and DT’s supervised loss jointly (called as “joint”), and pre-training with only unsupervised loss and freezing the weights during DT training (called as “frozen”).
We aggregate the learned Φ by summation within the input sequence (length is 20).
We evaluate BDT and DT- X with the same distribution matching evaluation as Section 6.1. We sweep m -dim learned feature from the encoder Φ( s ) with m ∈ { 1 , 4 , 16 } . Table 5 presents the ofﬂine multi-task IL results with respect to x-velocity distribution, using m = 16 embeddings (see
Appendix E.6 for the full results including m = 1 , 4 , and the reward distribution case). Similar to the discussion in Yang & Nachum (2021), DT-CPC sometimes fails to obtain sufﬁcient representation for imitation. While even simple approaches, DT-AE and DT-AE (frozen), show positive results compared to no-context BC baselines (in Table 2), BDT outperforms all other learned Φ variants or Meta-BC and is comparable to CDT or DT (also in Table 2) with longer input ( N = 50 ).
This implies that even though we don’t assume the state-feature speciﬁcation, aggregator choice in GDT with minimal architectural changes may solve the ofﬂine distribution matching problem efﬁciently.
We leave more sophisticated objectives or architectural changes as future work.
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure] [Table] [Figure] [Table]
C ONCLUSION
We provide a uniﬁed perspective on a wide range of hindsight algorithms, and generalize the problem formulation as hindsight information matching (HIM).
Inspired by recent successes in RL as sequence modeling, we propose Generalized Decision Transformer (GDT) which includes DT, Categorical
DT and Bi-directional DT as special cases and is applicable to any HIM with proper choices of Φ and aggregator.
We show how Categorical DT, a minor modiﬁcation of DT, enables the ﬁrst effective ofﬂine state-marginal matching algorithm and propose new benchmark tasks for this problem class. We also demonstrate the effectiveness of Bi-directional DT as a one-shot imitation learner, signiﬁcantly outperforming simple variants based on DT. We hope our proposed HIM and GDT frameworks shed new perspectives on hindsight algorithms and the applicability of sequence modeling to much broader classes of RL problems beyond classic reward-based RL
E THICS S TATEMENT
Since this paper mainly focuses on the reinterpretation of hindsight RL algorithms and experiments on existing benchmark datasets, we believe there are no ethical concerns.
R EPRODUCIBILITY S TATEMENT
We share our codes to ensure the reproductivity. The details of hyperparameters are described in
Appendix A and B.
The detailed settings of experiments are described in the Section 6, Appendix E, and G. We report the results averaged over 20 rollouts every 4 random seed
A PPENDIX A H YPER - PARAMETER OF G ENERALIZED D ECISION T RANSFORMERS
We implement Categorical Decision Transformer and Bi-directional Decision Transformer, built upon the ofﬁcial codebase released by Chen et al.
(2021a)
( https://github.com/kzl/ decision-transformer ).
We follow the most of hyperparameters as they did (Table 6).
[Table]
While, to the best of our knowledge, there are no prior work to tackle the ofﬂine state-marginal matching problem, we can regard meta or one-shot imitation learning as the methods solving similar problem (see Appendix D for futher discussion).
In this work, we choose Meta-BC and FOCAL (Li et al., 2021), a metric-based ofﬂine meta RL method, as decent baselines.
FOCAL FOCAL is a ofﬂine meta RL method combining BRAC (Wu et al., 2019) with metricbased approach.
It utilizes deterministic context encoder trained with inverse-power distance metric losses and detached from Bellman backup gradients. We follow the hyperparameters in the ofﬁcial implementation ( https://github.com/LanqingLi1993/FOCAL-ICLR ).
Deterministic context encoder takes single-step state-action-reward tuple as a context for task inference. We parameterize it with (200, 200, 200)-layers MLP. We train deterministic context encoder withiteration ﬁrst, and then train BRAC agent with task-conditioned policy and value functions with 100000 iteration. We use (256, 256, 256)-layers MLPs for policy and value network, and set batch size to 256.
Meta-BC We also use metric-based Meta-BC (Duan et al., 2017; Dasari & Gupta, 2020) as a strong baseline method for ofﬂine multi-task SMM.
We adapt deterministic context encoder from FOCAL to infer the task.
We train Meta-BC in the same way as FOCAL just replacing BRAC to BC.
The objective is mean-squared error minimization.
Throughout our experiments, Meta-BC shows better results than FOCAL, because RL algorithms often struggle to optimize Eq.
4 for distribution matching and FOCAL tries to maximize the task reward, which is not necessarily required for distribution matching problem.
In addition, BC often converges faster than ofﬂine RL methods.
C D ETAILS OF E VALUATION
Throughout the paper, we evaluate both CDT and BDT from a distribution matching perspective by formulating them as ofﬂine multi-task SMM or ofﬂine multi-task IL problem.
However, the current distribution matching research in RL (Lee et al., 2020; Ghasemipour et al., 2020; Gu et al., 2021) has been suffered from the lack of quantitative metrics for evaluation (while standard RL or BC are typically evaluated on the task reward performance).
As summarized in Table 7, prior works (Lee et al., 2020; Ghasemipour et al., 2020) evaluate the SMM performance by qualitative density visualization using rollout particles.
Although the distance between state-marginal and target distribution seems the most intuitive and suitable metric to quantify the performance of distribution matching algorithms, it is often intractable to measure such distance analytically because both state-marginal and target distribution can be non-parametric; we cannot access their densities, and only their samples are available.
While a concurrent work (Gu et al., 2021) tackles this problem by leveraging sample-based energy distance estimation, we introduce a single SMM-inspired evaluation for both ofﬂine multi-task SMM and ofﬂine multi-task IL via estimating Wasserstein-1 distance between empirical categorical distributions.
Since the discretization of low-dimensional features, such as reward, have success in many RL methods (Bellemare et al., 2017; Dabney et al., 2018; 2020; Furuta et al., 2021b), quantiﬁcation of distribution matching performance by Wasserstein-1 distance could be reliable evaluations (in addition Wasserstein-1 distance is symmetric, different from KL distance that is asymmetric).
We note that due to the equivalence between inverse RL and SMM methods, the performance of distribution matching methods may be measured via task reward when assuming the accessivity to the expert trajectories (Ho & Ermon, 2016;
Fu et al., 2018; Kostrikov et al., 2019).
However, in our experiments, it is not suitable to evaluate the performance based on task reward since we uses the sub-optimal trajectories (Section 6.1) or multi-task trajectories from different reward functions (Section 6.2).
Wasserstein-1 distance between state-marginal distribution ρ π ( s ) and target distribution p ∗ ( s ) is deﬁned as:
[Equation]
where Γ is the set of all possible joint distributions ν whose marginals are ρ π and p ∗ respectively ( X and Y are random variables).
In this work, we empirically estimate Eq.
by focusing on the “manually-speciﬁed” feature φ ∈ F (e.g. reward, xyz-velocities, etc; deﬁned in Section 4) and employing binning and discretization.
We discretize the feature space F and obtain B bins (per dimension), whose representatives are { ¯ φ 1 , ¯ φ 2 , . . .
¯ φ B } .
The range of feature space [ φ min , φ max ] is pre-deﬁned from the given ofﬂine datasets.
Then, we get categorical distribution from the target trajectory τ ; ˆ p ∗ τ ( φ ) =
{ (¯ φ 1 , c ∗ τ 1 ) , . . .
(¯ φ B , c ∗ τB ) } , and from the rollouts of the policy π (using 4 seeds × 20 rollouts); ˆ ρ π ( φ ) = { (¯ φ 1 , c π 1 ) , . . .
(¯ φ B , c πB ) } , where c ∗ τ and c π are the weights of each bin (i.e.
(cid:80)
Bl =1 c ∗ τl = 1 and (cid:80)
Bl =1 c
πl
= 1 ).
We compute the evaluation metric averaging on the test set of the trajectories D test : [Equation] w ij ≥ 0 , B (cid:88)
j = w
[Equation]
c
[Equation] B (cid:88) i = w [Equation]
≤ c πj ,
B (cid:88) i =
B (cid:88)
j = w ij = 1 .
In practice, we utilize the python package ( https://github.com/pkomiske/
Wasserstein ) released by Komiske et al.
(2020) to compute it.
[Table]
D C ONNECTION TO M ETA L EARNING
While we solve ofﬂine information matching problems in this paper, our formulations (especially Bi-directional DT) and experimental settings are similar to ofﬂine meta RL (Dorfman et al., 2021; Mitchell et al., 2021;
Li et al., 2021) and meta/one-shot imitation learning (Yu et al., 2019; Ghasemipour et al., 2019; Finn et al., 2017; Duan et al., 2017) (especially metric-based approach (Rakelly et al., 2019; Duan et al., 2016; Fakoor et al., 2020)).
We brieﬂy clarify the relevance and difference between them (Table 8).
Ofﬂine Meta RL Recently, some works deal with ofﬂine meta RL problem, assuming task distribution and ofﬂine training with pre-stored transitions collected by the (sub-) optimal or scripted task-conditioned agents (Dorfman et al., 2021;
Mitchell et al., 2021; Li et al., 2021; Pong et al., 2021;
Zhao et al., 2021).
In these works, few test-task trajectories, following the same task distribution but unseen during training phase, are given at test-time (i.e. few-shot), and the agents adapt the given task in an online (Pong et al., 2021; Zhao et al., 2021; Dorfman et al., 2021) or fully-ofﬂine (Mitchell et al., 2021; Li et al., 2021) manner. Meta Imitation Learning Another related domain is meta imitation learning, also assuming task distribution and ofﬂine training with pre-stored expert transitions per tasks (Yu et al., 2019;
Ghasemipour et al., 2019; Finn et al., 2017; Duan et al., 2017; Xu et al., 2019; Gleave & Habryka, 2018; Dasari &
Gupta, 2020).
While meta inverse RL methods (Yu et al., 2019; Xu et al., 2019; Gleave & Habryka, 2018) require online samples during test-time adaptation, its off-policy extension and BC-based approach performs ofﬂine adaptation with given unseen trajectories (Ghasemipour et al., 2019;
Finn et al., 2017; Dasari & Gupta, 2020)
[Table]
Our work, in contrast, assume no-adaptation at test time and evaluation criteria is a distance between the feature distributions, not the task rewards [Table] they E D ETAILS OF E XPERIMENTS
In this section, we provide the details and supplemental quantitative/qualitative results of the experiments in Section 6.
Figure 3 visualizes the dataset distributions we use in the experiments.
When we sort all the trajectories based on their cumulative rewards, each quality of trajectory (best, middle, worst) shows a different shape of distribution
[Figure]
and the distribution of the whole dataset seems a weighted mixture of those
[Figure]
E. Q UANTITATIVE AND Q UALITATIVE R ESULTS OF R EWARD AND S TATE - FEATURE M ATCHING
We provide the quantitative comaprison of Section 6.1 between Categorical DT and DT in the reward (Table 9) matching problem, computing Wasserstein-1 distance between the discretized rollout and target feature distributions.
Generally, similar to the x-velocity case, CDT shows the better results in ofﬂine multi-task SMM compared to original DT.
We also visualize some of CDT results in Figure
[Table]
[Table]
[Figure]
E. E VALUATION ON T ASK P ERFORMANCE
While in this paper we focus on the evaluation with the SMM-inspired distribution matching objective, such as Wasserstein-1 distance, we here provide the evaluation on the task rewards.
Table 10 shows that DT seems consistently better methods than Categorical DT on the task rewards evaluations, and achieves similar performances to the held-out trajectories.
[Table] E. 2D S TATE - FEATURE D ISTRIBUTION M ATCHING We also consider two-dimensional state-features (xy-velocities) distribution matching in Ant-v3. Same as 1D state-feature distribution matching in HalfCheetah, Hopper, and Walker2d-v3 (Section 6.1), we also use medium-expert(-v2) datasets from D4RL (Fu et al., 2020).
We bin the state-features per dimension separately to reduce the dimension of the categorical distribution that CDT takes as input, while in test-time we evaluate the performance with Wasserstein-1 metric on the joint distribution.
For DT, we compute the summation of x- and y-velocity each over trajectories and normalize them with the maximum horizon.
DT feeds these two scalars as information statistics to match.
Table 11 reveals that CDT performs better even in the case of two-dimensional state-features distributions, while DT doesn’t generalize to expert-quality trajectories.
As shown in Figure 5, while CDT could cope with the distribution shift between expert and medium target distribution, DT always ﬁts the medium one even if the expert trajectory is given as a target. CDT successfully scales to the ofﬂine multi-task SMM problem in the multi-dimensional feature spaces [Table]
[Figure]
E. D ETAILS OF S YNTHESIZING U NSEEN B I -M ODAL D ISTRIBUTION
To construct the dataset, we modiﬁed the original reward function in HalfCheetah-v3, adding absolute z-velocity term (such as +np.abs(z_vel) ), where the expert cheetah backﬂips towards -x direction. We trained SAC agent until convergence (3 million gradient steps), using pytorch implementation released by Furuta et al.
(2021a), and then collected 500 trajectories × 1000 time steps.
We combined them with 500 trajectories × 1000 time steps from halfcheetah-expert-v2 dataset in D4RL, which consists of both backﬂipping and running forward behaviors. For the evaluation, we prepared additional 5 trajectories of backﬂipping and 5 of running forward as uni-modal behaviors (10 test trajectories in total). In addition, we synthesized a bi-modal behavior by dividing each 1000-step trajectories into 500-step sub-trajectories, and concatenating them across different behaviors, which results in the patchworked trajectories of ﬁrst 500-step running forward and next 500-step backﬂipping (also 10 trajectories in total). E. D ETAILS OF D IVERSE U NSEEN D ISTRIBUTION FROM M ETA L EARNING T ASK
Following prior meta RL/IL works (Rakelly et al., 2019; Ghasemipour et al., 2019; Pong et al., 2021; Li et al., 2021; Fakoor et al., 2020), we modiﬁed the reward function for the cheetah to run with speciﬁed velocity (such as -np.abs(x_vel - target_vel) ), and set the horizon tosteps.
We prepared 31 target x-velocities; taken from [0.0, 3.0], uniformly spaced at 0.1 intervals.
We also trained the SAC agents until convergence (3 million gradient steps), using pytorch implementation released by Furuta et al. (2021a), and collected 250 trajectories × 200 time steps each. To simplify the problem than meta learning settings, we held out the 10 trajectories whose x-velocity is { 0 . 5 , 1 . 5 , 2 . 5 } as a test set, and used the rest as a train data. E. Q UANTITATIVE AND Q UALITATIVE R ESULTS OF O NE - SHOT D ISTRIBUTION M ATCHING IN F ULL S TATE
Table 12 and Table 13 shows the one-shot reward and state-feature distribution matching results respectively. In addition to the embedding size m , we also sweep the different context window N = 20 , 50 , 100 for BDT ( m = 16 ). While even simple auto-encoder regularizer (DT-AE or
DT-AE (frozen)) sometimes works well compared to no-context BC baselines presented in Tableand Table 9, BDT, using (second) anti-causal transformer as an encoder Φ and its aggregator, seems consistently better than other strategies or Meta-BC baseline for ofﬂine multi-task SMM and is comparable to CDT or DT results (also presented in Table 2 and Table 9) with longer context length ( N = 50 ).
Through the experiment we observe that while there are no clear trends in DT-AE, -CPC or -E2E as the size of context embedding m grows, BDT improves its performance with larger size of embedding.
Such intuitive properties might a good features to design the architectures.
We visualize the qualitative results of BDT ( m = 16 , N = 20 ) in Figure 6.
[Table] [Table] [Table] [Figure]
E. S HIFTING THE T ARGET D ISTRIBUTION
To generate the unseen but manageable generalization-test trajectories within the support of dataset distribution
[Table] we make the reward and velocities values of trajectories in the test set shift with a constant offset: bin_size ×{− 3 . 0 , − 2 . 0 , − 1 . 0 , 0 . 0 , +1 . 0 , +2 . 0 , +3 . 0 } . Table 14 shows the quantitative comparison between CDT and DT, based on Wasserstein-1 distance between two distributions.
CDT successfully handles the distribution shifts (especially in hopper) better than DT.
We also provide the state-feature results (Table 15) and qualitative visualizations (Figure 7 and Figure 8)
[Table]
which reveals that CDT can match the rollouts to the shifted target distributions when they are within the support of dataset distributions
[Table] [Figure] [Table] [Figure]
[Table] [Table] [Figure] [Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Figure]
[Table]
[Figure]
[Table]
[Figure] E S YNTHESIZING U NREALISTIC T ARGET D ISTRIBUTION We synthesize six target distributions manually generating x-velocity samples from Gaussian distributions via python scripts as done in prior works (Ghasemipour et al., 2020; Gu et al., 2021).
Since we consider the one-dimensional feature space (x-velocity), we simply specify the mean and standard deviation of Gaussian distributions referring each dataset distribution, as shown in Figure 3, and then generate the 1000 samples per trajectory.
While these targets are designed at least within the support of the dataset, we do not consider physical realizability.
• HalfCheetah: ( µ, σ ) = (5.0, 1.0), (13.0, 1.0), (9.0, 1.0), (2.5, 1.0), {(5.0, 1.0), (13.0, 1.0)}, {(9.0, 1.0), (2.5, 1.0)}. • Hopper: ( µ, σ ) = • Walker2d: ( µ, σ ) = For the last two sets, that have different distributional parameters { ( µ 1 , σ 1 ) , ( µ 2 , σ 2 ) } , we sampled from two gaussian distributions 500 samples each, and marge them as one trajectory that has multiple modes.
Although they might be unrealistic, Figure 9 implies that CDT tends to match the target distributions, even in the cases of bi-modal target distributions.
Such generalization to synthesized distribution is an important beneﬁt of distribution-conditioned training.
We also quantify the performance of CDT against DT from distributional matching perspective in Table [Table] [Figure] We synthesize the each target distribution from Gaussian distributions.
While the results are worse than for realistic test target distributions in Figure 4, considering that many of these arbitrary synthetic targets could be unrealizable, seeing bi-modal matching results show that indeed CDT has learned to generalize something non-trivial
[Figure]
Method
[Table] [Figure] [Table] F D ETAILS FOR C ATEGORICAL D ECISION T RANSFORMER
Categorical Decision Transformer (CDT) takes histograms of categorical distribution (i.e. discrete approximations of feature distributions; B -dim vector) as the inputs of the transformer.
Here we describe how to compute the distributions for all timesteps given a trajectory t ∈ [0 , 1 , . .
, T ] .
For simplicity, we explain the case of one-dimensional feature (e.g. scalar reward), but for n -dimensional features, we can adopt following procedure per each dimension and arrive at n categorical features.
This essentially approximates the full joints with a product of independent marginal distribution per dimension, and ensures that number of samples for getting reasonably discretized approximations do not need to grow exponentially as the dimension grows.
At ﬁrst, we discretize the feature space F using B bins (per dimension), and convert the feature φ t into the one-hot representation ˜ φ t .
The range of feature space [ φ min , φ max ] is pre-deﬁned from the given ofﬂine datasets.
z Φ hist ( t ) , the categorical feature distribution at time step t , can be computed recursively following Bellman-like equation:
[Equation]
(7) where 1 is the indicator function.
We compute a series of z Φ hist in a backward manner starting from T .
After we obtain the desired information statistics for all trajectories, we feed them to the categorical transformer during training/test time.
We describe the python-like pseudocode in Algorithm 1, coloring the changes from the original Decision Transformer (Chen et al., 2021a). G D ETAILS OF D ECISION T RANSFORMER WITH L EARNED Φ
While any unsupervised regularizer for an encoder could be combined into the action MSE loss of
Decision Transformer to obtain the learned Φ efﬁciently, we observe that even simple objectives, such as auto-encoder and contrastive loss, sometimes perform well.
For auto-encoder regularization (DT-AE), we train the MLP encoder (parameterized by ψ ) and decoder with MSE loss of current state reconstruction:
[Equation]
Then, we use the output of the encoder as a learned information statistics. In addition, for contrastive loss (DT-CPC), we adopt CURL objective (Srinivas et al., 2020) for state input while adding gaussian perturbation (cid:15) ∼ N ( µ = 0 . 0 , σ = 0 . 1) as data argumentation (following Sinha et al. We train the MLP encoder as a query, use its momentum encoder as a key: [Equation]
where W is a learned parameter matrix for the bi-linear inner-product, and ˜ ψ is the weights of the momentum encoder, updated as ˜ ψ ← m ˜ ψ
+ (1 − m ) ψ , and m = 0 . We treat its trained encoder output as a learned information statistics. It remains as future work to combine more advanced, temporary-extended objectives, such as attentive contrastive learning approach proposed in Yang & Nachum (2021). As described in Section 6.3, we consider three strategies to train the encoder for DT-AE and -CPC: training with only unsupervised loss, training with unsupervised and DT’s supervised loss jointly (called as “joint”), and pre-training with only unsupervised loss and freezing the weights during DT training (called
# z: [Table] [Table] timesteps # transformer:
[Table]
[Table] [Table] [Table] [Table]
[Table] [Table] _z: linear # anti_causal_tf: second as and aggregator # embed_t: learned episode positional embedding # pred_a: linear action prediction layer # compute_stats: a function to compute information statistics # main model def DecisionTransformer(z, s, a, t): # compute embeddings for tokens pos_embedding = embed_t(t) s_embedding = embed_s(s)
+ pos_embedding a_embedding = embed_a(a) + pos_embedding if categorical: z_embedding = embed_z(z)
+ pos_embedding elif bi_directional:#inputstatesequence in a reverse order # NOTE:
z is a target state sequence here reversed = flip(z) z_embedding = embed_z(anti_causal_tf(reversed))
+ pos_embedding input_embeds = stack(z_embedding, s_embedding, a_embedding)
# use transformer to get hidden states hidden_states = transformer(input_embeds=input_embeds)
# select hidden states for action prediction tokens a_hidden
= unstack(hidden_states).actions
# predict action return pred_a(a_hidden) # training loop train_z =
compute_stats(train_dataset) # dims: (batch_size, K, dim) for z, (s, a, t) in zip(train_z, train_dataset): if unsupervised:z=s a_preds =
DecisionTransformer(
) loss = mean((a_preds - a)**2) optimizer.zero_grad(); loss.backward(); optimizer.step() # evaluation loop test_z = compute_stats(test_dataset) n_tests = len(test_dataset) for index in range(n_tests): test_trajectory = test_dataset[index]
max_time_steps = len(test_trajectory) s, a, t, done =
[env.reset()], [], [1], False # conditioning on the desired information statistics if categorical:z=[test_z[index][0]] elif bi_directional:z=[test_trajectory[’observations’][0]] for t in range(max_time_steps): action = DecisionTransformer(z, s, a, t)[-1] new_s, r, done, _ = env.step(action)
# append new tokens to sequence if categorical: z = z + [test_z[index][t+1]] elif bi_directional:z=z+[test_trajectory[’observations’][t+1]] s, a, t = s + [new_s], a + [action], t + [len(z)]
z, s, a, t =
z[-N:], ...
# only keep context length of N