RL-Scope: Cross-Stack Profiling for Deep Reinforcement Learning Workloads

James Gleeson, Srivatsan Krishnan, Moshe Gabel, Vijay Janapa Reddi, Eyal de Lara, Gennady PekhimenkoMLSys 2021

Abstract

Deep reinforcement learning (RL) models are notoriously slow to train, yet their performance bottlenecks differ significantly from supervised learning (SL). While SL is typically GPU-bound, RL workloads are often limited by CPU-side simulation, high-level language logic, and frequent transitions between Python and C++. We present RL-Scope, a novel cross-stack profiler designed to accurately identify these bottlenecks by mapping low-level resource usage to high-level algorithmic phases. RL-Scope automatically corrects for profiling overhead, revealing that standard tools like nvidia-smi can be highly misleading in RL contexts. Our evaluation shows that language transitions and API calls often dominate training time, with "Eager" execution modes being up to 4.8× slower than compiled "Graph" modes.

The Challenge of Profiling RL

Standard machine learning profilers are optimized for supervised learning, where the primary task is streaming large datasets to the GPU. In contrast, RL involves a complex, iterative loop where the CPU must simulate environments, execute policy logic, and manage data buffers before passing small batches to the neural network.

The complex RL training loop involves frequent transitions between simulation, inference, and backpropagation across the Python/C++ boundary.

Existing tools often fail to capture these CPU-centric bottlenecks and introduce significant "book-keeping" overhead, which can inflate training time by nearly 2×. This leads developers to optimize GPU kernels when the real bottleneck lies in the simulator or the framework's internal API overhead.

RL-Scope Methodology

RL-Scope addresses these issues through four key techniques:

  1. Algorithmic Annotations: Developers use Python with blocks to label phases like simulation or inference.
  2. Transparent Interception: Using LD_PRELOAD hooks, the tool intercepts transitions between Python and C++ backends and CUDA API calls without requiring code recompilation.
  3. Cross-Stack Overlap Analysis: The tool calculates the precise overlap between CPU and GPU activity, scoped to specific algorithmic phases.
  4. Overhead Calibration: RL-Scope measures its own instrumentation overhead and subtracts it from the final results, reducing profiling bias from ~90% to within ±16%.

Key Results and Insights

Our evaluation across various algorithms (DQN, PPO, SAC, etc.) and frameworks (TensorFlow, PyTorch) yielded several critical insights into RL performance.

The "Eager" Execution Penalty

A major finding is the high cost of developer-friendly "Eager" execution modes. As shown in the performance breakdown, Eager modes in both TensorFlow and PyTorch suffer from significant Python-to-Backend transition overhead.

Training time breakdown and language transitions across different framework configurations for TD3 and DDPG algorithms.

For example, in the TD3 algorithm, PyTorch Eager is 2.3× faster than TensorFlow Eager because it minimizes these transitions more effectively. Converting TensorFlow code to "Autograph" or "Graph" mode can reduce Python-bound time from nearly 60% to under 8%.

The Illusion of GPU Utilization

RL-Scope reveals that standard metrics like nvidia-smi are often deceptive. In the Minigo (AlphaGoZero) workload, nvidia-smi reported 100% GPU utilization. However, RL-Scope's fine-grained tracing showed that the GPU was actually executing kernels for only 20 seconds out of over 5,000 seconds of training. The rest of the time was spent on CPU-side CUDA API calls and data preparation.

Conclusion

RL-Scope provides the first comprehensive view of the RL software stack, from high-level Python logic down to low-level GPU kernels. By identifying that RL is primarily CPU-bound and limited by framework overhead rather than compute, it enables developers to focus optimization efforts where they matter most. Future work includes extending these capabilities to distributed RL clusters.

Summary updated

BibTeX
@inproceedings{gleeson2021rl,
  author = {James Gleeson and Srivatsan Krishnan and Moshe Gabel and Vijay Janapa Reddi and Eyal de Lara and Gennady Pekhimenko},
  title = {{RL-Scope: Cross-Stack Profiling for Deep Reinforcement Learning Workloads}},
  booktitle = {MLSys},
  year = {2021},
  url = {https://openreview.net/forum?id=EoUZyJmieHT},
}
Figure