mirror of
https://github.com/wassname/ray.git
synced 2026-07-01 20:57:51 +08:00
Fix bug in which remote function redefinition doesn't happen. (#6175)
This commit is contained in:
committed by
Edward Oakes
parent
7f8de61441
commit
ffb9c0ecae
@@ -6,6 +6,7 @@ import os
|
||||
import logging
|
||||
from functools import wraps
|
||||
|
||||
from ray import cloudpickle as pickle
|
||||
from ray.function_manager import FunctionDescriptor
|
||||
import ray.signature
|
||||
|
||||
@@ -24,7 +25,10 @@ class RemoteFunction(object):
|
||||
|
||||
Attributes:
|
||||
_function: The original function.
|
||||
_function_descriptor: The function descriptor.
|
||||
_function_descriptor: The function descriptor. This is not defined
|
||||
until the remote function is first invoked because that is when the
|
||||
function is pickled, and the pickled function is used to compute
|
||||
the function descriptor.
|
||||
_function_name: The module and function name.
|
||||
_num_cpus: The default number of CPUs to use for invocations of this
|
||||
remote function.
|
||||
@@ -57,9 +61,6 @@ class RemoteFunction(object):
|
||||
def __init__(self, function, num_cpus, num_gpus, memory,
|
||||
object_store_memory, resources, num_return_vals, max_calls):
|
||||
self._function = function
|
||||
self._function_descriptor = FunctionDescriptor.from_function(function)
|
||||
self._function_descriptor_list = (
|
||||
self._function_descriptor.get_function_descriptor_list())
|
||||
self._function_name = (
|
||||
self._function.__module__ + "." + self._function.__name__)
|
||||
self._num_cpus = (DEFAULT_REMOTE_FUNCTION_CPUS
|
||||
@@ -146,10 +147,25 @@ class RemoteFunction(object):
|
||||
worker = ray.worker.get_global_worker()
|
||||
worker.check_connected()
|
||||
|
||||
# If this function was not exported in this session and job, we need to
|
||||
# export this function again, because the current GCS doesn't have it.
|
||||
if self._last_export_session_and_job != worker.current_session_and_job:
|
||||
# If this function was not exported in this session and job,
|
||||
# we need to export this function again, because current GCS
|
||||
# doesn't have it.
|
||||
# There is an interesting question here. If the remote function is
|
||||
# used by a subsequent driver (in the same script), should the
|
||||
# second driver pickle the function again? If yes, then the remote
|
||||
# function definition can differ in the second driver (e.g., if
|
||||
# variables in its closure have changed). We probably want the
|
||||
# behavior of the remote function in the second driver to be
|
||||
# independent of whether or not the function was invoked by the
|
||||
# first driver. This is an argument for repickling the function,
|
||||
# which we do here.
|
||||
self._pickled_function = pickle.dumps(self._function)
|
||||
|
||||
self._function_descriptor = FunctionDescriptor.from_function(
|
||||
self._function, self._pickled_function)
|
||||
self._function_descriptor_list = (
|
||||
self._function_descriptor.get_function_descriptor_list())
|
||||
|
||||
self._last_export_session_and_job = worker.current_session_and_job
|
||||
worker.function_actor_manager.export(self)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user