-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Change resource bookkeeping to account for machine precision. #4533
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
22 commits
Select commit
Hold shift + click to select a range
5d0983c
Create internal representation class
williamma12 4131d53
Consolidate error messages
williamma12 2e712f1
linting and fix test
williamma12 2f25c12
linting
williamma12 bf1eae4
called GetResourceMap instead of GetResourceAmountMap
williamma12 bad97fd
Remove print statements
williamma12 3e4b352
resolve comments
williamma12 c101484
linting
williamma12 df424da
Change test to loop 10 sec instead of 10 min
williamma12 1d0140a
Resolve comments
williamma12 3aa513d
Try undoing scheduling_policy.cc change
williamma12 67021d6
Clean up code
williamma12 17c65ad
linting
williamma12 c72d3c7
revert unnecessary change
williamma12 cf1140b
Refine comment to make it clearer
williamma12 449ace4
Passing zero resource deletion test
williamma12 411f7f3
Fix subtractResources
williamma12 38c467e
Change empty resourceSet to print {}
williamma12 143550f
linting
williamma12 c239322
linting
williamma12 c6253fd
linting and comments
williamma12 18c075b
more linting
williamma12 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -864,6 +864,71 @@ def method(self): | |
| assert ray.get([id1, id2, id3, id4]) == [0, 1, "test", 2] | ||
|
|
||
|
|
||
| def test_many_fractional_resources(shutdown_only): | ||
| ray.init(num_cpus=2, num_gpus=2, resources={"Custom": 2}) | ||
|
|
||
| @ray.remote | ||
| def g(): | ||
| return 1 | ||
|
|
||
| @ray.remote | ||
| def f(block, accepted_resources): | ||
| true_resources = { | ||
| resource: value[0][1] | ||
| for resource, value in ray.get_resource_ids().items() | ||
| } | ||
| if block: | ||
| ray.get(g.remote()) | ||
| return true_resources == accepted_resources | ||
|
|
||
| # Check that the resource are assigned correctly. | ||
| result_ids = [] | ||
| for rand1, rand2, rand3 in np.random.uniform(size=(100, 3)): | ||
|
||
| resource_set = {"CPU": int(rand1 * 10000) / 10000} | ||
| result_ids.append(f._remote([False, resource_set], num_cpus=rand1)) | ||
|
|
||
| resource_set = {"CPU": 1, "GPU": int(rand1 * 10000) / 10000} | ||
| result_ids.append(f._remote([False, resource_set], num_gpus=rand1)) | ||
|
|
||
| resource_set = {"CPU": 1, "Custom": int(rand1 * 10000) / 10000} | ||
| result_ids.append( | ||
| f._remote([False, resource_set], resources={"Custom": rand1})) | ||
|
|
||
| resource_set = { | ||
| "CPU": int(rand1 * 10000) / 10000, | ||
| "GPU": int(rand2 * 10000) / 10000, | ||
| "Custom": int(rand3 * 10000) / 10000 | ||
| } | ||
| result_ids.append( | ||
| f._remote( | ||
| [False, resource_set], | ||
| num_cpus=rand1, | ||
| num_gpus=rand2, | ||
| resources={"Custom": rand3})) | ||
| result_ids.append( | ||
| f._remote( | ||
| [True, resource_set], | ||
| num_cpus=rand1, | ||
| num_gpus=rand2, | ||
| resources={"Custom": rand3})) | ||
| assert all(ray.get(result_ids)) | ||
|
|
||
| # Check that the available resources at the end are the same as the | ||
| # beginning. | ||
| stop_time = time.time() + 10 | ||
| correct_available_resources = False | ||
| while time.time() < stop_time: | ||
| if ray.global_state.available_resources() == { | ||
| "CPU": 2.0, | ||
| "GPU": 2.0, | ||
| "Custom": 2.0, | ||
| }: | ||
| correct_available_resources = True | ||
| break | ||
| if not correct_available_resources: | ||
| assert False, "Did not get correct available resources." | ||
|
|
||
|
|
||
| def test_get_multiple(ray_start_regular): | ||
| object_ids = [ray.put(i) for i in range(10)] | ||
| assert ray.get(object_ids) == list(range(10)) | ||
|
|
@@ -2126,20 +2191,24 @@ def f(): | |
| ray.get(results) | ||
|
|
||
|
|
||
| # TODO: 5 retry attempts may be too little for Travis and we may need to | ||
| # increase it if this test begins to be flaky on Travis. | ||
| def test_zero_capacity_deletion_semantics(shutdown_only): | ||
| ray.init(num_cpus=2, num_gpus=1, resources={"test_resource": 1}) | ||
|
|
||
| def test(): | ||
| resources = ray.global_state.available_resources() | ||
| MAX_RETRY_ATTEMPTS = 5 | ||
| retry_count = 0 | ||
|
|
||
| while resources and retry_count < 5: | ||
| while resources and retry_count < MAX_RETRY_ATTEMPTS: | ||
| time.sleep(0.1) | ||
| resources = ray.global_state.available_resources() | ||
| retry_count += 1 | ||
|
|
||
| if retry_count >= 5: | ||
| raise RuntimeError("Resources were available even after retries.") | ||
| if retry_count >= MAX_RETRY_ATTEMPTS: | ||
| raise RuntimeError( | ||
| "Resources were available even after five retries.") | ||
|
|
||
| return resources | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.