Decision Transformer: Reinforcement Learning via Sequence Modeling
Decision Transformer: Reinforcement Learning via Sequence Modeling
Decision Transformer:用序列建模做强化学习
Lili Chen Kevin Lu Aravind Rajeswaran Kimin Lee Aditya Grover Michael Laskin Pieter Abbeel Aravind Srinivas Affiliation: equal contribution equal advising Igor Mordatch Affiliation: equal contribution equal advising Affiliation: UC Berkeley Facebook AI Research Google Brain {lilichen, kzl}@berkeley.edu
Abstract
摘要
We introduce a framework that abstracts Reinforcement Learning (RL) as a sequence modeling problem. This allows us to draw upon the simplicity and scalability of the Transformer architecture, and associated advances in language modeling such as GPT-x and BERT. In particular, we present Decision Transformer, an architecture that casts the problem of RL as conditional sequence modeling. Unlike prior approaches to RL that fit value functions or compute policy gradients, Decision Transformer simply outputs the optimal actions by leveraging a causally masked Transformer. By conditioning an autoregressive model on the desired return (reward), past states, and actions, our Decision Transformer model can generate future actions that achieve the desired return. Despite its simplicity, Decision Transformer matches or exceeds the performance of state-of-the-art model-free offline RL baselines on Atari, OpenAI Gym, and Key-to-Door tasks.
我们提出一个把强化学习(RL)抽象为序列建模问题的框架,从而借用 Transformer 架构的简洁与可扩展性,以及 GPT-x、BERT 等语言模型进展。具体地,我们提出 Decision Transformer:把 RL 问题写成条件序列建模。与拟合价值函数或计算策略梯度的先前 RL 路线不同,Decision Transformer 仅借助因果掩码 Transformer 输出最优动作。通过对期望回报(奖励)、过去状态与动作条件化一个自回归模型,Decision Transformer 可生成达成期望回报的未来动作。尽管形式简单,它在 Atari、OpenAI Gym 与 Key-to-Door 任务上匹配或超过当时最强的无模型离线 RL 基线。
图 1:Decision Transformer 结构[^1]。状态、动作与回报送入模态专用线性嵌入,并加上按回合时间步的位置编码。token 送入 GPT 架构,在因果自注意力掩码下自回归预测动作。
1 Introduction
1 引言
Contents
Recent work has shown transformers [1] can model high-dimensional distributions of semantic concepts at scale, including effective zero-shot generalization in language [2] and out-of-distribution image generation [3]. Given the diversity of successful applications of such models, we seek to examine their application to sequential decision making problems formalized as reinforcement learning (RL). In contrast to prior work using transformers as an architectural choice for components within traditional RL algorithms [4, 5], we seek to study if generative trajectory modeling – i.e. modeling the joint distribution of the sequence of states, actions, and rewards – can serve as a replacement for conventional RL algorithms.
目录
近期工作表明,Transformer [1] 能大规模建模语义概念的高维分布,包括语言中的有效零样本泛化 [2] 与分布外图像生成 [3]。鉴于此类模型应用多样,我们考察其在形式化为强化学习(RL)的序列决策问题上的应用。与把 Transformer 仅当作传统 RL 算法内部部件的先前工作 [4, 5] 不同,我们想研究:生成式轨迹建模——即建模状态、动作与奖励序列的联合分布——能否替代常规 RL 算法。
We consider the following shift in paradigm: instead of training a policy through conventional RL algorithms like temporal difference (TD) learning [6], we will train transformer models on collected experience using a sequence modeling objective. This will allow us to bypass the need for bootstrapping for long term credit assignment – thereby avoiding one of the “deadly triad” [6] known to destabilize RL. It also avoids the need for discounting future rewards, as typically done in TD learning, which can induce undesirable short-sighted behaviors. Additionally, we can make use of existing transformer frameworks widely used in language and vision that are easy to scale, utilizing a large body of work studying stable training of transformer models.
我们考虑如下范式转变:不再用时序差分(TD)学习 [6] 等常规 RL 算法训策略,而是用序列建模目标、在已收集经验上训练 Transformer。由此可绕开为长期信用分配做 bootstrap,从而避开已知会使 RL 不稳的「致命三角」之一 [6];也不必像 TD 学习那样对未来奖励打折,后者常诱发短视行为。此外,可直接使用语言与视觉中广泛、易扩展的现成 Transformer 框架,以及大量关于稳定训练 Transformer 的研究。
In addition to their demonstrated ability to model long sequences, transformers also have other advantages. Transformers can perform credit assignment directly via self-attention, in contrast to Bellman backups which slowly propagate rewards and are prone to “distractor” signals [7]. This can enable transformers to still work effectively in the presence of sparse or distracting rewards. Finally, empirical evidence suggest that a transformer modeling approach can model a wide distribution of behaviors, enabling better generalization and transfer [3].
除擅长建模长序列外,Transformer 还有其他优点。它可通过自注意力直接做信用分配,相对缓慢传播奖励、易受「干扰」信号影响的 Bellman 备份 [7]。这使得在稀疏或干扰奖励下 Transformer 仍可有效工作。经验证据也表明,Transformer 建模方法能刻画广泛行为分布,利于更好泛化与迁移 [3]。
We explore our hypothesis by considering offline RL, where we will task agents with learning policies from suboptimal data – producing maximally effective behavior from fixed, limited experience. This task is traditionally challenging due to error propagation and value overestimation [8]. However, it is a natural task when training with a sequence modeling objective. By training an autoregressive model on sequences of states, actions, and returns, we reduce policy sampling to autoregressive generative modeling. We can specify the expertise of the policy – which “skill” to query – by selecting the desired return tokens, acting as a prompt for generation.
我们通过离线 RL检验假设:智能体需从次优数据学习策略——在固定、有限经验上产出尽可能有效的行为。该设定因误差传播与价值高估而一向困难 [8],但对序列建模目标却很自然。在状态、动作与回报序列上训练自回归模型后,策略采样就变成自回归生成。通过选择期望回报 token 作为生成提示,可指定策略专长——查询何种「技能」。
Figure 2: Illustrative example of finding shortest path for a fixed graph (left) posed as reinforcement learning. Training dataset consists of random walk trajectories and their per-node returns-to-go (middle). Conditioned on a starting state and generating largest possible return at each node, Decision Transformer sequences optimal paths.
图 2:把固定图上找最短路(左)写成强化学习的示意。训练数据由随机游走轨迹及其每节点回报-to-go 组成(中)。条件于起始状态并在每个节点生成尽可能大的回报,Decision Transformer 可串出最优路径。
Illustrative example. To get an intuition for our proposal, consider the task of finding the shortest path on a directed graph, which can be posed as an RL problem. The reward is when the agent is at the goal node and otherwise. We train a GPT [9] model to predict next token in a sequence of returns-to-go (sum of future rewards), states, and actions. Training only on random walk data – with no expert demonstrations – we can generate optimal trajectories at test time by adding a prior to generate highest possible returns (see more details and empirical results in the Appendix) and subsequently generate the corresponding sequence of actions via conditioning. Thus, by combining the tools of sequence modeling with hindsight return information, we achieve policy improvement without the need for dynamic programming.
示意例子。为建立直觉,考虑有向图上找最短路,可写成 RL:在目标节点奖励为 ,否则为 。我们训练 GPT [9],在回报-to-go(未来奖励之和)、状态与动作序列中预测下一 token。仅在随机游走数据上训练——无专家演示——测试时通过对生成最高可能回报加入先验(附录有细节与结果),再条件化生成对应动作序列,即可得到最优轨迹。于是,把序列建模工具与后见回报信息结合,无需动态规划即可实现策略改进。
Motivated by this observation, we propose Decision Transformer, where we use the GPT architecture to autoregressively model trajectories (shown in Figure 1). We study whether sequence modeling can perform policy optimization by evaluating Decision Transformer on offline RL benchmarks in Atari [10], OpenAI Gym [11], and Key-to-Door [12] environments. We show that – without using dynamic programming – Decision Transformer matches or exceeds the performance of state-of-the-art model-free offline RL algorithms [13, 14]. Furthermore, in tasks where long-term credit assignment is required, Decision Transformer capably outperforms the RL baselines. With this work, we aim to bridge sequence modeling and transformers with RL, and hope that sequence modeling serves as a strong algorithmic paradigm for RL.
受此启发,我们提出 Decision Transformer:用 GPT 架构自回归建模轨迹(见图 1)。我们在 Atari [10]、OpenAI Gym [11] 与 Key-to-Door [12] 的离线 RL 基准上评估,检验序列建模能否做策略优化。结果表明——不使用动态规划——Decision Transformer 匹配或超过当时最强无模型离线 RL 算法 [13, 14]。在需要长期信用分配的任务上,它明显优于 RL 基线。本文旨在把序列建模与 Transformer 和 RL 桥接起来,并希望序列建模成为 RL 的有力算法范式。
2 Preliminaries
2 预备知识
2.1 Offline reinforcement learning
2.1 离线强化学习
We consider learning in a Markov decision process (MDP) described by the tuple (, , , ). The MDP tuple consists of states , actions , transition dynamics , and a reward function . We use , , and to denote the state, action, and reward at timestep , respectively. A trajectory is made up of a sequence of states, actions, and rewards: . The return of a trajectory at timestep , , is the sum of future rewards from that timestep. The goal in reinforcement learning is to learn a policy which maximizes the expected return in an MDP. In offline reinforcement learning, instead of obtaining data via environment interactions, we only have access to some fixed limited dataset consisting of trajectory rollouts of arbitrary policies. This setting is harder as it removes the ability for agents to explore the environment and collect additional feedback.
我们在由元组 , , , 描述的马尔可夫决策过程(MDP)中学习。元组含状态 、动作 、转移动态 与奖励函数 。用 、、 分别表示时间步 的状态、动作与奖励。轨迹由状态、动作与奖励序列组成:。时间步 的轨迹回报 是从该步起未来奖励之和。强化学习的目标是学习最大化期望回报 的策略。在离线强化学习中,不通过与环境交互获取数据,只能访问由任意策略 rollout 组成的固定有限数据集。该设定更难:智能体无法探索环境并收集额外反馈。
2.2 Transformers
2.2 Transformer
Transformers were proposed by Vaswani et al. 2017 as an architecture to efficiently model sequential data. These models consist of stacked self-attention layers with residual connections. Each self-attention layer receives embeddings corresponding to unique input tokens, and outputs embeddings , preserving the input dimensions. The -th token is mapped via linear transformations to a key , query , and value . The -th output of the self-attention layer is given by weighting the values by the normalized dot product between the query and other keys :
Transformer 由 Vaswani et al. 2017 提出,用于高效建模序列数据。模型由带残差连接的堆叠自注意力层组成。每层接收 个对应输入 token 的嵌入 ,输出同维的 个嵌入 。第 个 token 经线性变换得到键 、查询 与值 。自注意力层第 个输出由查询 与其他键 的归一化点积对值 加权得到:
As we shall see later, this allows the layer to assign “credit” by implicitly forming state-return associations via similarity of the query and key vectors (maximizing the dot product). In this work, we use the GPT architecture [9], which modifies the transformer architecture with a causal self-attention mask to enable autoregressive generation, replacing the summation/softmax over the tokens with only the previous tokens in the sequence (). We defer the other architecture details to the original papers.
后文将看到,这使该层可通过查询与键向量的相似性(最大化点积)隐式形成状态–回报关联,从而「分配信用」。本文使用 GPT 架构 [9]:用因果自注意力掩码改造 Transformer 以支持自回归生成,把对 个 token 的求和/softmax 换成仅对序列中先前 token()。其他结构细节见原论文。
3 Method
3 方法
In this section, we present Decision Transformer, which models trajectories autoregressively with minimal modification to the transformer architecture, as summarized in Figure 1 and Algorithm 1.
本节介绍 Decision Transformer:以对 Transformer 结构的最小改动自回归建模轨迹,概要见图 1 与算法 1。
Trajectory representation. The key desiderata in our choice of trajectory representation are that it should enable transformers to learn meaningful patterns and we should be able to conditionally generate actions at test time. It is nontrivial to model rewards since we would like the model to generate actions based on future desired returns, rather than past rewards. As a result, instead of feeding the rewards directly, we feed the model with the returns-to-go . This leads to the following trajectory representation which is amenable to autoregressive training and generation:
轨迹表示。 选择轨迹表示的关键诉求是:让 Transformer 能学到有意义模式,并在测试时条件生成动作。直接建模奖励并不平凡,因为我们希望模型基于未来期望回报而非过去奖励生成动作。因此不直接喂奖励,而喂回报-to-go 。由此得到适于自回归训练与生成的轨迹表示:
At test time, we can specify the desired performance (e.g. 1 for success or 0 for failure), as well as the environment starting state, as the conditioning information to initiate generation. After executing the generated action for the current state, we decrement the target return by the achieved reward and repeat until episode termination.
测试时可指定期望表现(如成功为 1、失败为 0)以及环境起始状态,作为启动生成的条件信息。对当前状态执行生成动作后,用已获奖励递减目标回报,重复直至回合结束。
Architecture. We feed the last timesteps into Decision Transformer, for a total of tokens (one for each modality: return-to-go, state, or action). To obtain token embeddings, we learn a linear layer for each modality, which projects raw inputs to the embedding dimension, followed by layer normalization [15]. For environments with visual inputs, the state is fed into a convolutional encoder instead of a linear layer. Additionally, an embedding for each timestep is learned and added to each token – note this is different than the standard positional embedding used by transformers, as one timestep corresponds to three tokens. The tokens are then processed by a GPT [9] model, which predicts future action tokens via autoregressive modeling.
结构。 我们将最近 个时间步送入 Decision Transformer,共 个 token(回报-to-go、状态、动作各一)。为得到 token 嵌入,对每个模态学习线性层,把原始输入投影到嵌入维,再接层归一化 [15]。视觉输入环境用卷积编码器替代线性层处理状态。此外为每个时间步学习嵌入并加到各 token——注意这与 Transformer 标准位置嵌入不同,因一个时间步对应三个 token。随后由 GPT [9] 处理这些 token,经自回归建模预测未来动作 token。
Training. We are given a dataset of offline trajectories. We sample minibatches of sequence length from the dataset. The prediction head corresponding to the input token is trained to predict – either with cross-entropy loss for discrete actions or mean-squared error for continuous actions – and the losses for each timestep are averaged. We did not find predicting the states or returns-to-go to improve performance, although it is easily permissible within our framework (as shown in Section 5.4) and would be an interesting study for future work.
训练。 给定离线轨迹数据集。从中采样长度 的小批量序列。对应输入 token 的预测头训练去预测 ——离散动作用交叉熵、连续动作用均方误差——并对各时间步损失取平均。我们发现预测状态或回报-to-go 并未提升表现,尽管框架内容易加入(见第 5.4 节),值得未来研究。
# R, s, a, t: returns-to-go, states, actions, or timesteps
# transformer: transformer with causal masking (GPT)
# embed_s, embed_a, embed_R: linear embedding layers
# embed_t: learned episode positional embedding
# pred_a: linear action prediction layer
# main model
def**DecisionTransformer(R,s,a,t):**
# compute embeddings for tokens
pos_embedding=embed_t(t)****# per-timestep (note: not per-token)
s_embedding**=embed_s(s)+pos_embedding
a_embedding=embed_a(a)+pos_embedding
R_embedding=embed_R(R)****+**pos_embedding
# interleave tokens as (R_1, s_1, a_1, ..., R_K, s_K)
input_embeds=stack(R_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
for(R,s,a,t)indataloader****:****# dims: (batch_size, K, dim)
a_preds=DecisionTransformer(R,s,a,t)
loss=mean((a_preds-a)2)****# L2 loss for continuous actions
optimizer.zero_grad();loss.backward();optimizer.step()**
# evaluation loop
target_return=1# for instance, expert-level return
R,s,a,t,done=[target_return],[env.reset()],[],[1],False
whilenotdone:****# autoregressive generation/sampling
# sample next action
action=DecisionTransformer(R,s,a,t)[-1]****# for cts actions
new_s,r,done,_=env.step(action)
# append new tokens to sequence
R=R+[R[-1]-r]****# decrement returns-to-go with reward
s,a,t=s+[new_s],a+[action],t+****[len(R)]
R,s,a,t=R[-K:],...# only keep context length of K
Algorithm 1 Decision Transformer Pseudocode (for continuous actions)
# R, s, a, t: returns-to-go, states, actions, or timesteps
# transformer: transformer with causal masking (GPT)
# embed_s, embed_a, embed_R: linear embedding layers
# embed_t: learned episode positional embedding
# pred_a: linear action prediction layer
# main model
def**DecisionTransformer(R,s,a,t):
# compute embeddings for tokens
pos_embedding=embed_t(t)# per-timestep (note: not per-token)
s_embedding=embed_s(s)+pos_embedding
a_embedding=embed_a(a)+pos_embedding
R_embedding=embed_R(R)****+**pos_embedding
# interleave tokens as (R_1, s_1, a_1, ..., R_K, s_K)
input_embeds=stack(R_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
for(R,s,a,t)indataloader**:**# dims: (batch_size, K, dim)
a_preds=DecisionTransformer(R,s,a,t)
loss=mean((a_preds-a)2)****# L2 loss for continuous actions
optimizer.zero_grad();loss.backward();optimizer.step()**
# evaluation loop
target_return=1# for instance, expert-level return
R,s,a,t,done=****[target_return],[env.reset()],[],[1],False
whilenotdone:# autoregressive generation/sampling
# sample next action
action=DecisionTransformer(R,s,a,t)[-1]****# for cts actions
new_s,r,done,_****=env.step(action)
# append new tokens to sequence
R=R+[R[-1]-r]****# decrement returns-to-go with reward
s,a,t=s+****[new_s],a+****[action],t+****[len(R)]
R,s,a,t=R[-K:],...# only keep context length of K
算法 1 Decision Transformer 伪代码(连续动作)
4 Evaluations on Offline RL Benchmarks
4 离线 RL 基准上的评估
In this section, we investigate the performance of Decision Transformer relative to dedicated offline RL and imitation learning algorithms. In particular, our primary points of comparison are model-free offline RL algorithms based on TD-learning, since our Decision Transformer architecture is fundamentally model-free in nature as well. Furthermore, TD-learning is the dominant paradigm in RL for sample efficiency, and also features prominently as a sub-routine in many model-based RL algorithms [16, 17]. We also compare with behavior cloning and variants, since it also involves a likelihood based policy learning formulation similar to ours. The exact algorithms depend on the environment but our motivations are as follows:
本节考察 Decision Transformer 相对专用离线 RL 与模仿学习算法的表现。主要对照是基于 TD 学习的无模型离线 RL,因为 Decision Transformer 本质上也是无模型的。TD 学习仍是样本效率上的主导范式,也是许多基于模型 RL 算法的子程序 [16, 17]。我们也与行为克隆及其变体比较,因其同样是基于似然的策略学习。具体算法随环境而变,动机如下:
- • TD learning: most of these methods use an action-space constraint or value pessimism, and will be the most faithful comparison to Decision Transformer, representing standard RL methods. A state-of-the-art model-free method is Conservative Q-Learning (CQL) [14] which serves as our primary comparison. In addition, we also compare against other prior model-free RL algorithms like BEAR [18] and BRAC [19].
- • TD 学习:这类方法大多使用动作空间约束或价值悲观,是对 Decision Transformer 最忠实的对照,代表标准 RL。当时最强无模型方法是 Conservative Q-Learning(CQL)[14],作为主要对照。另与 BEAR [18]、BRAC [19] 等先前无模型 RL 比较。
- • Imitation learning: this regime similarly uses supervised losses for training, rather than Bellman backups. We use behavior cloning here, and include a more detailed discussion in Section 5.1.
- • 模仿学习:该设定同样用监督损失训练,而非 Bellman 备份。我们使用行为克隆,并在第 5.1 节更细讨论。
We evaluate on both discrete (Atari [10]) and continuous (OpenAI Gym [11]) control tasks. The former involves high-dimensional observation spaces and requires long-term credit assignment, while the latter requires fine-grained continuous control, representing a diverse set of tasks. Our main results are summarized in Figure 3, where we show averaged normalized performance for each domain.
我们在离散(Atari [10])与连续(OpenAI Gym [11])控制任务上评估。前者观察空间高维、需要长期信用分配;后者需要细粒度连续控制,任务多样。主要结果汇总于图 3,给出各领域平均归一化表现。
Figure 3: Results comparing Decision Transformer (ours) to TD learning (CQL) and behavior cloning across Atari, OpenAI Gym, and Minigrid. On a diverse set of tasks, Decision Transformer performs comparably or better than traditional approaches. Performance is measured by normalized episode return (see text for details).
图 3:在 Atari、OpenAI Gym 与 Minigrid 上,比较 Decision Transformer(本文)、TD 学习(CQL)与行为克隆。任务多样时,Decision Transformer 与传统方法相当或更好。表现以归一化回合回报衡量(细节见正文)。
4.1 Atari
The Atari benchmark [10] is challenging due to its high-dimensional visual inputs and difficulty of credit assignment arising from the delay between actions and resulting rewards. We evaluate our method on 1% of all samples in the DQN-replay dataset as per Agarwal et al. 2020, representing 500 thousand of the 50 million transitions observed by an online DQN agent [20] during training; we report the mean and standard deviation of 3 seeds. We normalize scores based on a professional gamer, following the protocol of Hafner et al. 2020, where 100 represents the professional gamer score and 0 represents a random policy.
Atari 基准 [10] 因高维视觉输入、以及动作与奖励延迟带来的信用分配困难而具挑战。我们按 Agarwal et al. 2020,在 DQN-replay 数据集全部样本的 1% 上评估,即在线 DQN 智能体 [20] 训练期间观察到的 5000 万转移中的 50 万;报告 3 个种子的均值与标准差。分数按职业玩家归一化,遵循 Hafner et al. 2020:100 为职业玩家,0 为随机策略。
| Game | DT (Ours) | CQL | QR-DQN | REM | BC |
|---|---|---|---|---|---|
| Breakout | |||||
| Qbert | |||||
| Pong | |||||
| Seaquest |
Table 1: Gamer-normalized scores for the 1% DQN-replay Atari dataset. We report the mean and variance across 3 seeds. Best mean scores are highlighted in bold. Decision Transformer (DT) performs comparably to CQL on 3 out of 4 games, and outperforms other baselines in most games.
| 游戏 | DT(本文) | CQL | QR-DQN | REM | BC |
|---|---|---|---|---|---|
| Breakout | |||||
| Qbert | |||||
| Pong | |||||
| Seaquest |
表 1:1% DQN-replay Atari 数据集上的玩家归一化分数。报告 3 种子均值与方差。最优均值加粗。Decision Transformer(DT)在 4 款游戏中的 3 款与 CQL 相当,并在多数游戏上超过或持平其他基线。
We compare to CQL [14], REM [13], and QR-DQN [22] on four Atari tasks (Breakout, Qbert, Pong, and Seaquest) that are evaluated in Agarwal et al. 2020. We use context lengths of for Decision Transformer (except for Pong). We also report the performance of behavior cloning (BC), which utilizes the same network architecture and hyperparameters as Decision Transformer but does not have return-to-go conditioning[^2]. For CQL, REM, and QR-DQN baselines, we report numbers directly from the CQL and REM papers. We show results in Table 1. Our method is competitive with CQL in 3 out of 4 games and outperforms or matches REM, QR-DQN, and BC on all 4 games.
我们在 Agarwal et al. 2020 评估的四款 Atari 任务(Breakout、Qbert、Pong、Seaquest)上与 CQL [14]、REM [13]、QR-DQN [22] 比较。Decision Transformer 上下文长度 (Pong 为 )。也报告行为克隆(BC)表现:网络结构与超参同 Decision Transformer,但无回报-to-go 条件化[^2]。CQL、REM、QR-DQN 数字直接取自 CQL 与 REM 论文。结果见表 1。我们的方法在 4 款中的 3 款与 CQL 竞争,并在全部 4 款上超过或持平 REM、QR-DQN 与 BC。
4.2 OpenAI Gym
In this section, we consider the continuous control tasks from the D4RL benchmark [23]. We also consider a 2D reacher environment that is not part of the benchmark, and generate the datasets using a similar methodology to the D4RL benchmark. Reacher is a goal-conditioned task and has sparse rewards, so it represents a different setting than the standard locomotion environments (HalfCheetah, Hopper, and Walker). The different dataset settings are described below.
本节考虑 D4RL 基准 [23] 的连续控制任务。另考虑不在基准中的 2D reacher,并用类似 D4RL 的方法生成数据。Reacher 是目标条件任务且奖励稀疏,与标准运动环境(HalfCheetah、Hopper、Walker)设定不同。不同数据设定如下。
- Medium: 1 million timesteps generated by a “medium” policy that achieves approximately one-third the score of an expert policy.
- Medium:由达到约专家三分之一分数的「中等」策略生成的 100 万时间步。
- Medium-Replay: the replay buffer of an agent trained to the performance of a medium policy (approximately 25k-400k timesteps in our environments).
- Medium-Replay:训练到中等策略水平的智能体回放缓冲(我们环境中约 2.5 万–40 万时间步)。
- Medium-Expert: 1 million timesteps generated by the medium policy concatenated with 1 million timesteps generated by an expert policy.
- Medium-Expert:中等策略 100 万时间步与专家策略 100 万时间步拼接。
We compare to CQL [14], BEAR [18], BRAC [19], and AWR [24]. CQL represents the state-of-the-art in model-free offline RL, an instantiation of TD learning with value pessimism. Score are normalized so that 100 represents an expert policy, as per Fu et al. 2020. CQL numbers are reported from the original paper; BC numbers are run by us; and the other methods are reported from the D4RL paper. Our results are shown in Table 3. Decision Transformer achieves the highest scores in a majority of the tasks and is competitive with the state of the art in the remaining tasks.
我们与 CQL [14]、BEAR [18]、BRAC [19]、AWR [24] 比较。CQL 代表当时无模型离线 RL 前沿,是带价值悲观的 TD 学习实例。分数按 Fu et al. 2020 归一化,使 100 对应专家策略。CQL 数字取自原论文;BC 由我们运行;其余取自 D4RL 论文。结果见表 3。Decision Transformer 在多数任务取得最高分,其余任务也与当时最优竞争。
| Dataset | Environment | DT (Ours) | CQL | BEAR | BRAC-v | AWR | BC |
|---|---|---|---|---|---|---|---|
| Medium-Expert | HalfCheetah | ||||||
| Medium-Expert | Hopper | ||||||
| Medium-Expert | Walker | ||||||
| Medium-Expert | Reacher | - | - | - | |||
| Medium | HalfCheetah | ||||||
| Medium | Hopper | ||||||
| Medium | Walker | ||||||
| Medium | Reacher | - | - | - | |||
| Medium-Replay | HalfCheetah | ||||||
| Medium-Replay | Hopper | ||||||
| Medium-Replay | Walker | ||||||
| Medium-Replay | Reacher | - | - | - | |||
| Average (Without Reacher) | |||||||
| Average (All Settings) | - | - | - |
Table 2: Results for D4RL datasets[^3]. We report the mean and variance for three seeds. Decision Transformer (DT) outperforms conventional RL algorithms on almost all tasks.
| 数据集 | 环境 | DT(本文) | CQL | BEAR | BRAC-v | AWR | BC |
|---|---|---|---|---|---|---|---|
| Medium-Expert | HalfCheetah | ||||||
| Medium-Expert | Hopper | ||||||
| Medium-Expert | Walker | ||||||
| Medium-Expert | Reacher | - | - | - | |||
| Medium | HalfCheetah | ||||||
| Medium | Hopper | ||||||
| Medium | Walker | ||||||
| Medium | Reacher | - | - | - | |||
| Medium-Replay | HalfCheetah | ||||||
| Medium-Replay | Hopper | ||||||
| Medium-Replay | Walker | ||||||
| Medium-Replay | Reacher | - | - | - | |||
| 平均(不含 Reacher) | |||||||
| 平均(全部设定) | - | - | - |
表 2:D4RL 数据集结果[^3]。报告三种子均值与方差。Decision Transformer(DT)在几乎所有任务上超过常规 RL 算法。
5 Discussion
5 讨论
5.1 Does Decision Transformer perform behavior cloning on a subset of the data?
5.1 Decision Transformer 是否只是在数据子集上做行为克隆?
In this section, we seek to gain insight into whether Decision Transformer can be thought of as performing imitation learning on a subset of the data with a certain return. To investigate this, we propose a new method, Percentile Behavior Cloning (%BC), where we run behavior cloning on only the top of timesteps in the dataset, ordered by episode returns. The percentile interpolates between standard BC () that trains on the entire dataset and only cloning the best observed trajectory (), trading off between better generalization by training on more data with training a specialized model that focuses on a desirable subset of the data.
本节想弄清:Decision Transformer 是否可被理解为对具有某类回报的数据子集做模仿学习。为此提出百分位行为克隆(%BC):只对按回合回报排序后数据集中前 的时间步做行为克隆。百分位 在标准 BC()与只克隆最优观测轨迹()之间插值,权衡「用更多数据更好泛化」与「专注理想子集的专用模型」。
We show full results comparing %BC to Decision Transformer and CQL in Table 3, sweeping over . Note that the only way to choose the optimal subset for cloning is to evaluate using rollouts from the environment, so %BC is not a realistic approach; rather, it serves to provide insight into the behavior of Decision Transformer. When data is plentiful – as in the D4RL regime – we find %BC can match or beat other offline RL methods. On most environments, Decision Transformer is competitive with the performance of the best %BC, indicating it can hone in on a particular subset after training on the entire dataset distribution.
表 3 给出 %BC 与 Decision Transformer、CQL 的完整比较,。注意:选择最优克隆子集只能靠环境 rollout 评估,因此 %BC 并非现实方法,只为洞察 Decision Transformer 行为。数据充足时(如 D4RL),%BC 可匹配甚至超过其他离线 RL。多数环境上 Decision Transformer 与最佳 %BC 竞争,说明它在整集分布上训练后仍能聚焦特定子集。
| Dataset | Environment | DT (Ours) | 10%BC | 25%BC | 40%BC | 100%BC | CQL |
|---|---|---|---|---|---|---|---|
| Medium | HalfCheetah | ||||||
| Medium | Hopper | ||||||
| Medium | Walker | ||||||
| Medium | Reacher | ||||||
| Medium-Replay | HalfCheetah | ||||||
| Medium-Replay | Hopper | ||||||
| Medium-Replay | Walker | ||||||
| Medium-Replay | Reacher | ||||||
| Average |
Table 3: Comparison between Decision Transformer (DT) and Percentile Behavior Cloning (%BC).
| 数据集 | 环境 | DT(本文) | 10%BC | 25%BC | 40%BC | 100%BC | CQL |
|---|---|---|---|---|---|---|---|
| Medium | HalfCheetah | ||||||
| Medium | Hopper | ||||||
| Medium | Walker | ||||||
| Medium | Reacher | ||||||
| Medium-Replay | HalfCheetah | ||||||
| Medium-Replay | Hopper | ||||||
| Medium-Replay | Walker | ||||||
| Medium-Replay | Reacher | ||||||
| 平均 |
表 3:Decision Transformer(DT)与百分位行为克隆(%BC)比较。
In contrast, when we study low data regimes – such as Atari, where we use 1% of a replay buffer as the dataset – %BC is weak (shown in Table 4). This suggests that in scenarios with relatively low amounts of data, Decision Transformer can outperform %BC by using all trajectories in the dataset to improve generalization, even if those trajectories are dissimilar from the return conditioning target. Our results indicate that Decision Transformer can be more effective than simply performing imitation learning on a subset of the dataset. On the tasks we considered, Decision Transformer either outperforms or is competitive to %BC, without the confound of having to select the optimal subset.
相较之下,在低数据设定——如只用回放缓冲 1% 的 Atari——%BC 很弱(表 4)。说明数据相对少时,Decision Transformer 可通过使用全部轨迹改善泛化,即使这些轨迹与回报条件目标不相似,从而超过 %BC。结果表明它可比「只在数据子集上模仿」更有效。在所考虑任务上,Decision Transformer 超过或持平 %BC,且无需选择最优子集这一混淆因素。
| Game | DT (Ours) | 10%BC | 25%BC | 40%BC | 100%BC |
|---|---|---|---|---|---|
| Breakout | |||||
| Qbert | |||||
| Pong | |||||
| Seaquest |
Table 4: %BC scores for Atari. We report the mean and variance across 3 seeds. Decision Transformer (DT) outperforms all versions of %BC in most games.
| 游戏 | DT(本文) | 10%BC | 25%BC | 40%BC | 100%BC |
|---|---|---|---|---|---|
| Breakout | |||||
| Qbert | |||||
| Pong | |||||
| Seaquest |
表 4:Atari 上的 %BC 分数。报告 3 种子均值与方差。Decision Transformer(DT)在多数游戏上超过所有版本的 %BC。
5.2 How well does Decision Transformer model the distribution of returns?
5.2 Decision Transformer 对回报分布建模得如何?
We evaluate the ability of Decision Transformer to understand return-to-go tokens by varying the desired target return over a wide range – evaluating the multi-task distribution modeling capability of transformers. Figure 4 shows the average sampled return accumulated by the agent over the course of the evaluation episode for varying values of target return. On every task, the desired target returns and the true observed returns are highly correlated. On some tasks like Pong, HalfCheetah and Walker, Decision Transformer generates trajectories that almost perfectly match the desired returns (as indicated by the overlap with the oracle line). Furthermore, on some Atari tasks like Seaquest, we can prompt the Decision Transformer with higher returns than the maximum episode return available in the dataset, demonstrating that Decision Transformer is sometimes capable of extrapolation.
我们在宽范围内改变期望目标回报,评估 Decision Transformer 对回报-to-go token 的理解——检验 Transformer 的多任务分布建模能力。图 4 给出不同目标回报下,智能体在评估回合中累积的平均采样回报。每项任务上,期望目标回报与真实观测回报高度相关。Pong、HalfCheetah、Walker 等任务上,生成轨迹几乎完美匹配期望回报(与 oracle 线重合)。此外在 Seaquest 等部分 Atari 任务上,可用高于数据集最大回合回报的值提示 Decision Transformer,说明有时具备外推能力。
图 4:条件于指定目标(期望)回报时,Decision Transformer 累积的采样(评估)回报。上: Atari。下: D4RL medium-replay 数据集。
5.3 What is the benefit of using a longer context length?
5.3 更长上下文有何好处?
To assess the importance of access to previous states, actions, and returns, we ablate on the context length . This is interesting since it is generally considered that the previous state (i.e. ) is enough for reinforcement learning algorithms when frame stacking is used, as we do. Table 5 shows that performance of Decision Transformer is significantly worse when , indicating that past information is useful for Atari games. One hypothesis is that when we are representing a distribution of policies – like with sequence modeling – the context allows the transformer to identify which policy generated the actions, enabling better learning and/or improving the training dynamics.
为评估访问先前状态、动作与回报的重要性,我们对上下文长度 做消融。这很有意思:通常认为使用帧堆叠时,先前状态(即 )对强化学习算法已足够。表 5 显示 时 Decision Transformer 表现显著更差,说明 Atari 上历史信息有用。一个假说是:当用序列建模表示策略分布时,上下文让 Transformer 识别动作由何种策略生成,从而更好学习并/或改善训练动态。
| Game | DT (Ours) | DT with no context () | |
|---|---|---|---|
| Breakout | |||
| Qbert | |||
| Pong | |||
| Seaquest |
Table 5: Ablation on context length. Decision Transformer (DT) performs better when using a longer context length ( for Pong, for others).
| 游戏 | DT(本文) | 无上下文 DT() | |
|---|---|---|---|
| Breakout | |||
| Qbert | |||
| Pong | |||
| Seaquest |
表 5:上下文长度消融。使用更长上下文时 Decision Transformer(DT)更好(Pong 为 ,其余 )。
5.4 Does Decision Transformer perform effective long-term credit assignment?
5.4 Decision Transformer 能否有效做长期信用分配?
To evaluate long-term credit assignment capabilities of our model, we consider a variant of the Key-to-Door environment proposed in Mesnard et al. 2020. This is a grid-based environment with a sequence of three phases: (1) in the first phase, the agent is placed in a room with a key; (2) then, the agent is placed in an empty room; (3) and finally, the agent is placed in a room with a door. The agent receives a binary reward when reaching the door in the third phase, but only if it picked up the key in the first phase. This problem is difficult for credit assignment because credit must be propagated from the beginning to the end of the episode, skipping over actions taken in the middle.
为评估长期信用分配能力,我们采用 Mesnard et al. 2020 提出的 Key-to-Door 环境变体。这是基于网格的环境,含三阶段序列:(1)智能体被放在有钥匙的房间;(2)再放到空房间;(3)最后放到有门的房间。仅当第一阶段拾起钥匙后,第三阶段到达门才给二元奖励。该问题信用分配困难:信用须从回合开头传到末尾,并跳过中间动作。
We train on datasets of trajectories generated by applying random actions and report success rates in Table 6. Furthermore, for the Key-to-Door environment we use the entire episode length as the context, rather than having a fixed content window as in the other environments. Methods that use highsight return information: our Decision Transformer model and %BC (trained only on successful episodes) are able to learn effective policies – producing near-optimal paths, despite only training on random walks. TD learning (CQL) cannot effectively propagate Q-values over the long horizons involved and gets poor performance.
我们在随机动作生成的轨迹数据集上训练,成功率见表 6。Key-to-Door 上我们用整段回合长度作上下文,而非其他环境的固定窗口。使用后见回报信息的方法——Decision Transformer 与仅在成功回合上训练的 %BC——能学到有效策略,走出近乎最优路径,尽管只在随机游走上训练。TD 学习(CQL)无法在所涉长视野上有效传播 Q 值,表现很差。
| Dataset | DT (Ours) | CQL | BC | %BC | Random |
|---|---|---|---|---|---|
| 1K Random Trajectories | |||||
| 10K Random Trajectories |
Table 6: Success rate for Key-to-Door environment. Methods using hindsight (Decision Transformer, %BC) can learn successful policies, while TD learning struggles to perform credit assignment.
| 数据集 | DT(本文) | CQL | BC | %BC | 随机 |
|---|---|---|---|---|---|
| 1K 随机轨迹 | |||||
| 10K 随机轨迹 |
表 6:Key-to-Door 环境成功率。使用后见信息的方法(Decision Transformer、%BC)可学到成功策略,而 TD 学习难以完成信用分配。
5.5 Can transformers be accurate critics in sparse reward settings?
5.5 稀疏奖励设定下 Transformer 能否成为准确评判器?
In previous sections, we established that decision transformer can produce effective policies (actors). We now evaluate whether transformer models can also be effective critics. We modify Decision Transformer to output return tokens in addition to action tokens on the Key-to-Door environment. Additionally, the first return token is not given, but it is predicted instead (i.e. the model learns the initial distribution ), similar to standard autoregressive generative models. We find that the transformer continuously updates reward probability based on events during the episode, shown in Figure 5 (Left). Furthermore, we find the transformer attends to critical events in the episode (picking up the key or reaching the door), shown in Figure 5 (Right), indicating formation of state-reward associations as discussed in Raposo et al. 2021 and enabling accurate value prediction.
前几节表明 Decision Transformer 能产出有效策略(行动者)。现评估 Transformer 是否也能成为有效评判器。我们在 Key-to-Door 上修改 Decision Transformer,除动作 token 外还输出回报 token;且不给定第一个回报 token,而是预测它(即学习初始分布 ),类似标准自回归生成模型。我们发现 Transformer 会随回合内事件持续更新奖励概率,见图 5(左)。此外,它对回合中的关键事件(拾钥匙或到达门)给予注意力,见图 5(右),表明形成了 Raposo et al. 2021 讨论的状态–奖励关联,从而支持准确价值预测。
Figure 5: Left: Averages of running return probabilities predicted by the transformer model for three types of episode outcomes. Right: Transformer attention weights from all timesteps superimposed for a particular successful episode. The model attends to steps near pivotal events in the episode, such as picking up the key and reaching the door.
图 5:左: Transformer 对三类回合结果预测的运行回报概率均值。右: 某一成功回合上,所有时间步 Transformer 注意力权重叠加。模型关注接近关键事件的步骤,如拾起钥匙与到达门。
5.6 Does Decision Transformer perform well in sparse reward settings?
5.6 Decision Transformer 在稀疏奖励设定下表现如何?
A known weakness of TD learning algorithms is that they require densely populated rewards in order to perform well, which can be unrealistic and/or expensive. In contrast, Decision Transformer can improve robustness in these settings since it makes minimal assumptions on the density of the reward. To evaluate this, we consider a delayed return version of the D4RL benchmarks where the agent does not receive any rewards along the trajectory, and instead receives the cumulative reward of the trajectory in the final timestep. Our results for delayed returns are shown in Table 7. Delayed returns minimally affect Decision Transformer; and due to the nature of the training process, while imitation learning methods are reward agnostic. While TD learning collapses, Decision Transformer and %BC still perform well, indicating that Decision Transformer can be more robust to delayed rewards.
TD 学习算法的已知弱点是需要稠密奖励才能表现好,这往往不现实或昂贵。相较之下,Decision Transformer 对奖励密度假设很少,可提升这类设定下的稳健性。为此我们考虑 D4RL 基准的延迟回报版本:轨迹途中不给奖励,只在最后一步给整段累积奖励。延迟回报结果见表 7。延迟回报对 Decision Transformer 影响很小;训练过程本身也使模仿学习方法对奖励无关。TD 学习崩溃时,Decision Transformer 与 %BC 仍表现良好,说明前者对延迟奖励更稳健。
| Delayed (Sparse) | Agnostic | Original (Dense) | |||||
|---|---|---|---|---|---|---|---|
| Dataset | Environment | DT (Ours) | CQL | BC | %BC | DT (Ours) | CQL |
| Medium-Expert | Hopper | ||||||
| Medium | Hopper | ||||||
| Medium-Replay | Hopper |
Table 7: Results for D4RL datasets with delayed (sparse) reward. Decision Transformer (DT) and imitation learning are minimally affected by the removal of dense rewards, while CQL fails.
| 延迟(稀疏) | 无关 | 原始(稠密) | |||||
|---|---|---|---|---|---|---|---|
| 数据集 | 环境 | DT(本文) | CQL | BC | %BC | DT(本文) | CQL |
| Medium-Expert | Hopper | ||||||
| Medium | Hopper | ||||||
| Medium-Replay | Hopper |
表 7:延迟(稀疏)奖励下的 D4RL 结果。Decision Transformer(DT)与模仿学习几乎不受稠密奖励移除影响,而 CQL 失败。
5.7 Why does Decision Transformer avoid the need for value pessimism or behavior regularization?
5.7 为何 Decision Transformer 不需要价值悲观或行为正则?
One key difference between Decision Transformer and prior offline RL algorithms is that we do not require policy regularization or conservatism to achieve good performance. Our conjecture is that TD-learning based algorithms learn an approximate value function and improve the policy by optimizing this value function. This act of optimizing a learned function can exacerbate and exploit any inaccuracies in the value function approximation, causing failures in policy improvement. Since Decision Transformer does not require explicit optimization using learned functions as objectives, it avoids the need for regularization or conservatism.
Decision Transformer 与先前离线 RL 算法的一个关键差别是:我们不需要策略正则或保守性即可取得好表现。我们的猜想是:基于 TD 学习的算法学习近似价值函数,再通过优化该价值函数改进策略。优化所学函数会放大并利用价值近似中的任何误差,导致策略改进失败。Decision Transformer 不以所学函数为显式优化目标,因而回避了正则或保守的需要。
5.8 How can Decision Transformer benefit online RL regimes?
5.8 Decision Transformer 如何惠及在线 RL?
Offline RL and the ability to model behaviors has the potential to enable sample-efficient online RL for downstream tasks. Works studying the transition from offline to online generally find that likelihood-based approaches, like our sequence modeling objective, are more successful [26, 27]. As a result, although we studied offline RL in this work, we believe Decision Transformer can meaningfully improve online RL methods by serving as a strong model for behavior generation. For instance, Decision Transformer can serve as a powerful “memorization engine” and in conjunction with powerful exploration algorithms like Go-Explore [28], has the potential to simultaneously model and generative a diverse set of behaviors.
离线 RL 与行为建模能力有望使下游任务的在线 RL 更样本高效。研究离线到在线过渡的工作普遍发现,基于似然的方法——如我们的序列建模目标——更成功 [26, 27]。因此,尽管本文研究离线 RL,我们相信 Decision Transformer 可作为强行为生成模型,有意义地改进在线 RL。例如,它可充当强大的「记忆引擎」,与 Go-Explore [28] 等强探索算法结合,有望同时建模并生成多样化行为。
6 Related Work
6 相关工作
6.1 Offline reinforcement learning
6.1 离线强化学习
To mitigate the impact of distribution shift in offline RL, prior algorithms either (a) constrain the policy action space [29, 30, 31] or (b) incorporate value pessimism [29, 14], or (c) incorporate pessimism into learned dynamics models [32, 33]. Since we do not use Decision Transformers to explicitly learn the dynamics model, we primarily compare against model-free algorithms in our work; in particular, adding a dynamics model tends to improve the performance of model-free algorithms. Another line of work explores learning wide behavior distribution from an offline dataset by learning a task-agnostic set of skills, either with likelihood-based approaches [34, 35, 36, 37] or by maximizing mutual information [38, 39, 40]. Our work is similar to the likelihood-based approaches, which do not use iterative Bellman updates – although we use a simpler sequence modeling objective instead of a variational method, and use rewards for conditional generation of behaviors.
为减轻离线 RL 中的分布偏移,先前算法或(a)约束策略动作空间 [29, 30, 31],或(b)引入价值悲观 [29, 14],或(c)把悲观引入所学动力学模型 [32, 33]。因我们不用 Decision Transformer 显式学动力学,主要与无模型算法比较;加入动力学模型往往会提升无模型方法。另一路线从离线数据学习宽行为分布,用似然方法 [34, 35, 36, 37] 或最大化互信息 [38, 39, 40] 学任务无关技能集。我们的工作接近似然路线——同样不用迭代 Bellman 更新——但用更简单的序列建模目标而非变分方法,并用奖励条件化生成行为。
6.2 Supervised learning in reinforcement learning settings
6.2 强化学习设定中的监督学习
Some prior methods for reinforcement learning bear more resemblance to static supervised learning, such as Q-learning [41, 42], which still uses iterative backups, or likelihood-based methods such as behavior cloning, which do not (discussed in previous section). Recent work [43, 44, 45] studies “upside-down” reinforcement learning (UDRL), which are similar to our method in seeking to model behaviors with a supervised loss conditioned on the target return. A key difference in our work is the shift of motivation to sequence modeling rather than supervised learning: while the practical methods differ primarily in the context length and architecture, sequence modeling enables behavior modeling even without access to the reward, in a similar style to language [9] or images [46], and is known to scale well [2]. The method proposed by Kumar et al. 2019c is most similar to our method with , which we find sequence modeling/long contexts to outperform (see Section 5.3). Ghosh et al. 2019 extends prior UDRL methods to use state goal conditioning, rather than rewards, and Paster et al. 2020 further use an LSTM with state goal conditioning for goal-conditoned online RL settings.
一些强化学习先验方法更像静态监督学习,例如仍用迭代备份的 Q-learning [41, 42],或不做备份的似然方法如行为克隆(上节已讨论)。近期工作 [43, 44, 45] 研究「颠倒」强化学习(UDRL),与我们类似:用条件于目标回报的监督损失建模行为。关键差别在于动机转向序列建模而非监督学习:实践方法主要差在上下文长度与结构,但序列建模即使没有奖励也能像语言 [9] 或图像 [46] 那样建模行为,且已知可良好扩展 [2]。Kumar et al. 2019c 提出的方法最接近我们 的情形,而我们发现序列建模/长上下文更优(见第 5.3 节)。Ghosh et al. 2019 把先前 UDRL 扩展到状态目标条件化;Paster et al. 2020 进一步用带状态目标条件化的 LSTM 做目标条件在线 RL。
Concurrent to our work, Janner et al. 2021 propose Trajectory Transformer, which is similar to Decision Transformer but additionally uses state and return prediction, as well as discretization, which incorporates model-based components. We believe that their experiments, in addition to our results, highlight the potential for sequence modeling to be a generally applicable idea for reinforcement learning.
与我们同期,Janner et al. 2021 提出 Trajectory Transformer,与 Decision Transformer 类似,但额外使用状态与回报预测以及离散化,引入基于模型的成分。我们相信他们的实验加上我们的结果,共同凸显序列建模作为强化学习一般思路的潜力。
6.3 Credit assignment
6.3 信用分配
Many works have studied better credit assignment via state-association, learning an architecture which decomposes the reward function such that certain “important” states comprise most of the credit [50, 51, 12]. They use the learned reward function to change the reward of an actor-critic algorithm to help propagate signal over long horizons. In particular, similar to our long-term setting, some works have specifically shown such state-associative architectures can perform better in delayed reward settings [52, 7, 53, 25]. In contrast, we allow these properties to naturally emerge in a transformer architecture, without having to explicitly learn a reward function or a critic.
许多工作通过状态关联研究更好的信用分配:学习分解奖励函数的结构,使某些「重要」状态占据大部分信用 [50, 51, 12]。它们用所学奖励函数改变 actor-critic 的奖励,以帮助长视野传播信号。与我们的长期设定类似,一些工作专门表明此类状态关联结构在延迟奖励设定下更好 [52, 7, 53, 25]。相较之下,我们让这些性质在 Transformer 结构中自然涌现,而无需显式学习奖励函数或评判器。
6.4 Conditional language generation
6.4 条件语言生成
Various works have studied guided generation for images [54] and language [55, 56]. Several works [57, 58, 59, 60, 61, 62] have explored training or fine-tuning of models for controllable text generation. Class-conditional language models can also be used to learn disciminators to guide generation [63, 55, 64, 65]. However, these approaches mostly assume constant “classes”, while in reinforcement learning the reward signal is time-varying. Furthermore, it is more natural to prompt the model desired target return and continuously decrease it by the observed rewards over time, since the transformer model and environment jointly generate the trajectory.
多篇工作研究图像 [54] 与语言 [55, 56] 的引导生成。若干工作 [57, 58, 59, 60, 61, 62] 探索为可控文本生成训练或微调模型。类条件语言模型也可学习判别器来引导生成 [63, 55, 64, 65]。但这些方法大多假设恒定「类别」,而强化学习中奖励信号随时间变化。此外,更自然的是用期望目标回报提示模型,并随时间用观测奖励不断递减——因为轨迹由 Transformer 与环境共同生成。
6.5 Attention and transformer models
6.5 注意力与 Transformer 模型
Transformers [1] have been applied successfully to many tasks in natural language processing [66, 9] and computer vision [67, 68]. However, transformers are relatively unstudied in RL, mostly due to differing nature of the problem, such as higher variance in training. Zambaldi et al. 2018 showed that augmenting transformers with relational reasoning improve performance in combinatorial environments and Ritter et al. 2020 showed iterative self-attention allowed for RL agents to better utilize episodic memories. Parisotto et al. 2020 discussed design decisions for more stable training of transformers in the high-variance RL setting. Unlike our work, these still use actor-critic algorithms for optimization, focusing on novelty in architecture. Additionally, in imitation learning, some works have studied transformers as a replacement for LSTMs: Dasari and Gupta 2020 study one-shot imitation learning, and Abramson et al. 2020 combine language and image modalities for text-conditioned behavior generation.
Transformer [1] 已成功用于自然语言处理 [66, 9] 与计算机视觉 [67, 68] 的多项任务。但在 RL 中研究相对较少,多因问题性质不同,例如训练方差更高。Zambaldi et al. 2018 表明用关系推理增强 Transformer 可提升组合环境表现;Ritter et al. 2020 表明迭代自注意力让 RL 智能体更好利用情景记忆。Parisotto et al. 2020 讨论了在高方差 RL 设定下更稳定训练 Transformer 的设计选择。与我们不同,这些工作仍用 actor-critic 优化,创新在结构。此外在模仿学习中,有工作把 Transformer 当作 LSTM 替代:Dasari and Gupta 2020 研究一次性模仿学习;Abramson et al. 2020 结合语言与图像模态做文本条件行为生成。
7 Conclusion
7 结论
We proposed Decision Transformer, seeking to unify ideas in language/sequence modeling and reinforcement learning. On standard offline RL benchmarks, we showed Decision Transformer can match or outperform strong algorithms designed explicitly for offline RL with minimal modifications from standard language modeling architectures.
我们提出 Decision Transformer,旨在统一语言/序列建模与强化学习的思路。在标准离线 RL 基准上,它以相对标准语言建模结构的最小改动,即可匹配或超过专为离线 RL 设计的强算法。
We hope this work inspires more investigation into using large transformer models for RL. We used a simple supervised loss that was effective in our experiments, but applications to large-scale datasets could benefit from self-supervised pretraining tasks. In addition, one could consider more sophisticated embeddings for returns, states, and actions – for instance, conditioning on return distributions to model stochastic settings instead of deterministic returns. Transformer models can also be used to model the state evolution of trajectory, potentially serving as an alternative to model-based RL, and we hope to explore this in future work.
希望本文激发更多用大型 Transformer 做 RL 的研究。我们使用在实验中有效的简单监督损失,但面向大规模数据的应用或可受益于自监督预训练任务。此外可考虑更精细的回报、状态与动作嵌入——例如条件于回报分布以建模随机设定,而非确定性回报。Transformer 也可建模轨迹的状态演化,有望作为基于模型 RL 的替代,我们希望在未来工作中探索。
For real-world applications, it is important to understand the types of errors transformers make in MDP settings and possible negative consequences, which are underexplored. It will also be important to consider the datasets we train models on, which can potentially add destructive biases, particularly as we consider studying augmenting RL agents with more data which may come from questionable sources. For instance, reward design by nefarious actors can potentially generate unintended behaviors as our model generates behaviors by conditioning on desired returns.
面向真实世界应用,需要理解 Transformer 在 MDP 设定中会犯何种错误及可能负面后果,这方面仍探索不足。同样重要的是审视训练数据:它们可能引入破坏性偏见,尤其当我们研究用更多可能来源可疑的数据增强 RL 智能体时。例如,恶意行为者设计的奖励可能产生非预期行为,因为我们的模型通过条件于期望回报生成行为。
Acknowledgements
致谢
This research was supported by Berkeley Deep Drive, Open Philanthropy, and the National Science Foundation under NSF:NRI #2024675. Part of this work was completed when Aravind Rajeswaran was a PhD student at the University of Washington, where he was supported by the J.P. Morgan PhD Fellowship in AI (2020-21). We also thank Luke Metz and Daniel Freeman for valuable feedback and discussions, as well as Justin Fu for assistance in setting up D4RL benchmarks, and Aviral Kumar for assistance with the CQL baselines and hyperparameters.
本研究得到 Berkeley Deep Drive、Open Philanthropy,以及国家科学基金会 NSF:NRI #2024675 的支持。部分工作完成于 Aravind Rajeswaran 在华盛顿大学攻读博士期间,当时他获 J.P. Morgan AI 博士奖学金(2020-21)支持。我们也感谢 Luke Metz 与 Daniel Freeman 的宝贵反馈与讨论,Justin Fu 协助搭建 D4RL 基准,以及 Aviral Kumar 协助 CQL 基线与超参。
References
参考文献
Vaswani et al. [2017] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems , 2017.
Brown et al. [2020] Tom B Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, et al. Language models are few-shot learners. arXiv preprint arXiv:2005.14165 , 2020.
Ramesh et al. [2021] Aditya Ramesh, Mikhail Pavlov, Gabriel Goh, Scott Gray, Chelsea Voss, Alec Radford, Mark Chen, and Ilya Sutskever. Zero-shot text-to-image generation. arXiv preprint arXiv:2102.12092 , 2021.
Parisotto et al. [2020] Emilio Parisotto, Francis Song, Jack Rae, Razvan Pascanu, Caglar Gulcehre, Siddhant Jayakumar, Max Jaderberg, Raphael Lopez Kaufman, Aidan Clark, Seb Noury, et al. Stabilizing transformers for reinforcement learning. In International Conference on Machine Learning , 2020.
Zambaldi et al. [2018] Vinicius Zambaldi, David Raposo, Adam Santoro, Victor Bapst, Yujia Li, Igor Babuschkin, Karl Tuyls, David Reichert, Timothy Lillicrap, Edward Lockhart, et al. Deep reinforcement learning with relational inductive biases. In International Conference on Learning Representations , 2018.
Sutton and Barto [2018] Richard S Sutton and Andrew G Barto. Reinforcement learning: An introduction . MIT Press, 2018.
Hung et al. [2019] Chia-Chun Hung, Timothy Lillicrap, Josh Abramson, Yan Wu, Mehdi Mirza, Federico Carnevale, Arun Ahuja, and Greg Wayne. Optimizing agent behavior over long time scales by transporting value. Nature communications , 10(1):1–12, 2019.
Levine et al. [2020] Sergey Levine, Aviral Kumar, George Tucker, and Justin Fu. Offline reinforcement learning: Tutorial, review, and perspectives on open problems. arXiv preprint arXiv:2005.01643 , 2020.
Radford et al. [2018] Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. Improving language understanding by generative pre-training. 2018.
Bellemare et al. [2013] Marc G Bellemare, Yavar Naddaf, Joel Veness, and Michael Bowling. The arcade learning environment: An evaluation platform for general agents. Journal of Artificial Intelligence Research , 47:253–279, 2013.
Brockman et al. [2016] Greg Brockman, Vicki Cheung, Ludwig Pettersson, Jonas Schneider, John Schulman, Jie Tang, and Wojciech Zaremba. Openai gym. arXiv preprint arXiv:1606.01540 , 2016.
Mesnard et al. [2020] Thomas Mesnard, Théophane Weber, Fabio Viola, Shantanu Thakoor, Alaa Saade, Anna Harutyunyan, Will Dabney, Tom Stepleton, Nicolas Heess, Arthur Guez, et al. Counterfactual credit assignment in model-free reinforcement learning. arXiv preprint arXiv:2011.09464 , 2020.
Agarwal et al. [2020] Rishabh Agarwal, Dale Schuurmans, and Mohammad Norouzi. An optimistic perspective on offline reinforcement learning. In International Conference on Machine Learning , 2020.
Kumar et al. [2020] Aviral Kumar, Aurick Zhou, George Tucker, and Sergey Levine. Conservative q-learning for offline reinforcement learning. In Advances in Neural Information Processing Systems , 2020.
Ba et al. [2016] Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton. Layer normalization. arXiv preprint arXiv:1607.06450 , 2016.
Sutton [1990] Richard S. Sutton. Integrated architectures for learning, planning, and reacting based on approximating dynamic programming. In ICML , 1990.
Janner et al. [2019] Michael Janner, Justin Fu, Marvin Zhang, and Sergey Levine. When to trust your model: Model-based policy optimization. In Advances in Neural Information Processing Systems , pages 12498–12509, 2019.
Kumar et al. [2019a] Aviral Kumar, Justin Fu, George Tucker, and Sergey Levine. Stabilizing off-policy q-learning via bootstrapping error reduction. arXiv preprint arXiv:1906.00949 , 2019a.
Wu et al. [2019] Yifan Wu, George Tucker, and Ofir Nachum. Behavior regularized offline reinforcement learning. arXiv preprint arXiv:1911.11361 , 2019.
Mnih et al. [2015] Volodymyr Mnih, Koray Kavukcuoglu, David Silver, Andrei A Rusu, Joel Veness, Marc G Bellemare, Alex Graves, Martin Riedmiller, Andreas K Fidjeland, Georg Ostrovski, et al. Human-level control through deep reinforcement learning. nature , 518(7540):529–533, 2015.
Hafner et al. [2020] Danijar Hafner, Timothy Lillicrap, Mohammad Norouzi, and Jimmy Ba. Mastering atari with discrete world models. arXiv preprint arXiv:2010.02193 , 2020.
Dabney et al. [2018] Will Dabney, Mark Rowland, Marc Bellemare, and Rémi Munos. Distributional reinforcement learning with quantile regression. In Conference on Artificial Intelligence , 2018.
Fu et al. [2020] Justin Fu, Aviral Kumar, Ofir Nachum, George Tucker, and Sergey Levine. D4rl: Datasets for deep data-driven reinforcement learning. arXiv preprint arXiv:2004.07219 , 2020.
Peng et al. [2019] Xue Bin Peng, Aviral Kumar, Grace Zhang, and Sergey Levine. Advantage-weighted regression: Simple and scalable off-policy reinforcement learning. arXiv preprint arXiv:1910.00177 , 2019.
Raposo et al. [2021] David Raposo, Sam Ritter, Adam Santoro, Greg Wayne, Theophane Weber, Matt Botvinick, Hado van Hasselt, and Francis Song. Synthetic returns for long-term credit assignment. arXiv preprint arXiv:2102.12425 , 2021.
Gao et al. [2018] Yang Gao, Huazhe Xu, Ji Lin, Fisher Yu, Sergey Levine, and Trevor Darrell. Reinforcement learning from imperfect demonstrations. arXiv preprint arXiv:1802.05313 , 2018.
Nair et al. [2020] Ashvin Nair, Murtaza Dalal, Abhishek Gupta, and Sergey Levine. Accelerating online reinforcement learning with offline datasets. arXiv preprint arXiv:2006.09359 , 2020.
Ecoffet et al. [2019] Adrien Ecoffet, Joost Huizinga, Joel Lehman, Kenneth O Stanley, and Jeff Clune. Go-explore: a new approach for hard-exploration problems. arXiv preprint arXiv:1901.10995 , 2019.
Fujimoto et al. [2019] Scott Fujimoto, David Meger, and Doina Precup. Off-policy deep reinforcement learning without exploration. In International Conference on Machine Learning , 2019.
Kumar et al. [2019b] Aviral Kumar, Justin Fu, Matthew Soh, George Tucker, and Sergey Levine. Stabilizing off-policy q-learning via bootstrapping error reduction. In Advances in Neural Information Processing Systems , 2019b.
Siegel et al. [2020] Noah Y Siegel, Jost Tobias Springenberg, Felix Berkenkamp, Abbas Abdolmaleki, Michael Neunert, Thomas Lampe, Roland Hafner, and Martin Riedmiller. Keep doing what worked: Behavioral modelling priors for offline reinforcement learning. In International Conference on Learning Representations , 2020.
Kidambi et al. [2020] Rahul Kidambi, Aravind Rajeswaran, Praneeth Netrapalli, and Thorsten Joachims. Morel: Model-based offline reinforcement learning. In Advances in Neural Information Processing Systems , 2020.
Yu et al. [2020] Tianhe Yu, Garrett Thomas, Lantao Yu, Stefano Ermon, James Zou, Sergey Levine, Chelsea Finn, and Tengyu Ma. Mopo: Model-based offline policy optimization. In Advances in Neural Information Processing Systems , 2020.
Ajay et al. [2020] Anurag Ajay, Aviral Kumar, Pulkit Agrawal, Sergey Levine, and Ofir Nachum. Opal: Offline primitive discovery for accelerating offline reinforcement learning. arXiv preprint arXiv:2010.13611 , 2020.
Campos et al. [2020] Víctor Campos, Alexander Trott, Caiming Xiong, Richard Socher, Xavier Giro-i Nieto, and Jordi Torres. Explore, discover and learn: Unsupervised discovery of state-covering skills. In International Conference on Machine Learning , 2020.
Pertsch et al. [2020] Karl Pertsch, Youngwoon Lee, and Joseph J Lim. Accelerating reinforcement learning with learned skill priors. arXiv preprint arXiv:2010.11944 , 2020.
Singh et al. [2021] Avi Singh, Huihan Liu, Gaoyue Zhou, Albert Yu, Nicholas Rhinehart, and Sergey Levine. Parrot: Data-driven behavioral priors for reinforcement learning. In International Conference on Learning Representations , 2021.
Eysenbach et al. [2019] Benjamin Eysenbach, Abhishek Gupta, Julian Ibarz, and Sergey Levine. Diversity is all you need: Learning skills without a reward function. In International Conference on Learning Representations , 2019.
Lu et al. [2020] Kevin Lu, Aditya Grover, Pieter Abbeel, and Igor Mordatch. Reset-free lifelong learning with skill-space planning. arXiv preprint arXiv:2012.03548 , 2020.
Sharma et al. [2020] Archit Sharma, Shixiang Gu, Sergey Levine, Vikash Kumar, and Karol Hausman. Dynamics-aware unsupervised discovery of skills. In International Conference on Learning Representations , 2020.
Watkins [1989] Christopher Watkins. Learning from delayed rewards. 01 1989.
Mnih et al. [2013] Volodymyr Mnih, Koray Kavukcuoglu, David Silver, Alex Graves, Ioannis Antonoglou, Daan Wierstra, and Martin Riedmiller. Playing atari with deep reinforcement learning. arXiv preprint arXiv:1312.5602 , 2013.
Srivastava et al. [2019] Rupesh Kumar Srivastava, Pranav Shyam, Filipe Mutz, Wojciech Jaśkowski, and Jürgen Schmidhuber. Training agents using upside-down reinforcement learning. arXiv preprint arXiv:1912.02877 , 2019.
Kumar et al. [2019c] Aviral Kumar, Xue Bin Peng, and Sergey Levine. Reward-conditioned policies. arXiv preprint arXiv:1912.13465 , 2019c.
ogm [2019] Acting without rewards. 2019. URL https://ogma.ai/2019/08/acting-without-rewards/ .
Chen et al. [2020] Mark Chen, Alec Radford, Rewon Child, Jeffrey Wu, Heewoo Jun, David Luan, and Ilya Sutskever. Generative pretraining from pixels. In International Conference on Machine Learning , pages 1691–1703. PMLR, 2020.
Ghosh et al. [2019] Dibya Ghosh, Abhishek Gupta, Justin Fu, Ashwin Reddy, Coline Devin, Benjamin Eysenbach, and Sergey Levine. Learning to reach goals without reinforcement learning. arXiv preprint arXiv:1912.06088 , 2019.
Paster et al. [2020] Keiran Paster, Sheila A McIlraith, and Jimmy Ba. Planning from pixels using inverse dynamics models. arXiv preprint arXiv:2012.02419 , 2020.
Janner et al. [2021] Michael Janner, Qiyang Li, and Sergey Levine. Reinforcement learning as one big sequence modeling problem. arXiv preprint arXiv:2106.02039 , 2021.
Ferret et al. [2019] Johan Ferret, Raphaël Marinier, Matthieu Geist, and Olivier Pietquin. Self-attentional credit assignment for transfer in reinforcement learning. arXiv preprint arXiv:1907.08027 , 2019.
Harutyunyan et al. [2019] Anna Harutyunyan, Will Dabney, Thomas Mesnard, Mohammad Azar, Bilal Piot, Nicolas Heess, Hado van Hasselt, Greg Wayne, Satinder Singh, Doina Precup, et al. Hindsight credit assignment. arXiv preprint arXiv:1912.02503 , 2019.
Arjona-Medina et al. [2018] Jose A Arjona-Medina, Michael Gillhofer, Michael Widrich, Thomas Unterthiner, Johannes Brandstetter, and Sepp Hochreiter. Rudder: Return decomposition for delayed rewards. arXiv preprint arXiv:1806.07857 , 2018.
Liu et al. [2019] Yang Liu, Yunan Luo, Yuanyi Zhong, Xi Chen, Qiang Liu, and Jian Peng. Sequence modeling of temporal credit assignment for episodic reinforcement learning. arXiv preprint arXiv:1905.13420 , 2019.
Karras et al. [2019] Tero Karras, Samuli Laine, and Timo Aila. A style-based generator architecture for generative adversarial networks. In Conference on Computer Vision and Pattern Recognition , 2019.
Ghazvininejad et al. [2017] Marjan Ghazvininejad, Xing Shi, Jay Priyadarshi, and Kevin Knight. Hafez: an interactive poetry generation system. In Proceedings of ACL, System Demonstrations , 2017.
Weng [2021] Lilian Weng. Controllable neural text generation. lilianweng.github.io/lil-log , 2021. URL https://lilianweng.github.io/lil-log/2021/01/02/controllable-neural-text-generation.html .
Ficler and Goldberg [2017] Jessica Ficler and Yoav Goldberg. Controlling linguistic style aspects in neural language generation. arXiv preprint arXiv:1707.02633 , 2017.
Hu et al. [2017] Zhiting Hu, Zichao Yang, Xiaodan Liang, Ruslan Salakhutdinov, and Eric P Xing. Toward controlled generation of text. In International Conference on Machine Learning , 2017.
Rajani et al. [2019] Nazneen Fatema Rajani, Bryan McCann, Caiming Xiong, and Richard Socher. Explain yourself! leveraging language models for commonsense reasoning. arXiv preprint arXiv:1906.02361 , 2019.
Yu et al. [2017] Lantao Yu, Weinan Zhang, Jun Wang, and Yong Yu. Seqgan: Sequence generative adversarial nets with policy gradient. In AAAI conference on artificial intelligence , 2017.
Ziegler et al. [2019] Daniel M Ziegler, Nisan Stiennon, Jeffrey Wu, Tom B Brown, Alec Radford, Dario Amodei, Paul Christiano, and Geoffrey Irving. Fine-tuning language models from human preferences. arXiv preprint arXiv:1909.08593 , 2019.
Keskar et al. [2019] Nitish Shirish Keskar, Bryan McCann, Lav R Varshney, Caiming Xiong, and Richard Socher. Ctrl: A conditional transformer language model for controllable generation. arXiv preprint arXiv:1909.05858 , 2019.
Dathathri et al. [2019] Sumanth Dathathri, Andrea Madotto, Janice Lan, Jane Hung, Eric Frank, Piero Molino, Jason Yosinski, and Rosanne Liu. Plug and play language models: A simple approach to controlled text generation. arXiv preprint arXiv:1912.02164 , 2019.
Holtzman et al. [2018] Ari Holtzman, Jan Buys, Maxwell Forbes, Antoine Bosselut, David Golub, and Yejin Choi. Learning to write with cooperative discriminators. arXiv preprint arXiv:1805.06087 , 2018.
Krause et al. [2020] Ben Krause, Akhilesh Deepak Gotmare, Bryan McCann, Nitish Shirish Keskar, Shafiq Joty, Richard Socher, and Nazneen Fatema Rajani. Gedi: Generative discriminator guided sequence generation. arXiv preprint arXiv:2009.06367 , 2020.
Devlin et al. [2018] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805 , 2018.
Carion et al. [2020] Nicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, and Sergey Zagoruyko. End-to-end object detection with transformers. In European Conference on Computer Vision , 2020.
Dosovitskiy et al. [2020] Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. arXiv preprint arXiv:2010.11929 , 2020.
Ritter et al. [2020] Sam Ritter, Ryan Faulkner, Laurent Sartran, Adam Santoro, Matt Botvinick, and David Raposo. Rapid task-solving in novel environments. arXiv preprint arXiv:2006.03662 , 2020.
Dasari and Gupta [2020] Sudeep Dasari and Abhinav Gupta. Transformers for one-shot visual imitation. arXiv preprint arXiv:2011.05970 , 2020.
Abramson et al. [2020] Josh Abramson, Arun Ahuja, Iain Barr, Arthur Brussee, Federico Carnevale, Mary Cassin, Rachita Chhaparia, Stephen Clark, Bogdan Damoc, Andrew Dudzik, et al. Imitating interactive intelligence. arXiv preprint arXiv:2012.05672 , 2020.
Wolf et al. [2020] Thomas Wolf, Julien Chaumond, Lysandre Debut, Victor Sanh, Clement Delangue, Anthony Moi, Pierric Cistac, Morgan Funtowicz, Joe Davison, Sam Shleifer, et al. Transformers: State-of-the-art natural language processing. In Conference on Empirical Methods in Natural Language Processing: System Demonstrations , 2020.
Loshchilov and Hutter [2017] Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization. arXiv preprint arXiv:1711.05101 , 2017.
Appendix A Experimental Details
附录 A 实验细节
Code for experiments can be found in the supplementary material.
实验代码见补充材料。
A.1 Atari
We build our Decision Transformer implementation for Atari games off of minGPT (https://github.com/karpathy/minGPT), a publicly available re-implementation of GPT. We use most of the default hyperparameters from their character-level GPT example (https://github.com/karpathy/minGPT/blob/master/play_char.ipynb). We reduce the batch size (except in Pong), block size, number of layers, attention heads, and embedding dimension for faster training. For processing the observations, we use the DQN encoder from Mnih et al. 2015 with an additional linear layer to project to the embedding dimension.
Atari 上的 Decision Transformer 实现基于公开的 GPT 复现 minGPT(https://github.com/karpathy/minGPT)。多数超参取自其字符级 GPT 示例(https://github.com/karpathy/minGPT/blob/master/play_char.ipynb)。为加快训练,我们减小 batch size(Pong 除外)、block size、层数、注意力头数与嵌入维。观察处理使用 Mnih et al. 2015 的 DQN 编码器,再加线性层投影到嵌入维。
For return-to-go conditioning, we use either or the maximum return in the dataset, but more possibilities exist for principled return-to-go conditioning. In Atari experiments, we use Tanh instead of LayerNorm (as described in Section 3) after embedding each modality, but did this does not make a significant difference in performance. The full list of hyperparameters can be found in Table 8.
回报-to-go 条件化使用数据集最大回报的 或 ,也存在更原则的条件化选择。Atari 实验中,各模态嵌入后用 Tanh 而非第 3 节所述 LayerNorm,但对表现无显著影响。完整超参见表 8。
| Hyperparameter | Value |
|---|---|
| Number of layers | |
| Number of attention heads | |
| Embedding dimension | |
| Batch size | Pong |
| Breakout, Qbert, Seaquest | |
| Context length | Pong |
| Breakout, Qbert, Seaquest | |
| Return-to-go conditioning | Breakout ( max in dataset) |
| Qbert ( max in dataset) | |
| Pong ( max in dataset) | |
| Seaquest ( max in dataset) | |
| Nonlinearity | ReLU, encoder |
| GeLU, otherwise | |
| Encoder channels | |
| Encoder filter sizes | |
| Encoder strides | |
| Max epochs | |
| Dropout | |
| Learning rate | |
| Adam betas | |
| Grad norm clip | |
| Weight decay | |
| Learning rate decay | Linear warmup and cosine decay (see code for details) |
| Warmup tokens | |
| Final tokens |
Table 8: Hyperparameters of DT (and %BC) for Atari experiments.
| 超参数 | 取值 |
|---|---|
| 层数 | |
| 注意力头数 | |
| 嵌入维 | |
| Batch size | Pong |
| Breakout, Qbert, Seaquest | |
| 上下文长度 | Pong |
| Breakout, Qbert, Seaquest | |
| 回报-to-go 条件化 | Breakout(约数据集最大的 ) |
| Qbert(约数据集最大的 ) | |
| Pong(约数据集最大的 ) | |
| Seaquest(约数据集最大的 ) | |
| 非线性 | ReLU,编码器 |
| GeLU,其余 | |
| 编码器通道 | |
| 编码器滤波器尺寸 | |
| 编码器步长 | |
| 最大 epoch | |
| Dropout | |
| 学习率 | |
| Adam betas | |
| 梯度范数裁剪 | |
| 权重衰减 | |
| 学习率衰减 | 线性预热与余弦衰减(细节见代码) |
| Warmup tokens | |
| Final tokens |
表 8:Atari 实验中 DT(及 %BC)的超参数。
A.2 OpenAI Gym
A.2.1 Decision Transformer
Our code is based on the Huggingface Transformers library [72]. Our hyperparameters on all OpenAI Gym tasks are shown below in Table 9. Heuristically, we find using larger models helps to model the distribution of returns, compared to standard RL model sizes (which learn one policy). For reacher we use a smaller context length than the other environments, which we find to be helpful as the environment is goal-conditioned and the episodes are shorter. We choose return targets based on expert performance for each environment, except for HalfCheetah where we find 50% performance to be better due to the datasets containing lower relative returns to the other environments. Models were trained for gradient steps using the AdamW optimizer [73] following PyTorch defaults.
A.2.1 Decision Transformer
代码基于 Huggingface Transformers 库 [72]。所有 OpenAI Gym 任务超参见表 9。经验上,相对标准 RL 模型尺寸(学单一策略),更大模型更有助于建模回报分布。Reacher 使用比其他环境更短的上下文,因其目标条件且回合更短。各环境回报目标按专家表现选取,HalfCheetah 除外:因该数据集相对回报较低,我们发现 50% 表现更好。模型用 AdamW [73]、按 PyTorch 默认训练 梯度步。
| Hyperparameter | Value |
|---|---|
| Number of layers | |
| Number of attention heads | |
| Embedding dimension | |
| Nonlinearity function | ReLU |
| Batch size | |
| Context length | HalfCheetah, Hopper, Walker |
| Reacher | |
| Return-to-go conditioning | HalfCheetah |
| Hopper | |
| Walker | |
| Reacher | |
| Dropout | |
| Learning rate | |
| Grad norm clip | |
| Weight decay | |
| Learning rate decay | Linear warmup for first training steps |
Table 9: Hyperparameters of Decision Transformer for OpenAI Gym experiments.
| 超参数 | 取值 |
|---|---|
| 层数 | |
| 注意力头数 | |
| 嵌入维 | |
| 非线性 | ReLU |
| Batch size | |
| 上下文长度 | HalfCheetah, Hopper, Walker |
| Reacher | |
| 回报-to-go 条件化 | HalfCheetah |
| Hopper | |
| Walker | |
| Reacher | |
| Dropout | |
| 学习率 | |
| 梯度范数裁剪 | |
| 权重衰减 | |
| 学习率衰减 | 前 训练步线性预热 |
表 9:OpenAI Gym 实验中 Decision Transformer 的超参数。
A.2.2 Behavior Cloning
As briefly mentioned in Section 4.2, we found previously reported behavior cloning baselines to be weak, and so run them ourselves using a similar setup as Decision Transformer. We tried using a transformer architecture, but found using an MLP (as in previous work) to be stronger. We train for gradient steps; training more did not improve performance. Other hyperparameters are shown in Table 10. The percentile behavior cloning experiments use the same hyperparameters.
A.2.2 行为克隆
如第 4.2 节简述,我们发现先前报告的行为克隆基线偏弱,因而用与 Decision Transformer 类似的设定自行运行。试过 Transformer 结构,但发现(与先前工作一样)MLP 更强。训练 梯度步;再训更久无提升。其他超参见表 10。百分位行为克隆实验使用相同超参。
| Hyperparameter | Value |
|---|---|
| Number of layers | |
| Embedding dimension | |
| Nonlinearity function | ReLU |
| Batch size | |
| Dropout | |
| Learning rate | |
| Weight decay | |
| Learning rate decay | Linear warmup for first training steps |
Table 10: Hyperparameters of Behavior Cloning for OpenAI Gym experiments.
| 超参数 | 取值 |
|---|---|
| 层数 | |
| 嵌入维 | |
| 非线性 | ReLU |
| Batch size | |
| Dropout | |
| 学习率 | |
| 权重衰减 | |
| 学习率衰减 | 前 训练步线性预热 |
表 10:OpenAI Gym 实验中行为克隆的超参数。
A.3 Graph Shortest Path
A.3 图最短路
We give details of the illustrative example discussed in the introduction. The task is to find the shortest path on a fixed directed graph, which can be formulated as an MDP where reward is when the agent is at the goal node and otherwise. The observation is the integer index of the graph node the agent is in. The action is the integer index of the graph node to move to next. The transition dynamics transport the agent to the action’s node index if there is an edge in the graph, while the agent remains at the past node otherwise. The returns-to-go in this problem correspond to negative path lengths and maximizing them corresponds to generating shortest paths.
下面给出引言中示意例子的细节。任务是在固定有向图上找最短路,可写成 MDP:智能体在目标节点奖励为 ,否则为 。观察是智能体所在图节点的整数下标。动作是下一步要去的节点整数下标。若图中有边,转移把智能体送到动作节点;否则留在原节点。该问题中回报-to-go 对应负路径长度,最大化它们等价于生成最短路。
In this environment, we use the GPT model as described in Section 3 to generate both actions and return-to-go tokens. This makes it possible for the model it generate its own (realizable) returns-to-go . Since we require a return prompt to generate actions and we do assume knowledge of the optimal path length upfront, we use a simple prior over returns that favors shorter paths: , where is the maximum trajectory length. Then, it is combined with the return probabilities generated by the GPT model: . Note that the prior and return-to-go predictions are entirely computable by the model, and thus avoids the need for any external or oracle information like the optimal path length. Adjustment of generation by a prior has also been used for similar purposes in controllable text generation in prior work [65].
本环境中,我们用第 3 节所述 GPT 同时生成动作与回报-to-go token,使模型能生成自身(可实现的)回报-to-go 。因生成动作需要回报提示,且我们不预先知道最优路径长度,对回报使用偏好更短路的简单先验:,其中 为最大轨迹长度。再与 GPT 生成的回报概率相乘:。注意先验与回报-to-go 预测完全可由模型计算,因而无需最优路径长度等外部或 oracle 信息。用先验调节生成在可控文本生成中也有类似用途 [65]。
We train on a dataset of graph random walk trajectories of steps each with a random graph of nodes and edge sparsity coefficient of . We report the results in Figure 6, where we find that transformer model is able to significantly improve upon the number of steps required to reach the goal, closely matching performance of optimal paths.
我们在 20 节点、边稀疏系数 0.1 的随机图上,用各 步的 条图随机游走轨迹训练。结果见图 6:Transformer 显著减少到达目标所需步数,接近最优路径表现。
图 6:图上随机游走、到目标的最短可能路径,以及 Transformer 尝试生成的最短路径到达目标节点所需步数的直方图。 表示轨迹中未到达目标。
There are two reasons for the favorable performance on this task. In one case, the training dataset of random walk trajectories may contain a segment that directly corresponds to the desired shortest path, in which case it will be generated by the model. In the second case, generated paths are entirely original and are not subsets of trajectories in the training dataset - they are generated from stitching sub-optimal segments. We find this case accounts for of generated paths in the experiment.
该任务表现良好有两个原因。其一,随机游走训练数据可能包含直接对应期望最短路的片段,此时模型会生成它。其二,生成路径完全原创,不是训练轨迹的子集——由次优片段拼接而成。实验中这种情况占生成路径的 。
While this is a simple example and uses a prior on generation that we do not use in other experiments for simplicity, it illustrates how hindsight return information can be used with generation priors to avoid the need for explicit dynamic programming.
虽是简单例子,且为简洁在其他实验未使用生成先验,但它说明:后见回报信息配合生成先验,可避免显式动态规划。
Appendix B Atari Task Scores
附录 B Atari 任务分数
Table 11 shows the normalized scores used for normalization used in Hafner et al. 2020. Tables 12 and 13 show the raw scores corresponding to Tables 1 and 4, respectively. For %BC scores, we use the same hyperparameters as Decision Transformer for fair comparison. For REM and QR-DQN, there is a slight discrepancy between Agarwal et al. 2020 and Kumar et al. 2020; we report raw data provided to us by REM authors.
表 11 给出 Hafner et al. 2020 归一化所用分数。表 12 与 13 分别对应表 1 与 4 的原始分数。%BC 分数使用与 Decision Transformer 相同的超参以便公平比较。REM 与 QR-DQN 在 Agarwal et al. 2020 与 Kumar et al. 2020 之间略有出入;我们报告 REM 作者提供的原始数据。
| Game | Random | Gamer |
|---|---|---|
| Breakout | ||
| Qbert | ||
| Pong | ||
| Seaquest |
Table 11: Atari baseline scores used for normalization.
| 游戏 | 随机 | 玩家 |
|---|---|---|
| Breakout | ||
| Qbert | ||
| Pong | ||
| Seaquest |
表 11:用于归一化的 Atari 基线分数。
| Game | DT (Ours) | CQL | QR-DQN | REM | BC |
|---|---|---|---|---|---|
| Breakout | |||||
| Qbert | |||||
| Pong | |||||
| Seaquest |
Table 12: Raw scores for the 1% DQN-replay Atari dataset. We report the mean and variance across 3 seeds. Best mean scores are highlighted in bold. Decision Transformer performs comparably to CQL on 3 out of 4 games, and usually outperforms other baselines.
| 游戏 | DT(本文) | CQL | QR-DQN | REM | BC |
|---|---|---|---|---|---|
| Breakout | |||||
| Qbert | |||||
| Pong | |||||
| Seaquest |
表 12:1% DQN-replay Atari 数据集上的原始分数。报告 3 种子均值与方差。最优均值加粗。Decision Transformer 在 4 款中的 3 款与 CQL 相当,并通常超过其他基线。
| Game | DT (Ours) | 10%BC | 25%BC | 40%BC | 100%BC |
|---|---|---|---|---|---|
| Breakout | |||||
| Qbert | |||||
| Pong | |||||
| Seaquest |
Table 13: %BC scores for Atari. We report the mean and variance across 3 seeds. Decision Transformer usually outperforms %BC.
| 游戏 | DT(本文) | 10%BC | 25%BC | 40%BC | 100%BC |
|---|---|---|---|---|---|
| Breakout | |||||
| Qbert | |||||
| Pong | |||||
| Seaquest |
表 13:Atari 上的 %BC 分数。报告 3 种子均值与方差。Decision Transformer 通常超过 %BC。





