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; Offline RL] Fix small memory leak in OfflineSingleAgentEnvRunner. #48309

Conversation

simonsays1980
Copy link
Collaborator

@simonsays1980 simonsays1980 commented Oct 29, 2024

Why are these changes needed?

There was a small memory leak that became apparent when recording for a longer time. This leak was mainly due to output_max_rows_per_file too small for the sample size. This PR

  • fixes this small memory leak,
  • fixes a file-naming typo in the last written records when stopping a run
  • adds a new configuration option output_write_remaining_data that defines if the recording buffers in an OfflineSingleAgentEnvRunner should be cleared to disk when stopping recording.
  • changes the recording example to a more realistic use case.

Related issue number

Closes #48025

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 :(

…entEnvRunner'.

Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
@simonsays1980 simonsays1980 added rllib RLlib related issues rllib-system system issues, runtime env, oom, etc rllib-offline-rl Offline RL problems labels Oct 29, 2024
@simonsays1980 simonsays1980 marked this pull request as ready for review October 29, 2024 10:58
@sven1977 sven1977 changed the title [RLlib; Offline RL] - Fix small memory leak in OfflineSingleAgentEnvRunner. [RLlib; Offline RL] Fix small memory leak in OfflineSingleAgentEnvRunner. Oct 29, 2024
@@ -164,6 +164,8 @@ def sample(
# TODO (simon): Find a better way to write these data.
self._samples = self._samples[self.output_max_rows_per_file :]
samples_ds = ray.data.from_items(samples_to_write)
# Delete reference to free memory.
del samples_to_write
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to do this? Python's GC should take care of it when the variable goes out of scope, no?
It also keeps all the data anyways b/c it's just a slice from the self._samples ndarray.

…ric. Furthermore, added another user configuration 'output_write_remaining_data' to decide, if remaining data from the recording buffers of EnvRunners should be written to disk. Finally, updated the recording example to show a more realistic recording use case.

Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
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.

Very nice PR!!

While we are at this, can we convert this into an actual example and add it to the CI? This will bolsert our offline RL documentation efforts.

Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
…Implemented some changes suggested in @sven1977's review.

Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
…ming out in CI tests.

Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
…toscaler tells in CI test errors that resources can not be fulfilled.

Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
… of the corresponding 'EnvRunner'.

Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
…antly due to resource requests.

Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
…but still runs on local and cloud tests.

Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
@sven1977 sven1977 enabled auto-merge (squash) December 2, 2024 08:54
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Dec 2, 2024
@github-actions github-actions bot disabled auto-merge December 2, 2024 12:11
@sven1977 sven1977 merged commit 0e9f3d1 into ray-project:master Dec 2, 2024
5 checks passed
jecsand838 pushed a commit to jecsand838/ray that referenced this pull request Dec 4, 2024
…nner`. (ray-project#48309)

Signed-off-by: Connor Sanders <connor@elastiflow.com>
dentiny pushed a commit to dentiny/ray that referenced this pull request Dec 7, 2024
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Dec 17, 2024
…nner`. (ray-project#48309)

Signed-off-by: ujjawal-khare <ujjawal.khare@dream11.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-offline-rl Offline RL problems rllib-system system issues, runtime env, oom, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RLlib; Offline RL] - SingleAgentOfflineEnvRunner runs into OOM
2 participants