mirror of
https://github.com/wassname/ray.git
synced 2026-07-16 11:21:10 +08:00
Allow scheduling with arbitrary user-defined resource labels. (#1236)
* Enable scheduling with custom resource labels. * Fix. * Minor fixes and ref counting fix. * Linting * Use .data() instead of .c_str(). * Fix linting. * Fix ResourcesTest.testGPUIDs test by waiting for workers to start up. * Sleep in test so that all tasks are submitted before any completes.
This commit is contained in:
committed by
Philipp Moritz
parent
ac64631043
commit
c21e189371
+28
-57
@@ -639,9 +639,7 @@ def start_local_scheduler(redis_address,
|
||||
stdout_file=None,
|
||||
stderr_file=None,
|
||||
cleanup=True,
|
||||
num_cpus=None,
|
||||
num_gpus=None,
|
||||
num_custom_resource=None,
|
||||
resources=None,
|
||||
num_workers=0):
|
||||
"""Start a local scheduler process.
|
||||
|
||||
@@ -662,30 +660,22 @@ def start_local_scheduler(redis_address,
|
||||
cleanup (bool): True if using Ray in local mode. If cleanup is true,
|
||||
then this process will be killed by serices.cleanup() when the
|
||||
Python process that imported services exits.
|
||||
num_cpus: The number of CPUs the local scheduler should be configured
|
||||
with.
|
||||
num_gpus: The number of GPUs the local scheduler should be configured
|
||||
with.
|
||||
num_custom_resource: The quantity of a user-defined custom resource
|
||||
that the local scheduler should be configured with.
|
||||
resources: A dictionary mapping the name of a resource to the available
|
||||
quantity of that resource.
|
||||
num_workers (int): The number of workers that the local scheduler
|
||||
should start.
|
||||
|
||||
Return:
|
||||
The name of the local scheduler socket.
|
||||
"""
|
||||
if num_cpus is None:
|
||||
if resources is None:
|
||||
resources = {}
|
||||
if "CPU" not in resources:
|
||||
# By default, use the number of hardware execution threads for the
|
||||
# number of cores.
|
||||
num_cpus = psutil.cpu_count()
|
||||
if num_gpus is None:
|
||||
# By default, assume this node has no GPUs.
|
||||
num_gpus = 0
|
||||
if num_custom_resource is None:
|
||||
# By default, assume this node has none of the custom resource.
|
||||
num_custom_resource = 0
|
||||
print("Starting local scheduler with {} CPUs, {} GPUs"
|
||||
.format(num_cpus, num_gpus, num_custom_resource))
|
||||
resources["CPU"] = psutil.cpu_count()
|
||||
print("Starting local scheduler with the following resources: {}."
|
||||
.format(resources))
|
||||
local_scheduler_name, p = ray.local_scheduler.start_local_scheduler(
|
||||
plasma_store_name,
|
||||
plasma_manager_name,
|
||||
@@ -696,7 +686,7 @@ def start_local_scheduler(redis_address,
|
||||
use_profiler=RUN_LOCAL_SCHEDULER_PROFILER,
|
||||
stdout_file=stdout_file,
|
||||
stderr_file=stderr_file,
|
||||
static_resource_list=[num_cpus, num_gpus, num_custom_resource],
|
||||
static_resources=resources,
|
||||
num_workers=num_workers)
|
||||
if cleanup:
|
||||
all_processes[PROCESS_TYPE_LOCAL_SCHEDULER].append(p)
|
||||
@@ -894,9 +884,7 @@ def start_ray_processes(address_info=None,
|
||||
include_log_monitor=False,
|
||||
include_webui=False,
|
||||
start_workers_from_local_scheduler=True,
|
||||
num_cpus=None,
|
||||
num_gpus=None,
|
||||
num_custom_resource=None,
|
||||
resources=None,
|
||||
plasma_directory=None,
|
||||
huge_pages=False):
|
||||
"""Helper method to start Ray processes.
|
||||
@@ -940,13 +928,8 @@ def start_ray_processes(address_info=None,
|
||||
start_workers_from_local_scheduler (bool): If this flag is True, then
|
||||
start the initial workers from the local scheduler. Else, start
|
||||
them from Python.
|
||||
num_cpus: A list of length num_local_schedulers containing the number
|
||||
of CPUs each local scheduler should be configured with.
|
||||
num_gpus: A list of length num_local_schedulers containing the number
|
||||
of GPUs each local scheduler should be configured with.
|
||||
num_custom_resource: A list of length num_local_schedulers containing
|
||||
the quantity of a user-defined custom resource that each local
|
||||
scheduler should be configured with.
|
||||
resources: A dictionary mapping resource name to the quantity of that
|
||||
resource.
|
||||
plasma_directory: A directory where the Plasma memory mapped files will
|
||||
be created.
|
||||
huge_pages: Boolean flag indicating whether to start the Object
|
||||
@@ -956,21 +939,17 @@ def start_ray_processes(address_info=None,
|
||||
A dictionary of the address information for the processes that were
|
||||
started.
|
||||
"""
|
||||
if not isinstance(num_cpus, list):
|
||||
num_cpus = num_local_schedulers * [num_cpus]
|
||||
if not isinstance(num_gpus, list):
|
||||
num_gpus = num_local_schedulers * [num_gpus]
|
||||
if not isinstance(num_custom_resource, list):
|
||||
num_custom_resource = num_local_schedulers * [num_custom_resource]
|
||||
assert len(num_cpus) == num_local_schedulers
|
||||
assert len(num_gpus) == num_local_schedulers
|
||||
assert len(num_custom_resource) == num_local_schedulers
|
||||
if resources is None:
|
||||
resources = {}
|
||||
if not isinstance(resources, list):
|
||||
resources = num_local_schedulers * [resources]
|
||||
|
||||
if num_workers is not None:
|
||||
workers_per_local_scheduler = num_local_schedulers * [num_workers]
|
||||
else:
|
||||
workers_per_local_scheduler = []
|
||||
for cpus in num_cpus:
|
||||
for resource_dict in resources:
|
||||
cpus = resource_dict.get("CPU")
|
||||
workers_per_local_scheduler.append(cpus if cpus is not None
|
||||
else psutil.cpu_count())
|
||||
|
||||
@@ -1100,9 +1079,7 @@ def start_ray_processes(address_info=None,
|
||||
stdout_file=local_scheduler_stdout_file,
|
||||
stderr_file=local_scheduler_stderr_file,
|
||||
cleanup=cleanup,
|
||||
num_cpus=num_cpus[i],
|
||||
num_gpus=num_gpus[i],
|
||||
num_custom_resource=num_custom_resource[i],
|
||||
resources=resources[i],
|
||||
num_workers=num_local_scheduler_workers)
|
||||
local_scheduler_socket_names.append(local_scheduler_name)
|
||||
time.sleep(0.1)
|
||||
@@ -1156,9 +1133,7 @@ def start_ray_node(node_ip_address,
|
||||
worker_path=None,
|
||||
cleanup=True,
|
||||
redirect_output=False,
|
||||
num_cpus=None,
|
||||
num_gpus=None,
|
||||
num_custom_resource=None,
|
||||
resources=None,
|
||||
plasma_directory=None,
|
||||
huge_pages=False):
|
||||
"""Start the Ray processes for a single node.
|
||||
@@ -1183,6 +1158,8 @@ def start_ray_node(node_ip_address,
|
||||
called this method exits.
|
||||
redirect_output (bool): True if stdout and stderr should be redirected
|
||||
to a file.
|
||||
resources: A dictionary mapping resource name to the available quantity
|
||||
of that resource.
|
||||
plasma_directory: A directory where the Plasma memory mapped files will
|
||||
be created.
|
||||
huge_pages: Boolean flag indicating whether to start the Object
|
||||
@@ -1202,9 +1179,7 @@ def start_ray_node(node_ip_address,
|
||||
include_log_monitor=True,
|
||||
cleanup=cleanup,
|
||||
redirect_output=redirect_output,
|
||||
num_cpus=num_cpus,
|
||||
num_gpus=num_gpus,
|
||||
num_custom_resource=num_custom_resource,
|
||||
resources=resources,
|
||||
plasma_directory=plasma_directory,
|
||||
huge_pages=huge_pages)
|
||||
|
||||
@@ -1219,9 +1194,7 @@ def start_ray_head(address_info=None,
|
||||
cleanup=True,
|
||||
redirect_output=False,
|
||||
start_workers_from_local_scheduler=True,
|
||||
num_cpus=None,
|
||||
num_gpus=None,
|
||||
num_custom_resource=None,
|
||||
resources=None,
|
||||
num_redis_shards=None,
|
||||
redis_max_clients=None,
|
||||
include_webui=True,
|
||||
@@ -1257,8 +1230,8 @@ def start_ray_head(address_info=None,
|
||||
start_workers_from_local_scheduler (bool): If this flag is True, then
|
||||
start the initial workers from the local scheduler. Else, start
|
||||
them from Python.
|
||||
num_cpus (int): number of cpus to configure the local scheduler with.
|
||||
num_gpus (int): number of gpus to configure the local scheduler with.
|
||||
resources: A dictionary mapping resource name to the available quantity
|
||||
of that resource.
|
||||
num_redis_shards: The number of Redis shards to start in addition to
|
||||
the primary Redis shard.
|
||||
redis_max_clients: If provided, attempt to configure Redis with this
|
||||
@@ -1288,9 +1261,7 @@ def start_ray_head(address_info=None,
|
||||
include_log_monitor=True,
|
||||
include_webui=include_webui,
|
||||
start_workers_from_local_scheduler=start_workers_from_local_scheduler,
|
||||
num_cpus=num_cpus,
|
||||
num_gpus=num_gpus,
|
||||
num_custom_resource=num_custom_resource,
|
||||
resources=resources,
|
||||
num_redis_shards=num_redis_shards,
|
||||
redis_max_clients=redis_max_clients,
|
||||
plasma_directory=plasma_directory,
|
||||
|
||||
Reference in New Issue
Block a user