def actor_method_executor(actor, *args, **kwargs): # Execute the assigned method. is_bound = (is_class_method(method) or is_static_method(type(actor), method_name)) if is_bound: return method(*args, **kwargs) else: return method(actor, *args, **kwargs)
def actor_method_executor(dummy_return_id, actor, *args): # Update the actor's task counter to reflect the task we're about # to execute. self._worker.actor_task_counter += 1 # If this is the first task to execute on the actor, try to resume # from a checkpoint. # Current __init__ will be called by default. So the real function # call will start from 2. if actor_imported and self._worker.actor_task_counter == 2: checkpoint_resumed = ray.actor.restore_and_log_checkpoint( self._worker, actor) if checkpoint_resumed: # NOTE(swang): Since we did not actually execute the # __init__ method, this will put None as the return value. # If the __init__ method is supposed to return multiple # values, an exception will be logged. return # Determine whether we should checkpoint the actor. checkpointing_on = (actor_imported and self._worker.actor_checkpoint_interval > 0) # We should checkpoint the actor if user checkpointing is on, we've # executed checkpoint_interval tasks since the last checkpoint, and # the method we're about to execute is not a checkpoint. save_checkpoint = (checkpointing_on and (self._worker.actor_task_counter % self._worker.actor_checkpoint_interval == 0 and method_name != "__ray_checkpoint__")) # Execute the assigned method and save a checkpoint if necessary. try: if is_class_method(method): method_returns = method(*args) else: method_returns = method(actor, *args) except Exception: # Save the checkpoint before allowing the method exception # to be thrown. if save_checkpoint: ray.actor.save_and_log_checkpoint(self._worker, actor) raise else: # Save the checkpoint before returning the method's return # values. if save_checkpoint: ray.actor.save_and_log_checkpoint(self._worker, actor) return method_returns
def actor_method_executor(actor, *args, **kwargs): # Update the actor's task counter to reflect the task we're about # to execute. self._worker.actor_task_counter += 1 # Execute the assigned method and save a checkpoint if necessary. try: is_bound = (is_class_method(method) or is_static_method(type(actor), method_name)) if is_bound: method_returns = method(*args, **kwargs) else: method_returns = method(actor, *args, **kwargs) except Exception as e: # Save the checkpoint before allowing the method exception # to be thrown, but don't save the checkpoint for actor # creation task. if (isinstance(actor, ray.actor.Checkpointable) and self._worker.actor_task_counter != 1): self._save_and_log_checkpoint(actor) raise e else: # Handle any checkpointing operations before storing the # method's return values. # NOTE(swang): If method_returns is a pointer to the actor's # state and the checkpointing operations can modify the return # values if they mutate the actor's state. Is this okay? if isinstance(actor, ray.actor.Checkpointable): # If this is the first task to execute on the actor, try to # resume from a checkpoint. if self._worker.actor_task_counter == 1: if actor_imported: self._restore_and_log_checkpoint(actor) else: # Save the checkpoint before returning the method's # return values. self._save_and_log_checkpoint(actor) return method_returns
def actor_method_executor(dummy_return_id, actor, *args): # Update the actor's task counter to reflect the task we're about # to execute. self._worker.actor_task_counter += 1 # Execute the assigned method and save a checkpoint if necessary. try: if is_class_method(method): method_returns = method(*args) else: method_returns = method(actor, *args) except Exception as e: # Save the checkpoint before allowing the method exception # to be thrown, but don't save the checkpoint for actor # creation task. if (isinstance(actor, ray.actor.Checkpointable) and self._worker.actor_task_counter != 1): self._save_and_log_checkpoint(actor) raise e else: # Handle any checkpointing operations before storing the # method's return values. # NOTE(swang): If method_returns is a pointer to the actor's # state and the checkpointing operations can modify the return # values if they mutate the actor's state. Is this okay? if isinstance(actor, ray.actor.Checkpointable): # If this is the first task to execute on the actor, try to # resume from a checkpoint. if self._worker.actor_task_counter == 1: if actor_imported: self._restore_and_log_checkpoint(actor) else: # Save the checkpoint before returning the method's # return values. self._save_and_log_checkpoint(actor) return method_returns