Python api of placement group (#9243)

This commit is contained in:
Alisa
2020-07-28 05:57:05 +08:00
committed by GitHub
parent b51ab2af66
commit 51e12ee97c
20 changed files with 362 additions and 23 deletions
+3 -1
View File
@@ -1,8 +1,10 @@
from .api import get, wait
from .dynamic_resources import set_resource
from .placement_group import (
placement_group, )
__all__ = [
"get",
"wait",
"set_resource",
"placement_group",
]
@@ -0,0 +1,26 @@
import ray
from typing import (List, Dict)
def placement_group(bundles: List[Dict[str, float]],
strategy: str = "PACK",
name: str = None):
"""
Create a placement group.
This method is the api to create placement group.
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.
name: The name of the placement group.
"""
worker = ray.worker.global_worker
placement_group_id = worker.core_worker.create_placement_group(
name, bundles, strategy)
return placement_group_id