-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[Core] Add bundle_label_selector scheduling logic #52988
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
edoakes
merged 12 commits into
ray-project:master
from
ryanaoleary:add-bundle-selector-api
May 30, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a726854
Add bundle_label_selector scheduling logic initial commit
ryanaoleary 90fc136
Merge branch 'master' into add-bundle-selector-api
ryanaoleary f1b8832
Fix BUILD for test
ryanaoleary 029dfdd
Add default bundle_label_selector to PlacementGroupCreationOptions
ryanaoleary fc65425
Merge branch 'master' into add-bundle-selector-api
ryanaoleary 53ca17c
Merge branch 'master' into add-bundle-selector-api
ryanaoleary e35842d
Update src/ray/common/bundle_spec.cc
ryanaoleary dc463ba
Fix comments and library test failures
ryanaoleary 1c965e3
Merge branch 'master' into add-bundle-selector-api
ryanaoleary 03267ae
Update src/ray/common/scheduling/cluster_resource_data.h
ryanaoleary b09cd97
Remove unnecessary field and make arg default
ryanaoleary 1a45660
Merge branch 'master' into add-bundle-selector-api
MengjinYan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import sys | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| import ray | ||
|
|
||
| from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy | ||
| from ray._private.test_utils import placement_group_assert_no_leak | ||
|
|
||
|
|
||
| def test_bundle_label_selector_with_repeated_labels(ray_start_cluster): | ||
| cluster = ray_start_cluster | ||
| num_nodes = 2 | ||
| for _ in range(num_nodes): | ||
| cluster.add_node(num_cpus=4, labels={"ray.io/accelerator-type": "A100"}) | ||
| ray.init(address=cluster.address) | ||
|
|
||
| bundles = [{"CPU": 1}, {"CPU": 1}] | ||
| label_selector = [{"ray.io/accelerator-type": "A100"}] * 2 | ||
|
|
||
| placement_group = ray.util.placement_group( | ||
| name="repeated_labels_pg", | ||
| strategy="PACK", | ||
| bundles=bundles, | ||
| bundle_label_selector=label_selector, | ||
| ) | ||
| ray.get(placement_group.ready()) | ||
|
|
||
| placement_group_assert_no_leak([placement_group]) | ||
|
|
||
|
|
||
| def test_unschedulable_bundle_label_selector(ray_start_cluster): | ||
| cluster = ray_start_cluster | ||
| cluster.add_node(num_cpus=1, labels={"ray.io/accelerator-type": "A100"}) | ||
| cluster.add_node(num_cpus=1, labels={"ray.io/accelerator-type": "TPU"}) | ||
| ray.init(address=cluster.address) | ||
|
|
||
| # request 2 CPUs total, but only 1 CPU available with label ray.io/accelerator-type=A100 | ||
| bundles = [{"CPU": 1}, {"CPU": 1}] | ||
| label_selector = [{"ray.io/accelerator-type": "A100"}] * 2 | ||
|
|
||
| placement_group = ray.util.placement_group( | ||
| name="unschedulable_labels_pg", | ||
| strategy="STRICT_PACK", | ||
| bundles=bundles, | ||
| bundle_label_selector=label_selector, | ||
| ) | ||
|
|
||
| with pytest.raises(ray.exceptions.GetTimeoutError): | ||
| ray.get(placement_group.ready(), timeout=3) | ||
|
|
||
| state = ray.util.placement_group_table()[placement_group.id.hex()]["stats"][ | ||
| "scheduling_state" | ||
| ] | ||
| assert state == "INFEASIBLE" | ||
|
|
||
|
|
||
| def test_bundle_label_selectors_match_bundle_resources(ray_start_cluster): | ||
| cluster = ray_start_cluster | ||
|
|
||
| # Add nodes with unique labels and custom resources | ||
| cluster.add_node( | ||
| num_cpus=1, resources={"resource-0": 1}, labels={"region": "us-west4"} | ||
| ) | ||
| cluster.add_node( | ||
| num_cpus=1, resources={"resource-1": 1}, labels={"region": "us-east5"} | ||
| ) | ||
| cluster.add_node( | ||
| num_cpus=1, resources={"resource-2": 1}, labels={"region": "us-central2"} | ||
| ) | ||
| cluster.wait_for_nodes() | ||
|
|
||
| ray.init(address=cluster.address) | ||
|
|
||
| # Bundle label selectors to match the node labels above | ||
| bundle_label_selectors = [ | ||
| {"region": "us-west4"}, | ||
| {"region": "us-east5"}, | ||
| {"region": "us-central2"}, | ||
| ] | ||
|
|
||
| # Each bundle requests CPU and a unique custom resource | ||
| bundles = [ | ||
| {"CPU": 1, "resource-0": 1}, | ||
| {"CPU": 1, "resource-1": 1}, | ||
| {"CPU": 1, "resource-2": 1}, | ||
| ] | ||
|
|
||
| pg = ray.util.placement_group( | ||
| name="label_selectors_match_resources", | ||
| strategy="SPREAD", | ||
| bundles=bundles, | ||
| bundle_label_selector=bundle_label_selectors, | ||
| ) | ||
| ray.get(pg.ready()) | ||
|
|
||
| @ray.remote | ||
| def get_assigned_resources(): | ||
| return ( | ||
| ray.get_runtime_context().get_node_id(), | ||
| ray.get_runtime_context().get_assigned_resources(), | ||
| ) | ||
|
|
||
| node_id_to_label = { | ||
| node["NodeID"]: node["Labels"]["region"] for node in ray.nodes() | ||
| } | ||
|
|
||
| # Launch one task per bundle to check resource mapping | ||
| for i in range(len(bundles)): | ||
| result = ray.get( | ||
| get_assigned_resources.options( | ||
| num_cpus=1, | ||
| resources={f"resource-{i}": 1}, | ||
| scheduling_strategy=PlacementGroupSchedulingStrategy( | ||
| placement_group=pg, placement_group_bundle_index=i | ||
| ), | ||
| ).remote() | ||
| ) | ||
| node_id, assigned = result | ||
|
|
||
| # Check node label matches expected | ||
| assert node_id_to_label[node_id] == bundle_label_selectors[i]["region"] | ||
|
|
||
| # Check resource assignment includes the expected custom resource | ||
| assert f"resource-{i}" in assigned | ||
| assert assigned[f"resource-{i}"] == 1.0 | ||
|
|
||
| # Check CPU was assigned | ||
| assert "CPU" in assigned and assigned["CPU"] == 1.0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| if os.environ.get("PARALLEL_CI"): | ||
| sys.exit(pytest.main(["-n", "auto", "--boxed", "-vs", __file__])) | ||
| else: | ||
| sys.exit(pytest.main(["-sv", __file__])) |
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.