Skip to content

Fix native CPU-env training hang (OMP regions + missing log keys) - #668

Open
IlyaasK wants to merge 1 commit into
PufferAI:5.0from
IlyaasK:fix-native-cpu-env-hangs
Open

Fix native CPU-env training hang (OMP regions + missing log keys)#668
IlyaasK wants to merge 1 commit into
PufferAI:5.0from
IlyaasK:fix-native-cpu-env-hangs

Conversation

@IlyaasK

@IlyaasK IlyaasK commented Aug 27, 2026

Copy link
Copy Markdown

Problem

puffer train hangs indefinitely at init for every CPU-host env in the 5.0 branch when run in a containerized/virtualized environment (reproduced on Thunder Compute: NVIDIA A6000, CUDA 13.0, Ubuntu 22.04, stock build.sh breakout && puffer train --train.total-timesteps=50000; same with cartpole and our pinball env).

Symptoms: env_start completes, then the process spins at ~107% of one core with GPU at 0%, no output, workers futex-waiting. Never reaches the train loop.

Root cause

Two #pragma omp parallel for regions in the CPU-env path:

  1. env_start() — the one-time puf_reset of all envs runs in an OMP region
  2. vec_thread_main() — the per-buffer puf_step loop runs in an OMP region

Both deadlock inside the sandboxed/containerized process (standalone OpenMP works; the deadlock is process-context-specific, e.g. interaction with injected monitoring threads/hardened seccomp). Since region 1 is one-time init and region 2 already runs per-buffer on its own worker thread, serial execution preserves behavior.

Fix

  • Serialize both OMP regions (drop the two pragmas; loops stay identical)
  • Add dict_get_default() to ini.h
  • Guard dashboard/log-history reads (util/*, uptime, agent_steps) with defaults so missing log keys no longer abort training after the first epoch

Verification

Before: hang after env_setup (marker-traced; env-independent).
After: full epoch progress on Thunder Compute, live dashboard, ~80–110K SPS, losses (policy/value/entropy) updating, 200K-step sanity run completes without error.

Related: behaviors validated with stock breakout config too — same marker trace on both envs before the fix.

Two OpenMP regions in the CPU-env path (env_start reset loop and the
per-buffer worker step loop) deadlock inside containerized processes
(observed on Thunder Compute / CUDA 13 / Ubuntu 22.04 with every env
including stock breakout). Serialize both: they are one-time init and
per-buffer stepping, so serial execution is correct and cheap.

Also guard dashboard/log-history reads (util/*, uptime, agent_steps)
with a new dict_get_default so missing log keys no longer abort training.

Repro: build.sh breakout && puffer train --train.total-timesteps=50000
-> hangs after env_setup; this branch completes epochs at ~80-110K sps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant