Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

tinybaselines

PPO in tinygrad. Continuous actions clipped to [-1, 1].

LunarLander from PyPI

Use Python 3.11 and clang. The library install does not include Gymnasium.

python3.11 -m venv .venv
source .venv/bin/activate
python -m pip install tinybaselines==0.1.0a2

Install Gymnasium and Box2D to run this example:

python -m pip install 'gymnasium[box2d]==1.4.0'

Save this as train_lander.py. It runs one PPO update and evaluates the reloaded checkpoint.

from contextlib import closing
from statistics import mean

import gymnasium as gym

from tinybaselines import GaussianActorCritic, PPO, evaluate, learn

policy = GaussianActorCritic(state_dim=8, action_dim=2, hidden_dim=128,
                             actor_layers=4, critic_layers=4,
                             observation_scale=[10, 6.666, 5, 7.5, 1, 2.5, 1, 1])
ppo = PPO(policy, pi_lr=1e-3, vf_lr=1e-3, gamma=0.99, lamda=0.95,
          K_epochs=20, eps_clip=0.2, batch_size=10_000, vf_coef=1.0, entropy_coef=0.001)

with closing(gym.vector.SyncVectorEnv(
    [lambda: gym.make('LunarLander-v3', continuous=True)] * 4,
    autoreset_mode=gym.vector.AutoresetMode.SAME_STEP,
)) as env:
    for step in learn(env, ppo, total_timesteps=20_000, rollout_steps=20_000):
        print(step.timesteps, step.rollout_seconds, step.update_seconds)
    ppo.save('ppo.safetensors')
    policy = PPO.load('ppo.safetensors').actor_critic
    print(mean(evaluate(env, policy, num_episodes=10)))
DEV=CPU BEAM=0 python train_lander.py

total_timesteps and rollout_steps count transitions across all environments. Use a positive multiple of env.num_envs for rollout_steps. Training stops after the first full rollout that reaches the budget. Each step contains completed episode_returns and collection/update times. The caller owns the environment. Use a separate environment for evaluation during training. evaluate resets its environment and returns complete episode returns. It samples actions by default; deterministic=True uses clipped policy means. actions go to the environment; raw_actions go into PPO. The collector uses Gymnasium vector environments with same-step autoreset. For time-limit bootstrapping, the collector reads pre-reset observations from infos['final_obs'].

PPO checkpoints contain the policy, observation scale, Adam state, and PPO settings. Continue training by passing the loaded PPO to learn with a new transition budget. Each learn call starts fresh episodes and a new transition counter. policy.save(path) exports a policy for inference.

Repository examples

From a checkout, run the full LunarLander trainer:

pip install -e . -r examples/lunar_lander/requirements.txt
python -m examples.lunar_lander.train

Pendulum uses three observations and one action. Its example rescales policy actions from [-1, 1] to torque in [-2, 2].

pip install -e . -r examples/pendulum/requirements.txt
DEV=CPU BEAM=0 python -m examples.pendulum.train --output runs/pendulum

The output directory contains the configuration, episode returns, update times, and a PPO checkpoint. Initial and final evaluations each use 100 fresh stochastic episodes.

Three independent four-environment CPU runs reached mean returns of -141.4, -162.2, and -150.8 after 200,704 transitions each. Each final evaluation used the reloaded checkpoint. Our acceptance cutoff is -200 over 100 fresh stochastic episodes per run; all three passed. Gymnasium defines no solved threshold for Pendulum. We chose this cutoff after the first run. Run records: 1, 2, 3.

Metadata

Release files for tinybaselines 0.1.0a2

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

Source distribution (sdist)

Source distribution for tinybaselines 0.1.0a2
File Size Uploaded Provenance Actions
tinybaselines-0.1.0a2.tar.gz 85.6 kB Without provenance Details for tinybaselines-0.1.0a2.tar.gz

Built distribution (wheel)

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

Total release size: 95.5 kB

Release files / tinybaselines-0.1.0a2.tar.gz

Download URL tinybaselines-0.1.0a2.tar.gz
Size 85.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9bf03a7c6d5826c25e809967c63d0ce69c7e0d4786903b61882532c3e8c2c07b
BLAKE2b-256 checksum
How to use checksums
f2580e7e38e664d9b41fc8e24d4a18152527cf20113700d52835b0bef12c8278
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / tinybaselines-0.1.0a2-py3-none-any.whl

Download URL tinybaselines-0.1.0a2-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25c6b2e3ebedc38f7f0c70fbf2e87e4cd38749409d383222b899a325a9dafa23
BLAKE2b-256 checksum
How to use checksums
ab82c17a2ecbbfba7c6a4419c7dae92f6a076fdcf9844f87fab26837614c85ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for tinybaselines 0.1.0a2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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