ElegantRL Documentation

repository·master·Indexed 26 days ago

https://github.com/ai4finance-foundation/elegantrl

A lightweight, massively parallel deep reinforcement learning framework optimized for high efficiency, stability, and cloud-native deployment. It supports scaling to thousands of GPUs using simulators like Isaac Gym and provides implementations for algorithms such as DQN, DDPG, and PPO. The framework includes base classes like AgentBase for custom agent development, utility functions for MLP construction, and a Config class for hyperparameter management.

Tokens
38K
Snippets
55
Records
197
Agent score
85%

What's inside ElegantRL

  1. Overview of QMix Algorithm

    master

    QMIX is a value-based method for Deep Multi-Agent Reinforcement Learning that enables training decentralized policies in a centralized end-to-end fashion. It uses a network to estimate joint action-values as a non-linear combination of per-agent values based on local observations.

    Supported Features:

    • Experience replay: Yes
    • Target network: Yes
    • Prioritized Experience Replay (PER): Yes
    • Gradient clipping: No
    • Reward clipping: No
    • Ornstein–Uhlenbeck noise: No
  2. Overview of RLSolver capabilities

    master

    RLSolver is a high-performance Reinforcement Learning (RL) solver designed to find high-quality or nearly global optima for both nonconvex/nonlinear continuous optimization problems and combinatorial discrete optimization problems. It provides pretrained neural networks for real-time inference in these domains.

    Key technical features include:

    • Massively parallel simulations: Uses GPU (CUDA and Tensor cores) to simulate gym-environments.
    • Stability via Hamiltonian-term: Implements the Hamiltonian-term as an add-on regularization to Deep Reinforcement Learning (DRL) algorithms, utilizing GPU parallel computing to search for 'minimum-energy states'.
    • Problem Domains: Supports MCMC-related tasks such as Maxcut, MIMO Beamforming (5G/6G), Classical NP-Hard problems, Quantum Circuit simulation, Compressive Sensing, Portfolio Management, and OR-Gym.
  3. Overview of ElegantRL features and capabilities

    master

    ElegantRL is a massively parallel, cloud-native Deep Reinforcement Learning (DRL) framework implemented in PyTorch. It is designed to address simulation speed bottlenecks, hyper-parameter sensitivity, and unstable generalization through multi-level parallelism and cloud-native paradigms (containerization, microservices, and orchestration).

    Key capabilities include:

    • Scalability: High scalability via multi-level parallelism (worker/learner parallelism within containers, pipeline parallelism across microservices, and scheduling parallelism). It supports training populations of hundreds of agents across hundreds or thousands of cloud nodes.
    • Elasticity: Flexible resource allocation for workers, learners, and agents, allowing adaptation to dynamic cloud resource availability.
    • Stability: Improved stability through ensemble methods, population-based training (PBT), and the implementation of the Hamiltonian-term (H-term) as an add-on regularization to model-free DRL algorithms to find 'minimum-energy states'.
    • Accessibility: Modularized framework with support for OpenAI Gym, MuJoCo, and Isaac Gym, supplemented by tutorials and demos.
  4. Overview of ElegantRL algorithms and simulators

    master

    ElegantRL implements several model-free Deep Reinforcement Learning (DRL) algorithms:

    • Continuous actions (single-agent): DDPG, TD3, SAC, PPO, REDQ
    • Discrete actions (single-agent): DQN, Double DQN, D3QN
    • Multi-agent environment: QMIX, VDN, MADDPG, MAPPO, MATD3

    Supported simulators:

    • Isaac Gym: For massively parallel simulations.
    • Benchmarking: OpenAI Gym, MuJoCo, PyBullet, FinRL.
  5. Compare ElegantRL with RLlib and Stable Baselines3 (SB3)

    master

    ElegantRL vs RLlib

    • Efficiency: ElegantRL allows the learner to use data collected by the worker immediately on the same GPU without data movement. RLlib's asynchronous producer-consumer model can lead to stale data.
    • Vectorized Environments: ElegantRL supports vectorized environments for both workers and learners, including custom vwap vectorized environments. RLlib's learner support for vectorized environments is limited.
    • Complexity: RLlib has a higher barrier to entry due to its complex abstraction of the RL process.
    • Multi-GPU: RLlib excels at multi-card scheduling via Ray, while ElegantRL (e.g., using PPO+Podracer) focuses on higher data utilization efficiency for specific tasks like finance.

    ElegantRL vs Stable Baselines3 (SB3)

    • Stability: ElegantRL is more stable due to:
      • Use of vmap vectorized environments (e.g., StockTradingVecEnv) which allows GPU-based simulation, increasing data collection volume by orders of magnitude.
      • Implementation of the H term to find alternative optimization directions to avoid local optima.
    • Speed: ElegantRL is faster because of:
      • Optimized ReplayBuffer that stores states sequentially to avoid redundant storage and uses custom PyTorch tensor-based pointer logic instead of standard DataLoader.
      • Optimizations for vectorized environments in both workers and learners.
      • GPU-parallel simulation environments specifically for FinRL and RLSolver tasks.
  6. Parallelism types in ElegantRL

    master

    ElegantRL supports multiple levels of parallelism:

    • Agent Parallelism: Training hundreds of agents in parallel via Population-Based Training (PBT), useful for ensemble methods.
    • Worker Parallelism: Accelerates data collection by generating transitions in parallel. Supported methods include:
      • Using a VecEnv to generate transitions in batches.
      • Using multiple workers for environments that are not VecEnv.
    • Learner Parallelism: Training multiple critics and multiple actors in parallel for ensemble DRL methods to improve stability and reduce overestimation bias.
  7. Understand ElegantRL's Cloud-Native Architecture

    master

    ElegantRL is designed as a cloud-native framework for massively parallel Deep Reinforcement Learning (DRL) training. It utilizes a microservice-based architecture to handle the full DRL lifecycle (simulate-learn-deploy) on cloud computing power.

    Key architectural components include:

    • Microservices: DRL agents are organized into specialized microservices such as orchestrator, worker, learner, and evaluator, which communicate via APIs.
    • Containerization: Each microservice is mapped to a container, and the entire agent is encapsulated into a Kubernetes (K8s) Pod.
    • Orchestration: The framework uses Kubernetes to automate the deployment and management of DRL applications, providing benefits like asynchronous parallelism, fault isolation, and security.
  8. Multi-Agent Proximal Policy Optimization (MAPPO) Overview

    master
    MAPPO is a variant of Proximal Policy Optimization (PPO) specialized for multi-agent settings. It is designed to achieve strong performance in multi-agent environments (such as particle-world or Starcraft) while maintaining comparable sample efficiency to standard PPO. A key feature of this implementation is the use of shared network parameters across all agents.
  9. Implement Twin Delayed DDPG (TD3)

    master

    TD3 is an improvement over DDPG that uses Clipped Double-Q Learning, Delayed Policy Updates, and Target Policy Smoothing to prevent Q-value overestimation.

    Supported features in this implementation:

    • Experience replay
    • Target network
    • Gradient clipping
    • Prioritized Experience Replay (PER)

    Note: The implementation uses a CriticTwin class which shares parameters between two Q-networks to reduce computational and training time costs.

    Warning: TD3 contains highly sensitive hyperparameters that require careful tuning for satisfactory results.

  10. Understand the ElegantRL HelloWorld architecture

    master

    The ElegantRL HelloWorld project follows a 'Net-Agent-Env-Run' architecture to implement Deep Reinforcement Learning (DRL). The core components are:

    • net.py: Defines the neural network architectures, including Q-Net, Actor Network, and Critic Network.
    • agent.py: Contains DRL algorithm implementations (e.g., DQN, SAC, PPO) and the ReplayBuffer class for storing transitions.
    • erl_env.py: Provides a wrapper class to preprocess Gym-styled environments.
    • run.py: Orchestrates the training and evaluation loop via the train_and_evaluate process.
    • demo.py: Provides entry points for running specific algorithm/action-space combinations.
  11. Ensemble methods and Tournament-based training

    master

    ElegantRL supports three ensemble methods:

    1. Weighted average
    2. Model fusion
    3. Tournament-based ensemble training scheme

    Tournament-based ensemble training is a cloud orchestration mechanism that schedules interactions between a leaderboard and a training pool containing hundreds of agents (pods). This is detailed in the ElegantRL-Podracer documentation.