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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

causal_gpt_rl-0.17.0.tar.gz (108.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

causal_gpt_rl-0.17.0-py3-none-any.whl (73.0 kB view details)

Uploaded Python 3

File details

Details for the file causal_gpt_rl-0.17.0.tar.gz.

File metadata

  • Download URL: causal_gpt_rl-0.17.0.tar.gz
  • Upload date:
  • Size: 108.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for causal_gpt_rl-0.17.0.tar.gz
Algorithm Hash digest
SHA256 db0b22353ebe3c0866ec1d3fefd4062e65057ac51b7c176ccb932b2ca1ffa936
MD5 415ddfe233e8e3ace4a02464d0c41a9d
BLAKE2b-256 df8976ba2353da42ca22ad8fcdb34ea112cd1414b5f1f6c594339f4f65d75a01

See more details on using hashes here.

Provenance

The following attestation bundles were made for causal_gpt_rl-0.17.0.tar.gz:

Publisher: publish.yml on ccnets-team/causal-gpt-rl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file causal_gpt_rl-0.17.0-py3-none-any.whl.

File metadata

  • Download URL: causal_gpt_rl-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 73.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for causal_gpt_rl-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eedca6ec8f541676801e192dcc1d64ade71dc5c07492881efde2fdc3d18ab160
MD5 18c0e11745305e7feee2f021f0fa2945
BLAKE2b-256 bef53e989356d825415d1536dd08e7604c5219fd0fa55fb904a3f151662c6f98

See more details on using hashes here.

Provenance

The following attestation bundles were made for causal_gpt_rl-0.17.0-py3-none-any.whl:

Publisher: publish.yml on ccnets-team/causal-gpt-rl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.18.0

2 files

This release

0.17.0 This release

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 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