Skip to main content

Generative Reinforcement Learning (GRL)

Twitter
GitHub stars GitHub forks GitHub commit activity GitHub issues GitHub pulls Contributors License

English | 简体中文(Simplified Chinese)

GenerativeRL, short for Generative Reinforcement Learning, is a Python library for solving reinforcement learning (RL) problems using generative models, such as diffusion models and flow models. This library aims to provide a framework for combining the power of generative models with the decision-making capabilities of reinforcement learning algorithms.

Outline

Features

  • Support for training, evaluation and deploying diverse generative models, including diffusion models and flow models
  • Integration of generative models for state representation, action representation, policy learning and dynamic model learning in RL
  • Implementation of popular RL algorithms tailored for generative models, such as Q-guided policy optimization (QGPO)
  • Support for various RL environments and benchmarks
  • Easy-to-use API for training and evaluation

Framework Structure

Image Description 1

Integrated Generative Models

Score Matching Flow Matching
Diffusion Model Open In Colab
Linear VP SDE ✔ ✔
Generalized VP SDE ✔ ✔
Linear SDE ✔ ✔
Flow Model Open In Colab
Independent Conditional Flow Matching 🚫 ✔
Optimal Transport Conditional Flow Matching 🚫 ✔

Integrated Algorithms

Algo./Models Diffusion Model Flow Model
QGPO ✔ 🚫
SRPO ✔ 🚫
GMPO ✔ Open In Colab ✔
GMPG ✔ Open In Colab ✔

Installation

pip install grl

Or, if you want to install from source:

git clone https://github.com/opendilab/GenerativeRL.git
cd GenerativeRL
pip install -e .

Or you can use the docker image:

docker pull opendilab/grl:torch2.3.0-cuda12.1-cudnn8-runtime
docker run -it --rm --gpus all opendilab/grl:torch2.3.0-cuda12.1-cudnn8-runtime /bin/bash

Quick Start

Here is an example of how to train a diffusion model for Q-guided policy optimization (QGPO) in the LunarLanderContinuous-v2 environment using GenerativeRL.

Install the required dependencies:

pip install 'gym[box2d]==0.23.1'

(The gym version can be from 0.23 to 0.25 for box2d environments, but it is recommended to use 0.23.1 for compatibility with D4RL.)

Download dataset from here and save it as data.npz in the current directory.

GenerativeRL uses WandB for logging. It will ask you to log in to your account when you use it. You can disable it by running:

wandb offline
import gym

from grl.algorithms.qgpo import QGPOAlgorithm
from grl.datasets import QGPOCustomizedDataset
from grl.utils.log import log
from grl_pipelines.diffusion_model.configurations.lunarlander_continuous_qgpo import config

def qgpo_pipeline(config):
    qgpo = QGPOAlgorithm(config, dataset=QGPOCustomizedDataset(numpy_data_path="./data.npz", action_augment_num=config.train.parameter.action_augment_num))
    qgpo.train()

    agent = qgpo.deploy()
    env = gym.make(config.deploy.env.env_id)
    observation = env.reset()
    for _ in range(config.deploy.num_deploy_steps):
        env.render()
        observation, reward, done, _ = env.step(agent.act(observation))

if __name__ == '__main__':
    log.info("config: \n{}".format(config))
    qgpo_pipeline(config)

For more detailed examples and documentation, please refer to the GenerativeRL documentation.

Documentation

The full documentation for GenerativeRL can be found at GenerativeRL Documentation.

Tutorials

We provide several case tutorials to help you better understand GenerativeRL. See more at tutorials.

Benchmark experiments

We offer some baseline experiments to evaluate the performance of generative reinforcement learning algorithms. See more at benchmark.

Contributing

We welcome contributions to GenerativeRL! If you are interested in contributing, please refer to the Contributing Guide.

License

GenerativeRL is licensed under the Apache License 2.0. See LICENSE for more details.

Metadata

Release files for GenerativeRL 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for GenerativeRL 0.0.1
File Size Uploaded
generativerl-0.0.1.tar.gz 141.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for GenerativeRL 0.0.1
File Interpreter ABI Platform
GenerativeRL-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 332.4 kB

Release files / generativerl-0.0.1.tar.gz

Download URL generativerl-0.0.1.tar.gz
Size 141.1 kB
Tags Source
SHA-256 checksum
How to use checksums
911d75a8cf7481b67f93b67b4e4f6a29b364d4edb85a93bbe5fbdf64300fab0b
BLAKE2b-256 checksum
How to use checksums
29e836697d81b4ce99449e0b4d3ddaa9fa5483f4f9f981e9a5d5d039e45b29aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2024.

Transparency log

Release files / GenerativeRL-0.0.1-py3-none-any.whl

Download URL GenerativeRL-0.0.1-py3-none-any.whl
Size 191.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f18f3577219075ecfca4d72ab82808e3b405ae8c17a0441e17c2c4f3a38832a0
BLAKE2b-256 checksum
How to use checksums
744ff96c36768406c1ad7f69970828ab0a75c21ec1834f7b56fe5f19e9715226
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2024.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page