Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RLlib] Implementation of MultiAgentEpisodeReplayBuffer for the new API stack. #44450

Merged

Conversation

simonsays1980
Copy link
Collaborator

@simonsays1980 simonsays1980 commented Apr 3, 2024

Why are these changes needed?

With the new API stack and the EnvRunner API came the necessity to define new replay buffers that can work completely on episode objects and stores the latter. This PR proposes the multi-agent version of these EpisodeReplayBuffers.

Sampling works in independent and synchronized replay mode and can use different n-step for each item.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

sven1977 and others added 14 commits March 22, 2024 10:38
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
…d 'add' method. Fixed a minor bug in the 'MultiAgentEpisode' b/c the 'agent_module_ids' mapping was not assigned in the 'MultiAgentEpisode.__init__'. Furthermore, added some tests for the new buffer.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
… either 'independent' or

'synchronized'. There appears to be an inconsistency between the action getters of the SingleAgentEpisode' and the 'MultiAgentEpisode' - the latter retrieves the timestep one earlier than observations.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
@sven1977 sven1977 changed the title Multi agent episode replay buffer for the new API stack [RLlib] Implementation of MultiAgentEpisodeReplayBuffer for the new API stack. Apr 3, 2024
@sven1977 sven1977 marked this pull request as ready for review April 3, 2024 13:22

# Stores indices of module (single-agent) timesteps.
self._module_indices: Dict[str, List[Tuple[int]]] = defaultdict(list)
# Stores for each module the episode indices.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same: improve typehint to DefaultDict[ModuleID, Dict[EpisodeID, int]] ? Is int correct here or should this be a 4-tuple as well?

Let's also above declare what "index" means throughout this entire class:
Something like:
"In this class, we use a global indexing system, where an individual index is a 4-tuple, consisting of 1) ...2)... 3)... 4) ..."

sven1977 and others added 13 commits April 4, 2024 16:11
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
…api' into multi-agent-episode-replay-buffer

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
… and 'SingleAgentEpisode'.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
…ays1980/ray into multi-agent-episode-replay-buffer

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
…a buffer.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
…ts for getters and counters.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
…ixed.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
rllib/BUILD Outdated
@@ -1524,6 +1524,13 @@ py_test(
srcs = ["utils/replay_buffers/tests/test_episode_replay_buffer.py"]
)

oy_test(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> py_test

Copy link
Contributor

@sven1977 sven1977 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the fixes.
I understand we'll uncomment those tests for the new buffer once I have fixed the getter API of MultiAgentEpisode.

rllib/BUILD Outdated Show resolved Hide resolved
sven1977 and others added 5 commits April 8, 2024 13:03
Signed-off-by: Sven Mika <sven@anyscale.io>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
…ays1980/ray into multi-agent-episode-replay-buffer

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
…ts that depend on it.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
… the test for synchronized sampling'.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
@sven1977 sven1977 merged commit 97e910b into ray-project:master Apr 25, 2024
5 checks passed
ryanaoleary pushed a commit to ryanaoleary/ray that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants