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] Make Episode.to_numpy optional at end of EnvRunner.sample() (renamed from finalize()). #49800

Merged

Conversation

sven1977
Copy link
Contributor

Make Episode.to_numpy() optional at end of EnvRunner.sample() (renamed from finalize()).

  • Renamed Episode.finalize() -> to_numpy(); Renamed Episode.is_finalized -> is_numpy.
  • Optionally keep episodes at the end of a EnvRunner.sample() in list format, instead of numpy'izing (fka: finalizing) them.
  • Default remains to convert to numpy (no change in current behavior).
  • Keeping episodes in list format might yield a performance advantage for a) off-policy algos that have to concatenate episode chunks into a buffer (concatenation is expensive for numpy'ized episodes) and b) certain connector operations, like zero-padding.
  • So far, the advantages seem to be minor (which is why we leave the default behavior as-is for now), but more experiments need to be done to come to a conclusion about what the best default setting should be.

Why are these changes needed?

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 added 9 commits May 27, 2024 09:44
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>
@sven1977 sven1977 added rllib RLlib related issues rllib-newstack rllib-envrunners Issues around the sampling backend of RLlib labels Jan 13, 2025
Copy link
Collaborator

@simonsays1980 simonsays1980 left a comment

Choose a reason for hiding this comment

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

LGTM. I like this new naming. Imo it tells more clearly what we do there. One thing: Could you check the OfflinePreLearner and see, if there the finalize needs to be changed as well?

@@ -325,6 +325,7 @@ def __init__(self, algo_class: Optional[type] = None):
self.num_gpus_per_env_runner = 0
self.custom_resources_per_env_runner = {}
self.validate_env_runners_after_construction = True
self.episodes_to_numpy = False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

@sven1977
Copy link
Contributor Author

LGTM. I like this new naming. Imo it tells more clearly what we do there. One thing: Could you check the OfflinePreLearner and see, if there the finalize needs to be changed as well?

I think I went through all the code. But let me check again ...

@sven1977
Copy link
Contributor Author

LGTM. I like this new naming. Imo it tells more clearly what we do there. One thing: Could you check the OfflinePreLearner and see, if there the finalize needs to be changed as well?

I think I went through all the code. But let me check again ...

Ah, yeah, fixed it in the docs ...

Signed-off-by: sven1977 <svenmika1977@gmail.com>
@sven1977 sven1977 requested review from maxpumperla and a team as code owners January 13, 2025 09:24
@sven1977 sven1977 enabled auto-merge (squash) January 13, 2025 09:24
@github-actions github-actions bot disabled auto-merge January 13, 2025 09:24
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Jan 13, 2025
@sven1977 sven1977 enabled auto-merge (squash) January 13, 2025 09:25
…_accelerate

Signed-off-by: sven1977 <svenmika1977@gmail.com>

# Conflicts:
#	rllib/algorithms/algorithm_config.py
@github-actions github-actions bot disabled auto-merge January 13, 2025 14:02
…ot_finalize_episodes_sent_to_buffer

Signed-off-by: sven1977 <svenmika1977@gmail.com>

# Conflicts:
#	rllib/utils/replay_buffers/episode_replay_buffer.py
@sven1977 sven1977 enabled auto-merge (squash) January 13, 2025 14:20
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@github-actions github-actions bot disabled auto-merge January 13, 2025 16:10
@sven1977 sven1977 enabled auto-merge (squash) January 13, 2025 17:32
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@github-actions github-actions bot disabled auto-merge January 14, 2025 09:31
@sven1977 sven1977 enabled auto-merge (squash) January 14, 2025 09:35
@sven1977 sven1977 merged commit 74bc097 into ray-project:master Jan 14, 2025
6 checks passed
@sven1977 sven1977 deleted the do_not_finalize_episodes_sent_to_buffer branch January 14, 2025 11:24
srinathk10 pushed a commit that referenced this pull request Feb 2, 2025
anyadontfly pushed a commit to anyadontfly/ray that referenced this pull request Feb 13, 2025
…)` (renamed from `finalize()`). (ray-project#49800)

Signed-off-by: Puyuan Yao <williamyao034@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests rllib RLlib related issues rllib-envrunners Issues around the sampling backend of RLlib rllib-newstack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants