mirror of
https://github.com/wassname/ray.git
synced 2026-06-27 21:38:18 +08:00
Disable parallelization for Actors and ray.wait for debugging (#961)
Support actors and ray.wait in PYTHON_MODE.
This commit is contained in:
+28
-11
@@ -3,6 +3,7 @@ from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import cloudpickle as pickle
|
||||
import copy
|
||||
import hashlib
|
||||
import inspect
|
||||
import json
|
||||
@@ -314,17 +315,25 @@ def make_actor(cls, num_cpus, num_gpus, checkpoint_interval):
|
||||
self._actor_method_invokers[k] = ActorMethod(
|
||||
self, k, self._ray_method_signatures[k])
|
||||
|
||||
# Export the actor class if it has not been exported yet.
|
||||
if len(exported) == 0:
|
||||
export_actor_class(class_id, Class,
|
||||
self._ray_actor_methods.keys(),
|
||||
checkpoint_interval,
|
||||
ray.worker.global_worker)
|
||||
exported.append(0)
|
||||
# Export the actor.
|
||||
export_actor(self._ray_actor_id, class_id,
|
||||
self._ray_actor_methods.keys(), num_cpus, num_gpus,
|
||||
ray.worker.global_worker)
|
||||
# Do not export the actor class or the actor if run in PYTHON_MODE
|
||||
# Instead, instantiate the actor locally and add it to
|
||||
# global_worker's dictionary
|
||||
if ray.worker.global_worker.mode == ray.PYTHON_MODE:
|
||||
ray.worker.global_worker.actors[self._ray_actor_id] = (
|
||||
Class.__new__(Class))
|
||||
else:
|
||||
# Export the actor class if it has not been exported yet.
|
||||
if len(exported) == 0:
|
||||
export_actor_class(class_id, Class,
|
||||
self._ray_actor_methods.keys(),
|
||||
checkpoint_interval,
|
||||
ray.worker.global_worker)
|
||||
exported.append(0)
|
||||
# Export the actor.
|
||||
export_actor(self._ray_actor_id, class_id,
|
||||
self._ray_actor_methods.keys(), num_cpus,
|
||||
num_gpus, ray.worker.global_worker)
|
||||
|
||||
# Call __init__ as a remote function.
|
||||
if "__init__" in self._ray_actor_methods.keys():
|
||||
self._actor_method_call(
|
||||
@@ -340,6 +349,14 @@ def make_actor(cls, num_cpus, num_gpus, checkpoint_interval):
|
||||
ray.worker.check_connected()
|
||||
ray.worker.check_main_thread()
|
||||
args = signature.extend_args(function_signature, args, kwargs)
|
||||
|
||||
# Execute functions locally if Ray is run in PYTHON_MODE
|
||||
# Copy args to prevent the function from mutating them.
|
||||
if ray.worker.global_worker.mode == ray.PYTHON_MODE:
|
||||
return getattr(
|
||||
ray.worker.global_worker.actors[self._ray_actor_id],
|
||||
attr)(*copy.deepcopy(args))
|
||||
|
||||
# Add the current actor cursor, a dummy object returned by the most
|
||||
# recent method invocation, as a dependency for the next method
|
||||
# invocation.
|
||||
|
||||
@@ -2067,6 +2067,12 @@ def wait(object_ids, num_returns=1, timeout=None, worker=global_worker):
|
||||
check_connected(worker)
|
||||
with log_span("ray:wait", worker=worker):
|
||||
check_main_thread()
|
||||
|
||||
# When Ray is run in PYTHON_MODE, all functions are run immediately,
|
||||
# so all objects in object_id are ready.
|
||||
if worker.mode == PYTHON_MODE:
|
||||
return object_ids[:num_returns], object_ids[num_returns:]
|
||||
|
||||
object_id_strs = [plasma.ObjectID(object_id.id())
|
||||
for object_id in object_ids]
|
||||
timeout = timeout if timeout is not None else 2 ** 30
|
||||
|
||||
Reference in New Issue
Block a user