This paper introduces Pgx, a high-performance library designed to supercharge Reinforcement Learning (RL) research by moving game simulations directly onto the hardware that trains the models: GPUs and TPUs. By writing environments entirely in JAX, Pgx enables 10–100x faster simulations than traditional Python-based libraries, allowing researchers to scale RL training to thousands of parallel environments on a single workstation.
The "Speed Gap" in Reinforcement Learning
In modern RL, there is a frustrating speed gap. While neural network training happens at lightning speed on accelerators (GPUs/TPUs), the environment simulations—the "games" the AI plays to learn—usually run on CPUs. This setup creates two major hurdles:
- The Communication Bottleneck: Constantly moving data between the CPU (simulation) and GPU (training) is slow and inefficient.
- Parallelization Difficulties: Standard Python environments are hard to scale across multiple CPU cores due to the Global Interpreter Lock (GIL). While C++ wrappers like OpenSpiel help, they still don't solve the data transfer issue and can be difficult for researchers to modify.
Pgx aims to solve this by providing "accelerator-native" simulators for complex discrete games.
Methods: Pure JAX and the Anakin Architecture
The core innovation of Pgx is its implementation in JAX, a high-performance numerical computing library.
- Pure JAX Implementation: Unlike other libraries that wrap C++ code, Pgx games are written as pure JAX functions. This allows the library to use JAX’s
vmapfor auto-vectorization (running thousands of game instances simultaneously) andpmapfor parallelization across multiple GPUs. - Anakin Architecture: Pgx follows the "Anakin" RL architecture, where both the agent and the environment reside on the accelerator. This eliminates the need to move data back to the CPU during the training loop.
- JIT Compilation: By using Just-In-Time (JIT) compilation, Pgx optimizes the game logic specifically for the hardware it's running on, further boosting execution speed.
Supported Environments
Pgx provides a diverse collection of over 20 game environments.
These environments are categorized as follows:
- Classic Board Games: Chess, Shogi, and Go (both 9x9 and 19x19).
- Stochastic Games: Backgammon and 2048 (games involving chance).
- Imperfect Information Games: Bridge bidding, Kuhn poker, and Leduc hold’em.
- Miniature Games: Small-scale versions like "Animal Shogi" and "Gardner Chess" (5x5) to allow for rapid iteration on limited hardware.
- MinAtar: A JAX re-implementation of the simplified Atari benchmark suite.
Key Insights and Results
- Massive Speedups: On an NVIDIA DGX-A100, Pgx was 10x to 100x faster than existing Python libraries like PettingZoo and OpenSpiel across various games.
- Throughput Benchmarks: For simple games like Tic-tac-toe, Pgx reached over $10^8$ steps per second. Even for complex games like 19x19 Go, it maintained over $10^5$ steps per second on a single GPU.
- Hardware Efficiency: The results show that Pgx scales almost linearly with hardware. Moving from one A100 GPU to eight yielded a 7.4x increase in throughput, proving the library's readiness for large-scale clusters.
- Training Success: The authors successfully trained a Gumbel AlphaZero agent on 9x9 Go in just 8 hours on a single A100, achieving a level of play significantly stronger than established baselines like Pachi.
Limitations and Future Work
While highly effective, Pgx has a few limitations. Due to the difficulty of emulating legacy hardware logic in JAX, it does not currently support the full Atari 2600 suite, which remains a staple of RL benchmarking. Additionally, the API is specialized for fixed-player games and does not easily handle environments where the number of agents changes dynamically. Finally, researchers committed to frameworks like PyTorch may find it difficult to integrate Pgx into their existing pipelines.
Future directions include adding more complex imperfect information games (like Texas Hold'em and Mahjong), improving baseline models for large-scale games, and developing a human-vs-agent user interface for better qualitative evaluation.
Summary updated