-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[rllib] Replace ray.get() with ray_get_and_free() to optimize memory usage #4586
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f77c861
wip
ericl 9b74f05
comment
ericl b6e485b
ars
ericl 050b179
fix local mode
ericl e2284b2
fix internal
ericl a848618
add max queue size
ericl 092443b
free
ericl 411cd15
Merge remote-tracking branch 'upstream/master' into save-memory
ericl 8b3dfd3
py2
ericl 85a0597
Update memory.py
ericl fa839c7
Merge remote-tracking branch 'upstream/master' into save-memory
ericl d968d25
typo
ericl 5b13bef
Merge branch 'save-memory' of github.com:ericl/ray into save-memory
ericl 6f1f5cb
comment
ericl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,47 @@ | |
| from __future__ import print_function | ||
|
|
||
| import numpy as np | ||
| import time | ||
|
|
||
| import ray | ||
|
|
||
| FREE_DELAY_S = 10.0 | ||
| MAX_FREE_QUEUE_SIZE = 100 | ||
| _last_free_time = 0.0 | ||
| _to_free = [] | ||
|
|
||
|
|
||
| def ray_get_and_free(object_ids): | ||
| """Call ray.get and then queue the object ids for deletion. | ||
|
|
||
| This function should be used whenever possible in RLlib, to optimize | ||
| memory usage. The only exception is when an object_id is shared among | ||
| multiple readers. | ||
|
|
||
| Args: | ||
| object_ids (ObjectID|List[ObjectID]): Object ids to fetch and free. | ||
|
|
||
| Returns: | ||
| The result of ray.get(object_ids). | ||
| """ | ||
|
|
||
| global _last_free_time | ||
| global _to_free | ||
|
|
||
| result = ray.get(object_ids) | ||
| if type(object_ids) is not list: | ||
| object_ids = [object_ids] | ||
| _to_free.extend(object_ids) | ||
|
|
||
| # batch calls to free to reduce overheads | ||
| now = time.time() | ||
| if (len(_to_free) > MAX_FREE_QUEUE_SIZE | ||
| or now - _last_free_time > FREE_DELAY_S): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. batch the free calls to avoid too much overheads |
||
| ray.internal.free(_to_free) | ||
| _to_free = [] | ||
| _last_free_time = now | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| def aligned_array(size, dtype, align=64): | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this is nice