Skip to main content

license: other license_name: polyform-noncommercial-1.0.0 license_link: https://polyformproject.org/licenses/noncommercial/1.0.0 library_name: pytorch tags:

  • reinforcement-learning
  • gymnasium
  • mujoco
  • unity
  • ml-agents
  • causal-gpt-rl

Causal GPT-RL

PyPI Python Hugging Face License: PolyForm NC 1.0.0

GPT-style transformers (Llama) running as RL policies in continuous and discrete control environments.

Here to run a policy? → Quick Start. Evaluating the product? → Available Policies for what is published and how it scores.

No expert demonstrations required: trained only on simple and medium offline trajectories, several bundles outperform both. Horizon is adjustable at inference, with stable retention beyond the training window. Try the bundles on Hugging Face.

Both LLM generation and RL interaction are autoregressive:

token           → next token                           (LLM generation)
(state, action) → (next state from env, next action)   (RL rollout)

A rollout unrolled — each token pairs the current state with the action for it, that action moves the environment, and the environment returns the next state; meanwhile the model generates the next action from completed state-action pairs, not from the state it just received

Causal GPT-RL policies act stably under their own rollouts — long-horizon control without the drift that has historically kept transformers from being usable as RL agents.

A single autoregressive model drives full-episode rollouts via a KV cache, the same mechanism an LLM uses to hold its context while generating — no separate critic, no auxiliary networks at inference. It computes a value head on every forward pass, but a rollout never reads it: the action alone carries the loop.

The calling contract that follows from this — why the output is one step ahead of the observation you just passed, and why actions keep coming with no environment attached — is Transformer Model Integrating Environment Dynamics for RL.

This repository is the public inference runtime: it loads policy bundles, runs Gymnasium/MuJoCo rollouts, and provides small evaluation helpers. Training is not here — it runs on AWS Marketplace as the CCNets Causal GPT-RL Training Algorithm.

Released under PolyForm Noncommercial 1.0.0. Commercial use is licensed separately — see License.

Install

pip install "causal-gpt-rl[hub,mujoco]"

From a clone, python -m pip install -e ".[hub,mujoco]". For private bundles, run hf auth login first. On Windows the Hub cache uses symlinks, which fail with OSError: [WinError 1314] unless Developer Mode is on — enable it, or set HF_HUB_DISABLE_SYMLINKS=1.

Turning a bundle into a self-contained ONNX policy is Export a delivered bundle to ONNX.

Quick Start

import gymnasium as gym

from causal_gpt_rl.inference import load_runner_from_hub, run_episodes

env = gym.make("Ant-v5")
runner = load_runner_from_hub(
    repo_id="ccnets/causal-gpt-rl",
    subfolder="ant-v5",
)

stats = run_episodes(env, runner, num_episodes=5, seed=0)
env.close()
print(stats["return_mean"], stats["return_std"])

Notebook version: examples/hub_quickstart.ipynb

Five episodes off one seed is a smoke test, not the protocol the published scores were measured under. To measure a bundle that way, see Reproduce a published score.

Available Policies

Policy bundles, the environments they run in, and the trajectory datasets are published on the Hugging Face org:

Repo Contents
ccnets/causal-gpt-rl MuJoCo continuous control — Ant-v5, HalfCheetah-v5, Hopper-v5, Walker2d-v5, Humanoid-v5, HumanoidStandup-v5, Pusher-v5, Swimmer-v5
ccnets/causal-gpt-rl-unity Unity ML-Agents — Crawler, DungeonEscape, PushBlock, Pyramids, SoccerTwos (model.safetensors + per-context ONNX)
ccnets/causal-gpt-rl-unity-envs Model-removed Unity builds + stock policies where redistributable
ccnets/causal-gpt-rl-unity-datasets Recorded Minari trajectories

Returns, the evaluation protocol, and the runtime each score was measured on are on the corresponding model card; the MuJoCo training runs are public at wandb.ai/causal-gpt-rl/mujoco, and worked runs — including the Unity download-and-measure walkthroughs — are in examples/.

Observation & Action Spaces

Every fixed-shape Gymnasium space, and any Dict / Tuple nesting of them. Variable-length and structural spaces — raw images, Text, Sequence, Graph, OneOf — are out of scope; encode those into vectors on your side. A bundle carries its own spaces, so you pass observations exactly as your env produces them and get back a valid sample of its action space.

See docs/ for the per-space contract, the calling contract, the API reference, and ONNX export.

Rollout History

A bundle's context_length is the length used in training, and not a limit at inference.

kv_cache_max_len — how much past a rollout retains — is a load-time knob. It defaults to the bundle's own context_length, which keeps a rollout inside the window the policy was measured on:

runner = load_runner("path/to/bundle", kv_cache_max_len=64)

Why long-context extrapolation can be stable in RL — two measures leave the same first step, a short arrow to the trained window of 32 and a long one to a 1000-step retention, over a single unbroken bar of tokens that runs on past the shorter one

A long horizon becomes a matter of context length — conditioning on context offers a general way to address RL problems, using a quantity language models already expose: how much past the model retains, in steps rather than words. Unlike an MLP policy, that history can be changed at load time without changing the model. See Transformer Model Integrating Environment Dynamics for RL.

Larger values run. Whether more past helps a particular environment is a separate question — across the Hugging Face bundles, it helps some and hurts others.

On long rollouts, a mean return can average early failures and full-length runs into a number that describes neither. See Measuring a Long Horizon for what to report instead.

Bundle Format

A bundle is a directory of two files, and it is the same directory whether it came from Hugging Face, from local export, or from a training run. On the Hub each bundle is one subfolder of a repo, which is what subfolder= selects; locally, pass the directory to load_runner("path/to/bundle").

bundle/
  model.safetensors    # inference weights, state normalization embedded
  config.json          # model config, observation/action specs, context length

Public bundles are bundle_format_version=2. Runtime releases keep backward compatibility, so the bundles on Hugging Face today and the bundles produced through AWS load on any package version.

Development Checks

python -m compileall -q causal_gpt_rl
python -m unittest discover -s tests
python -m build
python -m twine check dist/*

License

Released under PolyForm Noncommercial License 1.0.0. See LICENSE for details. Commercial use is licensed separately — through a CCNets Causal GPT-RL Training Algorithm subscription on AWS Marketplace, or by contacting the maintainers via ccnets.org.

Metadata

Release files for causal-gpt-rl 0.21.0

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

Source distribution (sdist)

Source distribution for causal-gpt-rl 0.21.0
File Size Uploaded
causal_gpt_rl-0.21.0.tar.gz 144.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for causal-gpt-rl 0.21.0
File Interpreter ABI Platform
causal_gpt_rl-0.21.0-py3-none-any.whl Python 3 none any Details

Total release size: 230.5 kB

Release files / causal_gpt_rl-0.21.0.tar.gz

Download URL causal_gpt_rl-0.21.0.tar.gz
Size 144.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7ef25f3599dd89629228cfc302f251ebd732ddf265bd3254c44351f6fe76bb43
BLAKE2b-256 checksum
How to use checksums
a38a652c37f810351174e8dae20b98a19810f08a0cfd954b59ed49011bf8d6f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 9, 2026.

Transparency log

Release files / causal_gpt_rl-0.21.0-py3-none-any.whl

Download URL causal_gpt_rl-0.21.0-py3-none-any.whl
Size 86.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
730030c42e109414585edb7bd9a4127bef4a7b53952de773e279de7a3c298582
BLAKE2b-256 checksum
How to use checksums
3f854feb46f843bc26d4ba5ba246a4fbdb0ca94a672970337e1573b47fd26f42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.21.0 This release

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

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