mirror of
https://github.com/wassname/ray.git
synced 2026-06-30 02:56:05 +08:00
[Placement Group]Add soft pack strategy (#10099)
This commit is contained in:
@@ -69,6 +69,7 @@ from ray.includes.common cimport (
|
||||
WORKER_TYPE_IO_WORKER,
|
||||
PLACEMENT_STRATEGY_PACK,
|
||||
PLACEMENT_STRATEGY_SPREAD,
|
||||
PLACEMENT_STRATEGY_STRICT_PACK,
|
||||
)
|
||||
from ray.includes.unique_ids cimport (
|
||||
CActorID,
|
||||
@@ -1061,9 +1062,11 @@ cdef class CoreWorker:
|
||||
|
||||
if strategy == b"PACK":
|
||||
c_strategy = PLACEMENT_STRATEGY_PACK
|
||||
elif strategy == b"SPREAD":
|
||||
c_strategy = PLACEMENT_STRATEGY_SPREAD
|
||||
else:
|
||||
if strategy == b"SPREAD":
|
||||
c_strategy = PLACEMENT_STRATEGY_SPREAD
|
||||
if strategy == b"STRICT_PACK":
|
||||
c_strategy = PLACEMENT_STRATEGY_STRICT_PACK
|
||||
else:
|
||||
raise TypeError(strategy)
|
||||
|
||||
|
||||
@@ -13,11 +13,10 @@ def placement_group(bundles: List[Dict[str, float]],
|
||||
Args:
|
||||
bundles: A list of bundles which represent the resources needed.
|
||||
strategy: The strategy to create the placement group.
|
||||
There are two build-in strategies for the time begin.
|
||||
PACK: Packs Bundles close together inside processes or nodes as
|
||||
tight as possible.
|
||||
SPREAD: Places Bundles across distinct nodes or processes as even
|
||||
as possible.
|
||||
PACK: Packs Bundles into as few nodes as possible.
|
||||
SPREAD: Places Bundles across distinct nodes as even as possible.
|
||||
STRICT_PACK: Packs Bundles into one node.
|
||||
The group is not allowed to span multiple nodes.
|
||||
name: The name of the placement group.
|
||||
"""
|
||||
worker = ray.worker.global_worker
|
||||
|
||||
@@ -174,6 +174,8 @@ cdef extern from "src/ray/protobuf/common.pb.h" nogil:
|
||||
"ray::PlacementStrategy::PACK"
|
||||
cdef CPlacementStrategy PLACEMENT_STRATEGY_SPREAD \
|
||||
"ray::PlacementStrategy::SPREAD"
|
||||
cdef CPlacementStrategy PLACEMENT_STRATEGY_STRICT_PACK \
|
||||
"ray::PlacementStrategy::STRICT_PACK"
|
||||
|
||||
cdef extern from "ray/common/task/scheduling_resources.h" nogil:
|
||||
cdef cppclass ResourceSet "ray::ResourceSet":
|
||||
|
||||
@@ -57,6 +57,51 @@ def test_placement_group_pack(ray_start_cluster):
|
||||
assert node_of_actor_1 == node_of_actor_2
|
||||
|
||||
|
||||
def test_placement_group_strict_pack(ray_start_cluster):
|
||||
@ray.remote(num_cpus=2)
|
||||
class Actor(object):
|
||||
def __init__(self):
|
||||
self.n = 0
|
||||
|
||||
def value(self):
|
||||
return self.n
|
||||
|
||||
cluster = ray_start_cluster
|
||||
num_nodes = 2
|
||||
for _ in range(num_nodes):
|
||||
cluster.add_node(num_cpus=4)
|
||||
ray.init(address=cluster.address)
|
||||
|
||||
placement_group_id = ray.experimental.placement_group(
|
||||
name="name", strategy="STRICT_PACK", bundles=[{
|
||||
"CPU": 2
|
||||
}, {
|
||||
"CPU": 2
|
||||
}])
|
||||
actor_1 = Actor.options(
|
||||
placement_group_id=placement_group_id,
|
||||
placement_group_bundle_index=0).remote()
|
||||
actor_2 = Actor.options(
|
||||
placement_group_id=placement_group_id,
|
||||
placement_group_bundle_index=1).remote()
|
||||
|
||||
print(ray.get(actor_1.value.remote()))
|
||||
print(ray.get(actor_2.value.remote()))
|
||||
|
||||
# Get all actors.
|
||||
actor_infos = ray.actors()
|
||||
|
||||
# Make sure all actors in counter_list are collocated in one node.
|
||||
actor_info_1 = actor_infos.get(actor_1._actor_id.hex())
|
||||
actor_info_2 = actor_infos.get(actor_2._actor_id.hex())
|
||||
|
||||
assert actor_info_1 and actor_info_2
|
||||
|
||||
node_of_actor_1 = actor_info_1["Address"]["NodeID"]
|
||||
node_of_actor_2 = actor_info_2["Address"]["NodeID"]
|
||||
assert node_of_actor_1 == node_of_actor_2
|
||||
|
||||
|
||||
def test_placement_group_spread(ray_start_cluster):
|
||||
@ray.remote(num_cpus=2)
|
||||
class Actor(object):
|
||||
|
||||
Reference in New Issue
Block a user