Fast Python 3.14 wheels for stable-retro RL workloads
Project description
Fast Python 3.14 wheels for stable-retro RL workloads
stable-retro-turbo publishes installable macOS Apple Silicon and Linux wheels for the upstream stable-retro API surface.
Use it when you want stable_retro game environments without building the package and bundled public libretro cores from source yourself.
What changed from upstream
This fork keeps the upstream stable_retro API and focuses its optimized RL
surface on the native multithreaded vector path:
- Python
3.14wheels for macOSarm64and Linuxx86_64. - Bundled Game Boy, NES, SNES, and Genesis/Master System public cores.
- Multi-emulator native frontend support inside one process, using per-instance libretro function tables, thread-local callback routing, and isolated core copies when several emulator instances load the same core.
StableRetroNativeVecEnv, a same-process SB3 VecEnv where C++ owns the emulator pool, frame skip, preprocessing, frame stacking, autoreset, reward and done evaluation, and one contiguous batched observation buffer.- Native crop, resize, grayscale, max-pool, no-op reset, sticky actions, reward clipping, and a persistent C++ worker pool for batched stepping.
- Native C++ screen processing and fused
step_repeat_and_process()for the regular single-env API. STABLE_RETRO_DISABLE_AUDIO=1for RGB-only agents.scripts/benchmark_vec_env.pyfor native-vector throughput sweeps.
In local Mario benchmarks using SuperMarioBros-Nes-v0, the native vector path
is the supported runtime for SB3-style rollouts. It keeps the hot vector-env
state machine in C++ so rollout steps no longer cross Python once per
environment.
Use scripts/benchmark_vec_env.py for standardized native-vector benchmarks.
The default profile is supermario-level1-1, which uses the actual
Level1-1 game state from the stable integration instead of a power-on
State.NONE direct-ROM run:
python scripts/benchmark_vec_env.py --profile supermario-level1-1
Direct-ROM State.NONE benchmarks are only for low-level emulator diagnostics
and require --allow-state-none.
Install
python -m pip install stable-retro-turbo
Use it from Python:
import stable_retro as retro
env = retro.make("Alleyway-GameBoy-v0", render_mode="rgb_array")
RL preprocessing and SB3
For single environments, image preprocessing can still be done inside the env before observations are returned to the caller:
import stable_retro as retro
env = retro.make(
"SuperMarioBros-Nes-v0",
render_mode="rgb_array",
obs_resize=(84, 84),
obs_resize_algorithm="nearest", # nearest, bilinear, or area
obs_grayscale=True,
)
Available image kwargs:
obs_resize=(height, width): resize image observations before they leave the env.obs_resize_algorithm="nearest": choosenearest,bilinear, orarea;nearestis fastest, whileareais downscale-only and does more averaging work.obs_grayscale=True: return grayscale observations with shape(height, width, 1).obs_crop=(top, bottom, left, right): crop pixels before grayscale and resize.frame_skip=4: repeat each selected action inside the env and sum rewards.frame_stack=4: stack recent observations inside the env.maxpool_last_two=True: max-pool the last two skipped image frames.noop_reset_max=30: apply a random number of no-op reset steps.sticky_action_prob=0.25: probabilistically repeat the previous action.reward_clip=True: clip rewards to[-1, 1].
For SB3-style Mario rollouts, use the native vector env directly:
from stable_retro import StableRetroNativeVecEnv
env = StableRetroNativeVecEnv(
"SuperMarioBros-Nes-v0",
num_envs=32,
num_threads=16,
render_mode="rgb_array",
obs_resize=(84, 84),
obs_grayscale=True,
frame_skip=4,
frame_stack=4,
maxpool_last_two=True,
)
StableRetroNativeVecEnv currently targets homogeneous single-player image
rollouts with no movie recording and no screen rotation. It keeps the hot
rollout path in C++ and returns a contiguous NumPy observation batch shaped
(num_envs, height, width, channels * frame_stack).
When possible, image preprocessing and repeated-step processing use native C++
helpers instead of Python image loops. The native path is selected automatically
for single-player image observations with no rotation or movie recording. Set
STABLE_RETRO_DISABLE_NATIVE_IMAGEOPS=1 or
STABLE_RETRO_DISABLE_NATIVE_FUSED_STEP=1 to force the Python fallback while
debugging or benchmarking.
If your agent does not use audio, set STABLE_RETRO_DISABLE_AUDIO=1 before
creating environments. This keeps RGB observations enabled while skipping audio
capture and supported core-side audio generation.
The deprecated compatibility import still works:
import retro
For local development:
git clone https://github.com/tsilva/stable-retro-turbo.git
cd stable-retro-turbo
brew install cmake pkg-config lua@5.4 libzip
python -m pip install -U pip build cibuildwheel pytest pre-commit
python -m pip install -e .
Commands
python -m pip install stable-retro-turbo # install the published package
python -m pip install -e . # build and install this checkout
python -m build --wheel # build a local wheel
python -m cibuildwheel . --output-dir wheelhouse # build release-style wheels
pytest # run Python tests
pre-commit run --all-files # run repository hooks
cmake . && make -j2 && make -j2 -f tests/Makefile && ctest --progress --verbose
python scripts/benchmark_vec_env.py --profile supermario-level1-1
Notes
- Published wheels target Apple Silicon
arm64on macOS14.0+andx86_64on Linux, for Python3.14. - Package versions follow the upstream
stable-retrobase version with this fork's patch number as a PEP 440 post-release suffix, for example1.0.0.post1. - The public wheel build includes Game Boy, NES, SNES, and Sega Master System cores:
gambatte,fceumm,snes9x, andgenesis_plus_gx. - CapnProto is disabled in the public wheel build path.
- SNES on Apple Silicon uses an automatic Rosetta helper because the native arm64
snes9xpath is not stable across the bundled integrations. - If Rosetta is not installed yet, install it once:
softwareupdate --install-rosetta --agree-to-license
- Release automation builds macOS arm64 and Linux x86_64 wheels, publishes them to PyPI, and attaches matching wheel files to GitHub Releases.
- See
PUBLISHING.mdfor the release checklist. - Upstream API and integration docs are still useful:
docs/supported_emulators.md,docs/supported_games.md, anddocs/macos_installation.md.
Architecture
License
MIT. Bundled third-party notices are listed in LICENSES.md.
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 Distributions
Built Distributions
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 stable_retro_turbo-1.0.0.post4-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: stable_retro_turbo-1.0.0.post4-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 103.1 MB
- Tags: CPython 3.14, manylinux: glibc 2.26+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9bcfb534bc0c6e52094819c08ec58486b10090f23e86b5bc7608dd4fd48e9b2
|
|
| MD5 |
deaecc626c9a5c64abd7f254434f872b
|
|
| BLAKE2b-256 |
86676e561c29511d6da549da8015c4ab951aa8e49ad36bf4647d43e341a35550
|
File details
Details for the file stable_retro_turbo-1.0.0.post4-cp314-cp314-macosx_14_0_arm64.whl.
File metadata
- Download URL: stable_retro_turbo-1.0.0.post4-cp314-cp314-macosx_14_0_arm64.whl
- Upload date:
- Size: 101.3 MB
- Tags: CPython 3.14, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d18a2264ea52a6110af719c2bbce73a42cff1653a73f23ce341bec5407175e91
|
|
| MD5 |
3f35372cfc6f977b6444dd1039084dbd
|
|
| BLAKE2b-256 |
51dc69580ddc33ddbffebe931ff73464d3facd013c2064a5772671e394adec87
|