[Doc] Memory-efficient RL training tutorial + cross-refs#3745
Open
vmoens wants to merge 1 commit into
Open
Conversation
New tutorial under tutorials/sphinx-tutorials/memory_efficient_rl.py that ties together the three recent memory-efficiency PRs: - compact_obs flag on the collector (pytorch#3742) - NextStateReconstructor RB transform (pytorch#3743) - NaN-safe value-estimator forward (pytorch#3744) The tutorial walks through: - Where the observation memory goes and why TorchRL keeps both obs and ("next", obs) by default (bootstrap targets, MultiStep n-step fallback) - Knob 1: SyncDataCollector(compact_obs=True) — halves the obs footprint at the producer side - Knob 2: NextStateReconstructor — rebuilds ("next", obs) at sampling time, NaN at trajectory ends - Knob 2.5: ValueEstimatorBase._sanitize_next_obs_nan keeps GAE/TD targets numerically defined - When NOT to take this path: MultiStepTransform, truncated transitions where the V(obs[t]) ≈ V(real_next_obs) approximation is unacceptable - Knob 3: LazyMemmapStorage for buffers larger than VRAM - Knob 4: SliceSampler + scan/Triton recurrent backends for padding-free sequence training - End-to-end pipeline snippet The tutorial runs end-to-end on CPU (CartPole-v1, 200 frames) and reports concrete byte-level savings from `td.bytes()`. Cross-references added to: - SyncDataCollector / MultiSyncCollector / MultiAsyncCollector (`compact_obs` docstring) — pointers to NextStateReconstructor, the value-estimator sanitizer, MultiStep incompatibility note, and the new tutorial. - NextStateReconstructor — `.. seealso::` block to compact_obs, the sanitizer, MultiStep incompatibility, and the tutorial. - ValueEstimatorBase._sanitize_next_obs_nan — `.. seealso::` to compact_obs, NextStateReconstructor, and the tutorial. docs/source/index.rst — register the new tutorial under "Basics". Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3745
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 2 New Failures, 2 PendingAs of commit bf4a3f6 with merge base cc31dc3 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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
Ties together the three recently-merged memory-efficiency PRs into a
single story:
compact_obscollector flag ([Performance] Add compact_obs flag to DataCollector #3742)NextStateReconstructorRB transform ([Feature] NextStateReconstructor RB transform #3743)Two parts:
1. Runnable Sphinx-gallery tutorial at
tutorials/sphinx-tutorials/memory_efficient_rl.py. Sections:td.bytes()numbers)("next", obs)is kept by default — bootstrap target attrajectory ends,
MultiStepTransformn-step fallbackSyncDataCollector(compact_obs=True)NextStateReconstructorwith the traj_id + done contract(
_sanitize_next_obs_nan), GAE finite everywhereMultiStepTransformincompatibility,the
V(obs[t]) ≈ V(real_next_obs)approximation at truncated steps,and how
shifted=TrueinteractsLazyMemmapStoragefor buffers ≥ VRAMSliceSampler+ the new"scan"/"triton"recurrent backends for padding-free sequence training
Runs end-to-end on CPU (CartPole-v1, 200 frames; <2s wall) and reports
the byte-level savings concretely from
td.bytes().2. Docstring cross-references so a reader landing on any of the
three new APIs finds the other two:
Collector(compact_obs=…)(and the multi-process collectors):pointers to
NextStateReconstructor, the value-estimatorsanitizer, the
MultiStepTransformincompatibility note, and thenew tutorial.
NextStateReconstructor:.. seealso::block coveringcompact_obs, the sanitizer,MultiStepTransform, and thetutorial.
ValueEstimatorBase._sanitize_next_obs_nan:.. seealso::block to
compact_obs,NextStateReconstructor, and thetutorial.
docs/source/index.rstregisters the new tutorial under "Basics".Test plan
reported, NaN at slice boundaries confirmed to coincide with
trajectory boundaries, GAE advantage finite everywhere, memmap
roundtrip works).
(verified by reading the rendered class docstrings via
Collector.__doc__etc.).🤖 Generated with Claude Code