ESRL: Efficient Sampling-Based Reinforcement Learning for Sequence Generation

Chenglong Wang, Hang Zhou, Yimin Hu, Yifu Huo, Bei Li, Tongran Liu, Tong Xiao, Jingbo Zhu

Abstract

Reinforcement Learning (RL) is a powerful tool for optimizing sequence generation models directly for long-term rewards like BLEU scores or human preferences. However, standard RL training is computationally expensive and memory-intensive due to the need to store computational graphs for every generated token. We present ESRL (Efficient Sampling-Based Reinforcement Learning), a framework that significantly reduces memory consumption and training time by decoupling sequence generation from gradient calculation and dynamically adjusting exploration. ESRL reduces memory usage by up to 47% while outperforming established methods like PPO and REINFORCE across various tasks, including machine translation and RLHF.

Introduction

Fine-tuning sequence models with RL allows for direct optimization of non-differentiable metrics. Despite its potential, RL in Natural Language Processing (NLP) faces significant scalability challenges. Standard setups require storing the entire computational graph for every token in every sampled sequence to compute gradients. With large vocabularies and long sequences, memory requirements quickly become prohibitive, often forcing researchers to use suboptimal batch sizes or limited samples. This leads to unstable training and exposure bias. ESRL addresses these bottlenecks through architectural and algorithmic innovations.

Methodology: Two-Stage and Dynamic Sampling

The core of ESRL lies in two primary mechanisms designed to optimize both memory and computation.

Two-Stage Sampling

Standard RL generates sequences and tracks gradients simultaneously. ESRL decouples these into two stages:

  1. Exploration Stage: The model generates candidate sequences in an autoregressive mode without tracking gradients. This "cheap" generation phase avoids the memory overhead of the computational graph.
  2. Optimization Stage: Once sequences are generated, the model calculates their probabilities in a single, parallelized forward pass with gradients. By leveraging the parallel processing capabilities of Transformers for known tokens, this stage is highly efficient.

Dynamic Sampling

Rather than using a fixed number of samples for every input, ESRL estimates "Model Capability." For inputs where the model already performs well (e.g., high BLEU or low entropy), ESRL reduces the number of samples and the sampling temperature. Conversely, for difficult inputs, it increases exploration. This targeted allocation of resources ensures that computation is focused where it is most needed.

The ESRL architecture featuring Dynamic Sampling and Two-stage Sampling modules.

Additionally, a FIFO-based Baseline Reward system is used to stabilize training by reducing the variance of RL gradients.

Experimental Setup

ESRL was evaluated on several benchmarks:

  • Machine Translation: IWSLT’14 German-English (De-En) and WMT’14 English-German (En-De).
  • Abstractive Summarization: CNN/Daily Mail (CNN/DM).
  • RLHF: Fine-tuning a LLaMA-7B model using Alpaca and GPT-4 Alpaca datasets.

Results and Discussion

ESRL demonstrates superior performance and efficiency compared to baseline methods.

Efficiency and Performance Gains

In machine translation tasks, ESRL achieved a 47% reduction in memory consumption and a 39% reduction in training time compared to standard REINFORCE. On the WMT’14 En-De test set, ESRL improved the BLEU score by 1.04 points over a vanilla Transformer.

Performance and efficiency comparison of ESRL against MLE and standard RL baselines.

Comparison with PPO

In RLHF experiments with LLaMA-7B, ESRL outperformed Proximal Policy Optimization (PPO) on the Vicuna-80 benchmark (626.00 vs. 596.00). Notably, ESRL avoided the "Out of Memory" errors that typically limit PPO when increasing sample sizes, highlighting its scalability for Large Language Models (LLMs).

Conclusion

ESRL provides a scalable and efficient framework for applying Reinforcement Learning to sequence generation. By separating generation from gradient calculation and implementing dynamic exploration, it overcomes the memory bottlenecks that have previously hindered RL in NLP. Future work will explore more refined methods for estimating model capability to further optimize the dynamic sampling process.

Summary updated

BibTeX
@inproceedings{wang2024esrl,
  author = {Chenglong Wang and Hang Zhou and Yimin Hu and Yifu Huo and Bei Li and Tongran Liu and Tong Xiao and Jingbo Zhu},
  title = {{ESRL: Efficient Sampling-Based Reinforcement Learning for Sequence Generation}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2024},
  doi = {10.1609/aaai.v38i17.29878},
}
Figure