def __init__(self, function, num_cpus, num_gpus, resources, num_return_vals, max_calls): self._function = function self._function_descriptor = FunctionDescriptor.from_function(function) self._function_name = ( self._function.__module__ + "." + self._function.__name__) self._num_cpus = (DEFAULT_REMOTE_FUNCTION_CPUS if num_cpus is None else num_cpus) self._num_gpus = num_gpus self._resources = resources self._num_return_vals = (DEFAULT_REMOTE_FUNCTION_NUM_RETURN_VALS if num_return_vals is None else num_return_vals) self._max_calls = (DEFAULT_REMOTE_FUNCTION_MAX_CALLS if max_calls is None else max_calls) self._decorator = getattr(function, "__ray_invocation_decorator__", None) ray.signature.check_signature_supported(self._function) self._function_signature = ray.signature.extract_signature( self._function) self._last_export_session_and_job = None # Override task.remote's signature and docstring @wraps(function) def _remote_proxy(*args, **kwargs): return self._remote(args=args, kwargs=kwargs) self.remote = _remote_proxy
def __init__(self, function, num_cpus, num_gpus, resources, num_return_vals, max_calls): self._function = function self._function_descriptor = FunctionDescriptor.from_function(function) self._function_name = (self._function.__module__ + "." + self._function.__name__) self._num_cpus = (DEFAULT_REMOTE_FUNCTION_CPUS if num_cpus is None else num_cpus) self._num_gpus = num_gpus self._resources = resources self._num_return_vals = (DEFAULT_REMOTE_FUNCTION_NUM_RETURN_VALS if num_return_vals is None else num_return_vals) self._max_calls = (DEFAULT_REMOTE_FUNCTION_MAX_CALLS if max_calls is None else max_calls) self._decorator = getattr(function, "__ray_invocation_decorator__", None) ray.signature.check_signature_supported(self._function) self._function_signature = ray.signature.extract_signature( self._function) # Export the function. worker = ray.worker.get_global_worker() self._last_export_session = worker._session_index worker.function_actor_manager.export(self)
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 if num_cpus is None else num_cpus) self._num_gpus = num_gpus self._memory = memory if object_store_memory is not None: raise NotImplementedError( "setting object_store_memory is not implemented for tasks") self._object_store_memory = None self._resources = resources self._num_return_vals = (DEFAULT_REMOTE_FUNCTION_NUM_RETURN_VALS if num_return_vals is None else num_return_vals) self._max_calls = (DEFAULT_REMOTE_FUNCTION_MAX_CALLS if max_calls is None else max_calls) self._decorator = getattr(function, "__ray_invocation_decorator__", None) self._function_signature = ray.signature.extract_signature( self._function) self._last_export_session_and_job = None # Override task.remote's signature and docstring @wraps(function) def _remote_proxy(*args, **kwargs): return self._remote(args=args, kwargs=kwargs) self.remote = _remote_proxy
def __init__(self, function, num_cpus, num_gpus, resources, num_return_vals, max_calls): self._function = function self._function_descriptor = FunctionDescriptor.from_function(function) self._function_name = ( self._function.__module__ + '.' + self._function.__name__) self._num_cpus = (DEFAULT_REMOTE_FUNCTION_CPUS if num_cpus is None else num_cpus) self._num_gpus = num_gpus self._resources = resources self._num_return_vals = (DEFAULT_REMOTE_FUNCTION_NUM_RETURN_VALS if num_return_vals is None else num_return_vals) self._max_calls = (DEFAULT_REMOTE_FUNCTION_MAX_CALLS if max_calls is None else max_calls) ray.signature.check_signature_supported(self._function) self._function_signature = ray.signature.extract_signature( self._function) # # Export the function. worker = ray.worker.get_global_worker() worker.function_actor_manager.export(self)
def _remote(self, args=None, kwargs=None, num_return_vals=None, is_direct_call=None, num_cpus=None, num_gpus=None, memory=None, object_store_memory=None, resources=None, max_retries=None): """Submit the remote function for execution.""" 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: # 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) kwargs = {} if kwargs is None else kwargs args = [] if args is None else args if num_return_vals is None: num_return_vals = self._num_return_vals if is_direct_call is None: is_direct_call = self.direct_call_enabled if max_retries is None: max_retries = self._max_retries resources = ray.utils.resources_from_resource_arguments( self._num_cpus, self._num_gpus, self._memory, self._object_store_memory, self._resources, num_cpus, num_gpus, memory, object_store_memory, resources) def invocation(args, kwargs): if not args and not kwargs and not self._function_signature: list_args = [] else: list_args = ray.signature.flatten_args( self._function_signature, args, kwargs) if worker.mode == ray.worker.LOCAL_MODE: object_ids = worker.local_mode_manager.execute( self._function, self._function_descriptor, args, kwargs, num_return_vals) else: object_ids = worker.core_worker.submit_task( self._function_descriptor_list, list_args, num_return_vals, is_direct_call, resources, max_retries) if len(object_ids) == 1: return object_ids[0] elif len(object_ids) > 1: return object_ids if self._decorator is not None: invocation = self._decorator(invocation) return invocation(args, kwargs)