Optimizing Data Collection in Deep Reinforcement Learning

James Gleeson, Daniel Snider, Yvonne Yang, Moshe Gabel, Eyal de Lara, Gennady PekhimenkoarXiv 2022 · DOI

Abstract

Training Deep Reinforcement Learning (RL) models is often bottlenecked by the data collection phase, where agents interact with simulators. Traditionally, these simulators run on CPUs while neural networks run on GPUs, leading to significant latency from data transfer and serial processing. This paper explores moving simulators entirely onto the GPU, utilizing vectorization and kernel fusion. Our results demonstrate up to a 1024× speedup in data collection throughput, significantly reducing the time and cost of RL training.

Introduction

In Deep Reinforcement Learning, an agent improves its policy through iterative interaction with an environment. This "data collection" loop is a primary performance bottleneck. Standard implementations run simulators on the CPU, necessitating frequent data transfers between the CPU and GPU (where the policy network resides). This architecture suffers from two main issues: the inherent slowness of CPU-based physics simulation compared to GPU parallelization, and the "API tax"—the overhead of Python-based control flow managing GPU kernel launches.

Methods: GPU-Centric Data Collection

To address these bottlenecks, we propose keeping the entire simulation and inference loop on the GPU.

GPU Vectorization

Instead of sequential execution, we run thousands of simulator instances in parallel across GPU threads. We evaluated two implementation strategies:

  1. DNN Frameworks (PyTorch): Utilizing standard library operators for parallel execution.
  2. ML Compilers (XLA/JAX): Compiling the entire simulation loop into a single graph. This approach minimizes Python-to-GPU communication overhead, which is particularly beneficial at smaller scales where "chattiness" dominates execution time.
Unified GPU pipeline for simulation and inference.

Simulator Kernel Fusion

While vectorization exploits parallel environments (width), kernel fusion exploits sequential steps (depth). By manually writing CUDA kernels that "fuse" multiple simulation steps into a single launch, we keep the simulator state in fast local memory (registers/cache). This avoids the latency of writing state back to global memory after every step, which is crucial as environment complexity and state size increase.

Experimental Setup

We used the Cartpole environment as a primary benchmark for deep hardware analysis. To validate generalizability, we compared results against more complex robotics simulators in the Brax suite (Ant, Humanoid, Fetch). Baselines included standard single-core OpenAI Gym (CPU) and optimized multi-core C++ implementations.

Key Results

Our GPU-based implementations achieved massive throughput gains. Moving from a single-core CPU baseline to a vectorized GPU implementation yielded up to a 1024× speedup.

Throughput scaling for various simulators as the number of environments (N) increases.
  • Compiler Efficiency: XLA outperformed PyTorch's eager execution by 13.4× at lower scales and 53.8× on average by reducing API overhead.
  • Fusion Benefits: Manual CUDA fusion provided an 11.3× speedup for Cartpole. In memory-bound scenarios (simulated by increasing state size), fusion benefits scaled up to 1024×.
  • CPU Limitations: Even highly optimized multi-core C++ simulators only achieved a 4× improvement over single-core baselines, underscoring the necessity of GPU acceleration for large-scale RL.

Discussion and Future Work

While moving simulation to the GPU provides dramatic speedups, challenges remain. Manual kernel fusion for complex engines like MuJoCo is engineering-intensive. Furthermore, while we fused simulation steps, the "inference gap"—fusing the neural network forward pass directly into the simulation kernel—remains an area for future optimization. The reliance on closed-source libraries also limits the ability of compilers like XLA to perform global optimizations across the entire RL loop.

Summary updated

BibTeX
@misc{gleeson2022optimizing,
  author = {James Gleeson and Daniel Snider and Yvonne Yang and Moshe Gabel and Eyal de Lara and Gennady Pekhimenko},
  title = {{Optimizing Data Collection in Deep Reinforcement Learning}},
  year = {2022},
  eprint = {2207.07736},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2207.07736},
}
Figure