[Feature] Implement Compare-Version facility for update_if_present
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).
- [x] I have raised an issue to propose this change (required for new features and bug fixes)
Types of changes
- [x] New feature (non-breaking change which adds core functionality)
Checklist
- [x] I have read the CONTRIBUTION guide (required)
- [ ] My change requires a change to the documentation.
- [x] I have updated the tests accordingly (required for a bug fix or a new feature).
- [ ] I have updated the documentation accordingly.
:link: Helpful Links
:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4049
- :page_facing_up: Preview Python docs built from this PR
Note: Links to docs will display an error until the docs builds have been completed.
:white_check_mark: No Failures
As of commit 407ae4ed88d0870374152b74e5fd1a9311680516 with merge base d7659c781a55f7680a025f16015064b0a8169344 ():
:green_heart: Looks good so far! There are no failures yet. :green_heart:
This comment was automatically generated by Dr. CI and updates every 15 minutes.
Reviewed the rebased head 407ae4ed88d0, including the latest hardening commit. The current implementation normalizes nested key spellings, reads/writes full coordinates for multidimensional storage, resolves duplicate handles by highest incoming version with last-row tie-breaking, and keeps stale/version-rejected masks disjoint even for an all-stale call. I ran the focused core suite locally: 29 update_if_present tests passed, including concurrency, duplicates, multidimensional storage, nested keys, and checkpoint round trips. The Ray delegation test was collected but skipped because Ray is unavailable here; CUDA/MPS device paths were also not exercised locally. I did not find a blocking issue in the current diff, with those distributed/device paths as the remaining validation risk.
@vmoens Thanks for the thorough review and for adding that final hardening commit on top to handle the multidimensional and distributed edge cases