[Feature] Implement Compare-Version facility for update_if_present - #4049
Open
coder-jayp wants to merge 7 commits into
Open
[Feature] Implement Compare-Version facility for update_if_present#4049coder-jayp wants to merge 7 commits into
coder-jayp wants to merge 7 commits into
Conversation
Executable spec for step 1 of the conditional replay-update RFC: round-robin writers stamp each slot with an int64 generation exposed via writer.generations_of(index); first write is generation 0, every slot reuse increments it, empty() never revives old handles, and generations persist through state_dict and dumps with legacy checkpoints still loading. Sampling exposes the stamps as an index_generation info entry / TensorDict key aligned with index. Tests are expected to fail until the implementation lands.
Round-robin writers now stamp each storage slot with an int64 generation counter: the first write of a slot has generation 0 and every round-robin reuse increments it, so a captured (index, generation) pair identifies one specific record and becomes detectably stale once the slot is recycled or the buffer is emptied. Generations are exposed through writer.generations_of(index), persist through state_dict and dumps/loads (legacy checkpoints still load), and are reported at sampling time as an index_generation info entry, which TensorDict buffers surface as a sample key next to index. Writers that do not track reuse report -1. Positional write_at and raw __setitem__ writes patch records in place and do not advance generations. A wraparound-heavy extend benchmark covers the hot-path cost. First step of the conditional replay-update RFC (pytorch#4040). Addresses pytorch#4041.
Executable spec for step 2 of the conditional replay-update RFC: rb.update_if_present(index=, generation=, patch=) applies every patch key to records whose (index, generation) is still live, skips reused or emptied slots without touching their content, and returns a result with an updated mask aligned to the input order plus updated/stale counts. The whole patch is validated before any write (KeyError for unknown keys, ValueError for shape or dtype mismatches, storage untouched in both cases), handles survive repeated updates, nested keys are supported, ListStorage raises a capability error, multidim storages round-trip, sampled handles flow straight into the call, and a concurrent writer/updater stress test pins non-torn multi-key visibility. RayReplayBuffer delegates the call to the actor. Tests are expected to fail until the implementation lands.
…itional updates Adds a best-effort conditional mutation API for stored replay fields. update_if_present(index=, generation=, patch=) applies a patch only to records whose (index, generation) pair still matches the writer's current slot generation, skipping records whose slot was recycled or emptied instead of corrupting them, and returns a ConditionalUpdateResult with a per-record updated mask plus updated/stale counts. The whole patch is validated (key existence, shape, dtype) before any write; validation failures leave storage untouched. The generation comparison and the patch write share one replay-lock acquisition, giving per-record atomicity against concurrent extends, and updating a record does not consume its handle. Tensor storages advertise supports_conditional_update; unsupported backends such as ListStorage raise a capability error instead of performing an unsafe raw-index write. RayReplayBuffer delegates the call to the actor in a single RPC (validation and write run inside the actor under its own lock); the distributed transport raises a clear capability error. Nested keys and multidimensional storages are supported. Second step of the conditional replay-update RFC. Closes pytorch#4040.
Executable contract for the optional versioning extension of pytorch#4040: activation requires version_key and version together; generation-live records apply iff version > stored (require_newer=True) or >= stored (default); accepted records get the version written back atomically with the patch; version_key may not appear in the patch; staleness takes precedence and updated/version_rejected/stale partition the batch; rejection is deterministic and side-effect free; version accepts a scalar or a per-record int64 tensor; validation failures leave storage and the version column untouched; without the facility behavior is unchanged and version_rejected is None. Tests are expected to fail until the implementation lands.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4049
Note: Links to docs will display an error until the docs builds have been completed. ❌ 41 New Failures, 18 Unrelated Failures, 1 Unclassified FailureAs of commit b2f4b09 with merge base ae421b9 ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
BROKEN TRUNK - The following jobs 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. |
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.
Description
Implements the optional compare-version facility inside
ReplayBuffer.update_if_present. This allows asynchronous updates to be safely ignored if they carry an older model/state version than what is currently stored in a live Replay Buffer slot.Motivation and Context
This prevents an older asynchronous computation from overwriting a newer refresh of mutable replay fields. It guarantees generation-safe and version-safe updates.
Part of #4040. (Builds on top of the base API drafted in #4043).
Types of changes
Checklist