Repository navigation
Add sync-free masked autoreset and CUDA graph capture of the reset segment - #2604
Closed
Cudrix-dev wants to merge 3 commits into
Closed
Cudrix-dev wants to merge 3 commits into
Cudrix-dev wants to merge 3 commits into
Conversation
…gment Opt-in fixed-shape step path for TorchEnv / ManagerBasedRlEnv, built on the unisim torch_graph_capture_scope backend contract: - ResetSelection (base/reset_selection.py): fixed-shape persistent reset mask passed through the env_ids reset APIs. Participants opt in with supports_reset_selection / @reset_selection_capable; the env negotiates support at init_state and names every unsupported participant. A selection is not an index, so unconverted code fails closed. - masked_autoreset: the done-row reset runs every step with no .any() / .nonzero() gate; final_observation is published every step (valid on done rows). Requires defer_finite_validation. - Deferred fail-closed checks: TorchEnv.require() latches named device verdicts; reset-state mask checks and backend tensor validation join the single poll_finite_validation host read. - persistent_step_buffers: working obs/reward/done carriers updated in place with copy_(); a publication ring (published_buffer_depth, default 2) keeps a consumer's held observation valid across the next step. - autoreset_cuda_graph: AutoresetGraph captures the whole masked reset body (managers + backend reset) into one torch.cuda.graph inside the backend's external capture scope, registers the manager RNG generator, and replays recorded host transitions (base/host_transitions.py) after each replay. No eager epilogue. All flags default off; existing behavior is unchanged.
G1MotionTracking (mjwarp) now runs with masked_autoreset and autoreset_cuda_graph: no reported blockers, no host sync in the reset segment, and the graph captures and replays on real MJWarp. - MotionCommand: declares ResetSelection support. Under a selection (or an env running masked_autoreset) _resample_command always dispatches its full-width sampling instead of probing the mask with .any(); the robot cache step stamp is a declared host transition. - MotionJointPositionAction, JointPositionAction, the motion body reward terms and the anchor/body height terminations declare support. - MotionSampler: the top-1 sampling probability uses amax instead of indexing with the device argmax (a host read). - supports_reset_selection: a declaration only counts at or below the class that defines the effective reset(), so an override that was not converted is reported as a blocker instead of inheriting its parent's opt-in. - Reward/termination blockers name the term instead of the object repr.
Downstream unit tests build env shells with __new__ and set only the attributes they exercise. Declare the fixed-shape step state at class level so such shells keep the ordinary step and state-publication path instead of failing with AttributeError.
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
Adds an opt-in, fixed-shape step path for
TorchEnv/ManagerBasedRlEnv. It removes the per-step host synchronizations of the done-row reset and can capture the reset segment as one CUDA graph. All flags default to off, so existing behavior is unchanged.Requires the unisim backend contract
torch_graph_capture_scope(unisim PR: ).Fixed-shape reset selection
ResetSelection(unilab/base/reset_selection.py) is a persistent full-width bool mask passed through the existingenv_idsreset APIs.supports_reset_selection = Trueor@reset_selection_capable.fill_rows_andassign_rows_cover the common masked writes.init_stateand names every unsupported participant (reset_selection_blockers()).reset(). A subclass that overridesresetwithout converting it is reported as a blocker; it does not silently inherit the parent's opt-in.Env flags
masked_autoreset:.any()/.nonzero()gate;final_observationis published every step and is valid on done rows;defer_finite_validation.TorchEnv.require(ok, name, message)latches a named device verdict;poll_finite_validationhost read.persistent_step_buffers:published_buffer_depth, default 2) keeps a consumer's held observation valid across the next step.autoreset_cuda_graph, withautoreset_graph_warmupandautoreset_graph_capture_mode:AutoresetGraphcaptures the whole masked reset body (managers plus backend reset) into onetorch.cuda.graph, inside the backend's external capture scope;unilab/base/host_transitions.py) replay after each launch;Managers and buffers
CircularBufferandDelayBufferreset through the mask.__new__) test shells keep the ordinary path.G1 motion tracking opts in
MotionCommand:masked_autoreset, always dispatches its full-width sampling instead of probing the mask;MotionJointPositionAction,JointPositionAction, the motion body reward terms and the anchor/body height terminations declare support.MotionSampler's top-1 probability usesamax; indexing with the deviceargmaxcaused a host read.Results (G1MotionTracking, MJWarp, 4096 envs, RTX 6000D)
masked_autoresetmasked_autoreset+persistent_step_buffers+autoreset_cuda_graphTests
tests/envs/test_fixed_shape_autoreset.py: negotiation, the MRO opt-in rule, masked reset equivalence, publication ring lifetime, deferred verdicts, and graph capture/replay with host transitions.tests/tasks/test_g1_motion_fixed_shape.py, including a slow real-MJWarp G1 graph test.