mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 13:54:27 +08:00
Move function/actor exporting & loading code to function_manager.py (#3003)
Move function/actor exporting & loading code to function_manager.py to prepare the code change for function descriptor for python.
This commit is contained in:
committed by
Robert Nishihara
parent
d73ee36e60
commit
9948e8c11b
@@ -22,7 +22,7 @@ def compute_function_id(function):
|
||||
func: The actual function.
|
||||
|
||||
Returns:
|
||||
This returns the function ID.
|
||||
Raw bytes of the function id
|
||||
"""
|
||||
function_id_hash = hashlib.sha1()
|
||||
# Include the function module and name in the hash.
|
||||
@@ -39,8 +39,6 @@ def compute_function_id(function):
|
||||
# Compute the function ID.
|
||||
function_id = function_id_hash.digest()
|
||||
assert len(function_id) == ray_constants.ID_SIZE
|
||||
function_id = ray.ObjectID(function_id)
|
||||
|
||||
return function_id
|
||||
|
||||
|
||||
@@ -72,7 +70,7 @@ class RemoteFunction(object):
|
||||
# TODO(rkn): We store the function ID as a string, so that
|
||||
# RemoteFunction objects can be pickled. We should undo this when
|
||||
# we allow ObjectIDs to be pickled.
|
||||
self._function_id = compute_function_id(self._function).id()
|
||||
self._function_id = compute_function_id(function)
|
||||
self._function_name = (
|
||||
self._function.__module__ + '.' + self._function.__name__)
|
||||
self._num_cpus = (DEFAULT_REMOTE_FUNCTION_CPUS
|
||||
@@ -90,11 +88,7 @@ class RemoteFunction(object):
|
||||
|
||||
# # Export the function.
|
||||
worker = ray.worker.get_global_worker()
|
||||
if worker.mode == ray.worker.SCRIPT_MODE:
|
||||
self._export()
|
||||
elif worker.mode is None:
|
||||
worker.cached_remote_functions_and_actors.append(
|
||||
("remote_function", self))
|
||||
worker.function_actor_manager.export(self)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
raise Exception("Remote functions cannot be called directly. Instead "
|
||||
@@ -141,9 +135,3 @@ class RemoteFunction(object):
|
||||
return object_ids[0]
|
||||
elif len(object_ids) > 1:
|
||||
return object_ids
|
||||
|
||||
def _export(self):
|
||||
worker = ray.worker.get_global_worker()
|
||||
worker.export_remote_function(
|
||||
ray.ObjectID(self._function_id), self._function_name,
|
||||
self._function, self._max_calls, self)
|
||||
|
||||
Reference in New Issue
Block a user