Skip to content

Add reusable RL lifecycle and checkpoint resource hooks - #982

Open
yuecideng wants to merge 1 commit into
mainfrom
codex/assembly-03-rl-runtime
Open

yuecideng wants to merge 1 commit into
mainfrom
codex/assembly-03-rl-runtime

Conversation

@yuecideng

@yuecideng yuecideng commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Make standard RL rollouts, episode evaluation and saved environments reliable across ordinary tasks. This PR targets main and has no dependency on #981 or the assembly toolkit.

  • Preserve owned pre-reset observations for completed rows and bootstrap only real timeouts; hard termination suppresses bootstrap.
  • Infer terminal values only for eligible rows, with evaluation behavior and exact module-mode restoration, including exceptions. GRPO opts out of unused timeout-value inference.
  • Evaluate PPO's clipped actor objective in log space without changing its finite objective or gradients.
  • Add optional balanced per-environment episode quotas, completion/success denominators, Wilson intervals and scalar on_scored_episode records; retain environment-owned on_episode reports.
  • Prepare scenes on owned configurations before World creation and export materialized resources through task-owned hooks. Saved Task Programs retain embodiment skill metadata and correctly bind physical/semantic references after configuration relocation. Synchronize packaging errors on all ranks before resume or training.
  • Share device-reduced metric means between logging sinks, add optional final-target limits for relative joint actions, and group observation functors while preserving public and internally consumed import paths.
  • Remove unused logging wrappers. Assembly-specific resource-path handling stays in the downstream task layer.

Stack

Type of change

  • Bug fix and enhancement.

Validation

Isolated Python 3.12.14 / Torch 2.11 / DexSim 0.6.0rc1 environment, editable imports verified against this worktree:

  • Affected Gym, actions, observations, runtime, evaluation, PPO, resume, CLI and metadata selection: 562 passed, 13 skipped. Includes a real two-process CPU Gloo regression: both ranks receive an export failure, then complete normal training/save/resume communication.
  • GRPO/shared-rollout CPU, policy Task Program and context/API checker selection: 72 passed, 2 deselected.
  • Existing Task Program bridge/policy/state/pour observation regressions: 154 passed, including the observation-facade compatibility paths.
  • Actual wheel/source-free consumers and robot/example packaging: 5 passed.
  • Native CartPole external-rollout integration under Xvfb/Hybrid: 1 passed (physics/data contract, not rendered-pixel quality).
  • The independent runtime has no importable assembly toolkit or assembly benchmark package.
  • Black 26.10.1 (black .), API coverage 4915/4915, context validation, changed Python headers/annotations, skill validation and whitespace checks passed.

Tests extend existing modules; compact/full terminal batches, hard termination, simultaneous termination/truncation, singleton BatchNorm inference and exception recovery, PPO/GRPO consumer selection, and file/inline Task Program snapshot reload close demonstrated gaps. Existing bridge coverage is reused for moved private observation helpers. Other mapped simulation/robot/randomization/data guidance remains accurate; RL lifecycle and observation ownership context was updated.

Focused collection comparison

Completed CPU collection latency, 32 steps without timeouts, FP32 [64,64] Tanh MLPs, one AMD EPYC 9K65 CPU thread, seed 42, five warmups and 15 alternating samples:

Environments Previous #982 median Current median
1 8.91 ms 7.91 ms
64 12.67 ms 10.79 ms
1024 56.92 ms 41.87 ms

Observation/action/reward/done/value tensors match exactly. Persistent rollout storage is unchanged. This measures collection only; GPU performance, CPU transient peak memory and end-to-end training throughput are unmeasured.

Limits

GPU cases are excluded from the CPU qualification. No rendered-pixel quality, NCCL or full task-training qualification is claimed. An initial expanded selection entered the native display initializer without a configured display and aborted; the isolated native external-rollout case subsequently passed with the proper Xvfb/Hybrid setup.

Checklist

@yuecideng yuecideng added enhancement Improvements to existing capabilities; use feature for new capabilities. refactor Structural changes; add breaking when user-visible compatibility changes. gym Environment lifecycle, managers, configuration composition and registration. rl Reinforcement learning algorithms, collectors, trainers and training contracts. labels Nov 4, 2026
@yuecideng
yuecideng marked this pull request as ready for review November 9, 2026 12:22
@yuecideng
yuecideng force-pushed the codex/assembly-03-rl-runtime branch from aa87f5f to 7c5e1f0 Compare November 15, 2026 10:07
@yuecideng
yuecideng changed the base branch from codex/assembly-02-assets to main November 15, 2026 10:07
snapshots = {train_path: trainer._checkpoint_config}
if gym_path is not None:
snapshots[gym_path] = deepcopy(gym_data)
frozen_gym = _freeze_gym_config(gym_data, gym_config or config_path)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve resume compatibility when freezing the saved Gym config

When a run starts with a component-based Gym config and is later resumed with trainer.gym_config pointing to that run's saved configs/gym.yaml, this expansion makes the snapshot incompatible with its own checkpoint. _configure_checkpoints() still stores the original declaration in _checkpoint_context, while _freeze_gym_config() replaces environment.component with fields such as env, physics, and max_episode_steps. checkpoint._validate() compares those raw contexts and raises Incompatible checkpoint configuration, even though both declarations resolve to the same environment.

A focused probe using an absolute component path (to exclude pre-existing relative-path issues) confirms that the base snapshot has no compatibility differences, whereas the new snapshot produces differences at metadata.context.gym.{env,environment,max_episode_steps,physics}. Both snapshots resolve to exactly the original environment. The added snapshot tests only reload the configuration; they do not resume the corresponding checkpoint.

Please use a consistent compatibility identity across the original configuration and exported snapshot, and cover resuming a checkpoint with its saved Gym config.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvements to existing capabilities; use feature for new capabilities. gym Environment lifecycle, managers, configuration composition and registration. refactor Structural changes; add breaking when user-visible compatibility changes. rl Reinforcement learning algorithms, collectors, trainers and training contracts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants