Skip to main content

Rejax
Hardware-Accelerated Reinforcement Learning Algorithms in pure Jax!
Open In Colab Code style: black License: Apache 2.0 PyPI version


Rejax is a library of RL algorithms which are implemented in pure Jax. It allows you to accelerate your RL pipelines by using jax.jit, jax.vmap, jax.pmap or any other transformation on whole training algorithms. Use it to quickly search for hyperparameters, evaluate agents for multiple seeds in parallel, or run meta-evolution experiments on your GPUs and TPUs. If you're new to rejax and want to learn more about it,

Open In Colab 📸 Take a tour

rejax demo

🏗 Installing rejax

  1. Install via pip: pip install rejax
  2. Install from source: pip install git+https://github.com/keraJLi/rejax

⚡ Vectorize training for incredible speedups!

  • Use jax.jit on the whole train function to run training exclusively on your GPU!
  • Use jax.vmap and jax.pmap on the initial seed or hyperparameters to train a whole batch of agents in parallel!
from rejax import SAC

# Get train function and initialize config for training
algo = SAC.create(env="CartPole-v1", learning_rate=0.001)

# Jit the training function
train_fn = jax.jit(algo.train)

# Vmap training function over 300 initial seeds
vmapped_train_fn = jax.vmap(train_fn)

# Train 300 agents!
keys = jax.random.split(jax.random.PRNGKey(0), 300)
train_state, evaluation = vmapped_train_fn(keys)

Benchmark on an A100 80G and a Intel Xeon 4215R CPU. Note that the hyperparameters were set to the default values of cleanRL, including buffer sizes. Shrinking the buffers can yield additional speedups due to better caching, and enables training of even more agents in parallel.

Speedup over cleanRL on hopper Speedup over cleanRL on breakout

🤖 Implemented algorithms

Algorithm Link Discrete Continuous Notes
PPO here ✔ ✔
SAC here ✔ ✔ discrete version as in Christodoulou, 2019
DQN here ✔ incl. DDQN, Dueling DQN
PQN here ✔
IQN here ✔
TD3 here ✔

🛠 Easily extend and modify algorithms

The implementations focus on clarity! Easily modify the implemented algorithms by overwriting isolated parts, such as the loss function, trajectory generation or parameter updates. For example, easily turn DQN into DDQN by writing

class DoubleDQN(DQN):
    def update(self, state, minibatch):
        # Calculate DDQN-specific targets
        targets = ddqn_targets(state, minibatch)

        # The loss function predicts Q-values and returns MSBE
        def loss_fn(params):
            ...
            return jnp.mean((targets - q_values) ** 2)

        # Calculate gradients
        grads = jax.grad(loss_fn)(state.q_ts.params)

        # Update train state
        q_ts = state.q_ts.apply_gradients(grads=grads)
        state = state.replace(q_ts=q_ts)
        return state

🔙 Flexible callbacks

Using callbacks, you can run logging to the console, disk, wandb, and much more. Even when the whole train function is jitted! For example, run a jax.experimental.io_callback regular intervals during training, or print the current policies mean return:

def print_callback(algo, state, rng):
    policy = make_act(algo, state)           # Get current policy
    episode_returns = evaluate(policy, ...)  # Evaluate it
    jax.debug.print(                         # Print results
        "Step: {}. Mean return: {}",
        state.global_step,
        episode_returns.mean(),
    )
    return ()  # Must return PyTree (None is not a PyTree)

algo = algo.replace(eval_callback=print_callback)

Callbacks have the signature callback(algo, train_state, rng) -> PyTree, which is called every eval_freq training steps with the config and current train state. The output of the callback will be aggregated over training and returned by the train function. The default callback runs a number of episodes in the training environment and returns their length and episodic return, such that the train function returns a training curve.

Importantly, this function is jit-compiled along with the rest of the algorithm. However, you can use one of Jax's callbacks such as jax.experimental.io_callback to implement model checkpoining, logging to wandb, and more, all while maintaining the advantages of a completely jittable training function.

💞 Alternatives in end-to-end GPU training

Libraries:

  • Brax along with several environments, brax implements PPO and SAC within their environment interface

Single file implementations:

  • PureJaxRL implements PPO, recurrent PPO and DQN
  • Stoix features DQN, DDPG, TD3, SAC, PPO, as well as popular extensions and more

✍ Cite us!

@misc{rejax, 
  title={rejax}, 
  url={https://github.com/keraJLi/rejax}, 
  journal={keraJLi/rejax}, 
  author={Liesen, Jarek and Lu, Chris and Lange, Robert}, 
  year={2024}
} 

Metadata

Release files for rejax 0.1.3

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

Source distribution (sdist)

Source distribution for rejax 0.1.3
File Size Uploaded Provenance Actions
rejax-0.1.3.tar.gz 22.7 MB With provenance Details for rejax-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 22.7 MB

Release files / rejax-0.1.3.tar.gz

Download URL rejax-0.1.3.tar.gz
Size 22.7 MB
Tags Source
SHA-256 checksum
How to use checksums
dc3bfb7d033169242d09012bc4c68764997975090fbfc483a0360b8e0f266b65
BLAKE2b-256 checksum
How to use checksums
03e2b0273e4e600c3a586cea915b633adc040b224b09ba3d3ca718001a4e2a53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 10, 2026.

Transparency log

Release files / rejax-0.1.3-py3-none-any.whl

Download URL rejax-0.1.3-py3-none-any.whl
Size 41.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86c7468b5b3c9b520b813d0e89137f36e1472d14c327ae86c5328b6e0ca629c0
BLAKE2b-256 checksum
How to use checksums
995426ff8e17574f3ec915833420282d630c6f94bba7f35b0897d5c8dd016d2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 10, 2026.

Transparency log

Security for rejax 0.1.3

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rejax-0.1.3.tar.gz

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 Jun 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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