Stabilizing Transformer-Based Action Sequence Generation For Q-Learning

Gideon Stein, Andrey Filchenkov, Arip AsadulaevarXiv 2020

Abstract

Since the publication of the original Transformer architecture (Vaswani et al. 2017), Transformers have revolutionized the field of Natural Language Processing (NLP). This is mainly due to their ability to understand temporal dependencies better than competing RNN-based architectures. Surprisingly, this architecture change has not significantly affected the field of Reinforcement Learning (RL), even though RNNs are popular in RL and time dependencies are common. Recently, Parisotto et al. (2019) conducted the first promising research of Transformers in RL. To support these findings, this paper provides an additional example of a Transformer-based RL method: a simple Transformer-based Deep Q-Learning method (TBQN) that is stable over several environments. Due to the unstable nature of Transformers and RL, an extensive method search was conducted to arrive at a final method that leverages developments in both Transformers and Q-learning. The proposed method matches the performance of classic Q-learning on control environments while showing potential on selected Atari benchmarks.

Introduction

In Natural Language Processing, Transformers are the gold standard because they handle long-term dependencies much better than Recurrent Neural Networks (RNNs). One would expect this advantage to carry over to RL, where agents often need to remember past states to make decisions in partially observable environments. However, Transformers are notoriously difficult to stabilize in RL. Unlike NLP, where the dataset is fixed, an RL agent’s own actions determine its future data. This creates a feedback loop that makes optimization incredibly unstable. Previous attempts to use Transformers in RL often resulted in erratic performance, even on simple problems. This research identifies the specific architectural tweaks and hyperparameters necessary to make a Transformer-based agent work reliably in a Deep Q-Learning (DQN) framework.

Methodology

The authors propose the Transformer-Based Q-Network (TBQN). The core architecture is a modified Transformer Encoder where the standard embedding layer is replaced by a fully connected layer to map state dimensions to model dimensions, and the final output is mapped to Q-values.

The TBQN architecture integrates state history through a modified Transformer block to output Q-values.

Architectural Search and Stability

To find a stable configuration, an extensive search was conducted across three categories:

  1. Layer Variations: Several "stabilized" Transformer blocks were tested, including Pre-layer Normalization and Gated Connections.
  2. Standard RL Additions: Integration of Double Q-learning, Gradient Clipping, and various Target Update strategies.
  3. Initialization: Implementation of Depth-Scaled Initialization, which scales weights based on their layer depth to prevent signal explosion or vanishing during the early stages of training.
Comparison of Transformer layer variations: (a) No dropout, (b) Identity Map Reordering (IMR), (c) Norm-first, and (d) Gated connections.

The search utilized a Tree-Structured Parzen Estimator to navigate the hyperparameter space efficiently, identifying the most robust configurations for RL environments.

Key Insights

  • IMR is King: Surprisingly, the Identity Map Reordering (IMR) layer performed best. While complex GRU-gated connections are often touted as the solution for deep RL stability, they were excluded early in this study due to frequent divergence.
  • Gradient Clipping is Non-Negotiable: For TBQNs, gradient clipping is essential. Without it, the "destructive updates" common in the early stages of RL training cause the Transformer to diverge almost immediately.
  • NLP Rules Don't Apply to RL: In NLP, Transformers are famously dependent on specific learning rate schedules (like the "warmup" phase). This study found that with the right layer architecture (like IMR), these schedules become obsolete in an RL context.
  • Initialization Matters: Depth-scaled initialization significantly reduced the tendency of the model to diverge at the start of training, leading to higher average rewards.

Results and Discussion

The TBQN was evaluated on OpenAI Gym control tasks (e.g., LunarLander-v2, CartPole-v1) and Atari benchmarks using RAM states.

  • Matching Baselines: In classic control environments, the TBQN matched the performance of highly optimized "classic" Q-learning baselines.
  • Atari Success: On the Asteroids benchmark, the TBQN significantly outperformed previous benchmarks, achieving an average return of 1813, compared to 1629 for a standard DQN and 1020 for a Recurrent Q-Network (RQN).
  • Stability: The paper demonstrates that with the proposed modifications, the Transformer provides consistent, reproducible learning curves across different seeds and environments.

However, limitations remain. In MsPacman, performance fluctuated wildly during training, and the model failed to consistently beat the DQN baseline. This suggests that while architectural stability is achieved, capturing the deep temporal nuances of complex games remains a hurdle.

Conclusion

This work demonstrates that Transformers can be successfully and stably applied to Deep Q-Learning. By adopting Identity Map Reordering, gradient clipping, and depth-scaled initialization, TBQNs overcome the inherent instabilities of the RL feedback loop. Future work will involve scaling these models to use visual (pixel) inputs rather than RAM states and exploring more advanced optimization methods to further dampen fluctuations in complex environments.

Summary updated

BibTeX
@misc{stein2020stabilizing,
  author = {Gideon Stein and Andrey Filchenkov and Arip Asadulaev},
  title = {{Stabilizing Transformer-Based Action Sequence Generation For Q-Learning}},
  year = {2020},
  eprint = {2010.12698},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2010.12698},
}
Figure