[BugFix] Bound direct off-policy replay collection - #4018
Open
vmoens wants to merge 2 commits into
Open
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4018
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 85023be with merge base 702709c ( 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
force-pushed
the
codex/ray-direct-replay-frame-accounting
branch
from
July 16, 2026 09:22
938097f to
2d815f3
Compare
vmoens
force-pushed
the
codex/ray-direct-replay-frame-accounting
branch
from
July 16, 2026 09:31
2d815f3 to
eddb876
Compare
vmoens
force-pushed
the
codex/ray-direct-replay-frame-accounting
branch
from
July 16, 2026 09:58
eddb876 to
b0acf37
Compare
vmoens
force-pushed
the
codex/ray-direct-replay-frame-accounting
branch
from
July 16, 2026 10:38
b0acf37 to
8fb5f54
Compare
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
total_framesbefore launching actor calls, preventing direct replay writes after the collection targetwrite_count, preserving multidimensional replay items[B, T] -> [B * T]collector postprocessing for standard feed-forward off-policy workloads without imposing that layout on general replay usageRoot causes
Frame accounting versus replay item accounting
A vectorized collector can emit a rollout with batch shape
[num_envs, time]. A replay buffer may intentionally store that rollout asnum_envssequence items, or a workload may flatten it intonum_envs * timetransition items before insertion. Both layouts are valid.Replay
write_countcounts stored items, so it is not necessarily a transition counter. Using it to drive Trainer progress made collection accounting depend on replay layout: grouped sequence storage advancedwrite_countbynum_envswhile the collector had producednum_envs * timetransitions.The Trainer now uses
collector.collected_framesfor asynchronous progress and termination. Replaywrite_countretains its normal item-count semantics. Regression coverage runs the same Ray Trainer with both grouped[N, T]samples and flat[N]samples and verifies that each completes at the same collected-frame target.DQN, SAC, DDPG, and TD3 in the validation suite still explicitly flatten collector rollouts before direct insertion because those particular workloads use transition replay. That policy remains in the workload configuration rather than the generic Trainer.
In-flight collection
The asynchronous iterator previously launched one replacement task after every completed batch. Once the target was reached, it waited for the remaining tasks to finish. Direct-replay collectors write inside those actor calls, so every in-flight call completed an extra replay insertion even though its result was never yielded.
The iterator now includes in-flight batches when deciding whether another actor call can be scheduled. This bounds both collected frames and direct replay writes without constraining the shape of each stored replay item.
Pre-bound distributed transport
When
extend_specandsample_specare supplied, the replay owner establishes the distributed payload endpoints during startup. The lazy client nevertheless used the first extend payload and first sampled result to call the Ray bootstrap methods. The actor did not need those payloads once the schemas were bound, but Ray had already serialized and transferred them.The lazy client now asks the owner for an existing endpoint first. It retains first-use payload bootstrap as the fallback when no explicit schema was supplied. This keeps dynamic schemas working while avoiding a full Ray transfer of the initial large collector and learner batches.
Tests
python -m pytest -q test/rb/test_rb_distributed.py::TestRayRB::test_prebound_distributed_replay_skips_payload_bootstrap test/rb/test_rb_distributed.py::TestRayRB::test_ray_replay_with_prebound_gloo_transport test/rb/test_rb_distributed.py::TestRayRB::test_ray_replay_with_gloo_transport test/test_distributed.py::TestRayCollector::test_async_ray_collector_does_not_write_unreserved_batches test/test_distributed.py::TestRayCollector::test_async_trainer_tracks_frames_independently_of_replay_shape test/test_distributed.py::TestRayCollector::test_dqn_trainer_ray_backend test/test_distributed.py::TestRayCollector::test_offpolicy_trainer_ray_backend test/test_distributed.py::TestRayCollector::test_ray_collector_pause_drains_and_resumes test/test_distributed.py::TestRayCollector::test_distributed_collector_sync(13 passed)pre-commit run --files torchrl/collectors/distributed/ray.py torchrl/data/replay_buffers/ray_buffer.py torchrl/data/replay_buffers/replay_buffers.py torchrl/trainers/trainers.py test/rb/test_rb_distributed.py test/test_distributed.py