Parallel-env training, compute plan, observation-validation fix#33
Merged
Conversation
The smoke test on 2026-04-30 measured ~91 fps with a single PyBoy env on M3 Max, which would put each 10M-step pilot at ~30 hours and threaten the EWRL deadline. PyBoy is single-threaded CPU-bound, so SubprocVecEnv across multiple cores is the right unlock. scripts/train.py — new --n-envs N flag (default 1). When N==1 the single-env DummyVecEnv path is preserved bit-for-bit. When N>1, build N PokemonRedGymEnv factories and pass them to SubprocVecEnv. Each env writes its Monitor CSV to a rank-suffixed path so parallel envs don't clobber each other's logs. W&B integration, alerts, and callbacks are unchanged — they consume SB3's ep_info_buffer regardless of the vectorisation strategy. scripts/run_pilots.sh — adds --n-envs (default 4) and forwards it to every train.py invocation. Also fixes the default --save-state path from the playbook's incorrect "states/post_intro.state" to the actual filename "states/s0_post_intro.state". At --parallel 3 × --n-envs 4 the pilot grid uses 12 P-cores on the M3 Max — the realistic upper bound that completes 9 pilots in ~33 hours wall-clock. pokemon_red_ai/environment/observations.py — fix a real bug surfaced by the smoke test: validate_observation() assumed a Dict observation space, crashing with "'Box' object has no attribute 'spaces'" on the pixel / symbolic / minimal / screen_only treatments (all single-Box spaces). The error is non-fatal but spammed the log every step, which both polluted training logs and degraded throughput. Now handles Dict and Box correctly; emits a clear error for any other type. paper/compute_plan.md — new operational document projecting compute needs across the 3-paper cascade. Confirms M3 Max gets us through EWRL (M2), maps when cloud becomes uncomfortable (M4 NeurIPS) vs mandatory (M5 TMLR), and lists action triggers for the NCSA ACCESS application (AMC-69) and other grants. Sits alongside compute_ledger (actuals) and analysis_plan (locked protocol). Tests: 8 new tests covering the --n-envs flag, the env factory, and the dispatcher's choice between DummyVecEnv and SubprocVecEnv. All 841 tests pass (was 833). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
amcheste
approved these changes
Apr 30, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three related changes triggered by the 2026-04-30 smoke test result.
1.
scripts/train.py—--n-envs Nparallel-env supportThe smoke test measured ~91 fps on the M3 Max with a single PyBoy env. At that rate each 10M-step pilot would take ~30 hours, putting the 9-pilot EWRL grid at ~270 hours (~11 days) sequential — too long for the 2026-05-25 deadline.
PyBoy is single-threaded CPU-bound, so
SubprocVecEnvacross multiple P-cores is the unlock. This PR adds:--n-envs Nflag (default 1). When N==1 the legacyDummyVecEnvsingle-env path is preserved bit-for-bit._make_vec_envconstructs N picklablePokemonRedGymEnvfactories and passes them toSubprocVecEnv.MonitorCSV to a rank-suffixed path (monitor.0,monitor.1, …) so parallel envs don't clobber each other's logs.ep_info_bufferregardless of vectorisation.Projected throughput on M3 Max: 4 envs → ~250-350 fps, 8 envs → ~500-700 fps.
2.
scripts/run_pilots.sh—--n-envsdefault to 4 + correct save-state path--n-envs N(default4); forwards to everytrain.pyinvocation.states/post_intro.statebut the actual filename isstates/s0_post_intro.state(thes0_prefix comes fromcreate_save_states.py's naming). The smoke test caught this —--save-statesilently fell back to playing the intro from boot, which then failed.--parallel 3 --n-envs 4the grid uses 12 P-cores (the realistic M3 Max max), completing 9 pilots in ~33 hours wall-clock.3.
pokemon_red_ai/environment/observations.py— obs-validation Box fixvalidate_observation()assumed aDictobservation space, crashing with'Box' object has no attribute 'spaces'on every step for the single-Box treatments (pixel,symbolic,minimal,screen_only). Non-fatal but spammed the log every step, both polluting training output and degrading throughput. Now handlesDictandBoxcorrectly; clear error message for any other type.4.
paper/compute_plan.md— new operational docProjects compute needs across the 3-paper cascade (EWRL / NeurIPS workshop / TMLR), maps when cloud becomes uncomfortable vs mandatory, and lists action triggers for the NCSA ACCESS application (Linear AMC-69). Sits alongside
compute_ledger.md(actuals) andanalysis_plan.md(locked protocol).Test plan
--n-envsflag, the env factory (per-rank monitor paths, kwarg passthrough), and the dispatcher's choice betweenDummyVecEnvandSubprocVecEnvscripts/run_pilots.sh --rom PokemonRed.gb --dry-runshows--n-envs 4and--save-state states/s0_post_intro.statein every emitted command--n-envs 4to measure real speedup (next step on the user's machine)Out of scope
pokemon_red_ai/game/controls.py(visible during the broken--save-statefallback path) is real but doesn't affect pilot runs that load a save state correctly. File for a separate PR.game/hp_ratio_mean = 5290anomaly observed in the smoke-test W&B output (HP ratio should be 0–1). Separate metric-reporting bug; non-blocking for pilots.🤖 Generated with Claude Code