[Feature] Add flat replay writes to collectors - #4020
Open
vmoens wants to merge 3 commits into
Open
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4020
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 3794707 with merge base f2a2337 ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
vmoens
marked this pull request as ready for review
July 16, 2026 12:26
- Raise TypeError when flatten_data=True is passed without a replay buffer (Collector, multi-process collectors, RayCollector) instead of silently ignoring the flag. - Use setdefault when forwarding flatten_data to Ray collector_kwargs, matching the trajs_per_batch convention. - Comment the conditional flatten kwargs in _main_async_collector (backward compatibility with custom collector classes) and the LLMCollector flatten_data attribute coupling in _postproc. - Document that trajs_per_batch supersedes flatten_data and that fake_tensordict() returns flat data when flattening is active. - Add tests: missing-buffer TypeError for all collector entry points, postproc runs on the batched rollout before flattening, and config forwarding via the raised error. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
vmoens
force-pushed
the
codex/ray-flatten-replay-data
branch
from
July 16, 2026 13:44
df559de to
2c7c3c5
Compare
# Conflicts: # docs/source/reference/collectors_replay.rst # torchrl/collectors/distributed/ray.py # torchrl/trainers/algorithms/configs/collectors.py
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
flatten_datacollector argument that writes batched rollouts to 1-D replay storage with one reshape and one extendMotivation
Batched environments produce
[N, T]rollouts. Direct replay writes currently preserve that batch shape, so 1-D storage recordsNitems with length-Tpayloads instead ofN * Ttransitions. This makes transition sampling and frame accounting awkward, particularly for Ray-backed collectors.With
flatten_data=True, collectors reshape the rollout once immediately before replay insertion, preserving one replay-bufferextendcall while storing individual transitions.Compatibility
The option defaults to
False, so existing multidimensional replay-buffer layouts are unchanged. The deprecatedextend_buffer=Falsepath is rejected with flattening, and paddedsplit_trajs=Trueoutput remains separate from flat replay writes.Testing
pre-commit run --files <changed files>python -m pytest test/test_collectors.py::TestCollectorRB -q(19 passed, 25 skipped)python -m pytest test/test_collectors.py::TestTrajsPerBatchReplayBuffer -q(28 passed)Ray and config regression tests were added but not executed locally because their optional dependencies were unavailable.