PPO for stateful/recurrent networks in JAX and flax.nnx.
Project description
nnx-ppo
Experimental implementation of Proximal Policy Optimization in JAX, with first-class support for recurrent/stateful networks. Networks are built with flax.nnx; environments follow the MuJoCo Playground API.
Status: experimental — the API may change without notice.
Highlights
- Stateful modules. Recurrent layers, delayed connections, and noisy / variational populations are all first-class citizens. Carry state is threaded through rollout collection and multi-epoch loss replay, and is reset correctly when the environment resets — something other JAX RL libraries (e.g. Brax) do not natively support.
- PyTree observations. Observations can be arbitrary nested dicts, which makes it easy to route different streams (proprioception, vision, imitation targets, …) to different parts of a network.
- PyTree actions and rewards. Actions and rewards are also allowed to be PyTrees, which simplifies multi-actuator and multi-agent setups.
Installation
pip install nnx-ppo
nnx-ppo installs the CPU build of JAX by default. For a CUDA 12 GPU build:
pip install nnx-ppo "jax[cuda12]"
Optional extras:
nnx_ppo[examples]—brax,wandb, andplayground(import namemujoco_playground) for the scripts in examples/.nnx_ppo[dev]— test-suite dependencies (pytest,pyright,beartype,absl-py, plusplaygroundfor the env-driven tests).
Quick example
from flax import nnx
import mujoco_playground
from nnx_ppo.algorithms import ppo
from nnx_ppo.algorithms.config import TrainConfig, PPOConfig, EvalConfig
from nnx_ppo.networks.factories import make_mlp_actor_critic
from nnx_ppo.wrappers import episode_wrapper
env = mujoco_playground.registry.load("CartpoleBalance")
train_env = episode_wrapper.EpisodeWrapper(env, 1000)
rngs = nnx.Rngs(0)
nets = make_mlp_actor_critic(
env.observation_size,
env.action_size,
actor_hidden_sizes=[64] * 4,
critic_hidden_sizes=[256] * 2,
rngs=rngs,
normalize_obs=True,
)
result = ppo.train_ppo(
train_env,
nets,
TrainConfig(
ppo=PPOConfig(n_envs=1024, rollout_length=30, total_steps=10_000_000),
eval=EvalConfig(enabled=True, every_steps=500_000, n_envs=64,
max_episode_length=1000),
),
eval_env=env,
)
print(f"Final eval reward: {result.eval_history[-1]['episode_reward_mean']}")
See examples/wandb_logging.py for a complete training script with W&B logging and video recording.
Documentation
Full documentation, tutorials, and API reference are at https://nnx-ppo.readthedocs.io.
License
BSD 3-Clause — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nnx_ppo-0.3.0.tar.gz.
File metadata
- Download URL: nnx_ppo-0.3.0.tar.gz
- Upload date:
- Size: 84.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86eb4f65255ad09480d25a5c63a3b6c037aa875b62306d409d7923f3ff17ce1e
|
|
| MD5 |
98963ddfc3f8015d9a23cd1e94dc1299
|
|
| BLAKE2b-256 |
d70869b142084e3a6cef30f6759e2ec73cea5fb79e952a8946179de56571583a
|
Provenance
The following attestation bundles were made for nnx_ppo-0.3.0.tar.gz:
Publisher:
release.yml on emiwar/nnx-ppo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nnx_ppo-0.3.0.tar.gz -
Subject digest:
86eb4f65255ad09480d25a5c63a3b6c037aa875b62306d409d7923f3ff17ce1e - Sigstore transparency entry: 2036246992
- Sigstore integration time:
-
Permalink:
emiwar/nnx-ppo@34095a7fdce0e3d9de801d8eebf9e02ab2f43f64 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/emiwar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@34095a7fdce0e3d9de801d8eebf9e02ab2f43f64 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nnx_ppo-0.3.0-py3-none-any.whl.
File metadata
- Download URL: nnx_ppo-0.3.0-py3-none-any.whl
- Upload date:
- Size: 106.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
733a3282ce08cd592176895026a2d5e3da988bc8de5bbc9a5061e7595cb222ed
|
|
| MD5 |
a9069928323e9fb39496dd23760a120e
|
|
| BLAKE2b-256 |
177addd5837088c644deb5a3b5d6381d51cf8cc26754446ca4e0db35d22df693
|
Provenance
The following attestation bundles were made for nnx_ppo-0.3.0-py3-none-any.whl:
Publisher:
release.yml on emiwar/nnx-ppo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nnx_ppo-0.3.0-py3-none-any.whl -
Subject digest:
733a3282ce08cd592176895026a2d5e3da988bc8de5bbc9a5061e7595cb222ed - Sigstore transparency entry: 2036247342
- Sigstore integration time:
-
Permalink:
emiwar/nnx-ppo@34095a7fdce0e3d9de801d8eebf9e02ab2f43f64 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/emiwar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@34095a7fdce0e3d9de801d8eebf9e02ab2f43f64 -
Trigger Event:
release
-
Statement type: