ray.actor.ActorClass.options#

ActorClass.options(**actor_options)[source]#

Configures and overrides the actor instantiation parameters.

The arguments are the same as those that can be passed to ray.remote.

Parameters:
  • num_cpus – The quantity of CPU cores to reserve for this task or for the lifetime of the actor.

  • num_gpus – The quantity of GPUs to reserve for this task or for the lifetime of the actor.

  • resources (Dict[str, float]) – The quantity of various custom resources to reserve for this task or for the lifetime of the actor. This is a dictionary mapping strings (resource names) to floats.

  • accelerator_type – If specified, requires that the task or actor run on a node with the specified type of accelerator. See accelerator types.

  • memory – The heap memory request in bytes for this task/actor, rounded down to the nearest integer.

  • object_store_memory – The object store memory request for actors only.

  • max_restarts – This specifies the maximum number of times that the actor should be restarted when it dies unexpectedly. The minimum valid value is 0 (default), which indicates that the actor doesn’t need to be restarted. A value of -1 indicates that an actor should be restarted indefinitely.

  • max_task_retries – How many times to retry an actor task if the task fails due to a system error, e.g., the actor has died. If set to -1, the system will retry the failed task until the task succeeds, or the actor has reached its max_restarts limit. If set to n > 0, the system will retry the failed task up to n times, after which the task will throw a RayActorError exception upon ray.get. Note that Python exceptions are not considered system errors and will not trigger retries.

  • max_pending_calls – Set the max number of pending calls allowed on the actor handle. When this value is exceeded, PendingCallsLimitExceeded will be raised for further tasks. Note that this limit is counted per handle. -1 means that the number of pending calls is unlimited.

  • max_concurrency – The max number of concurrent calls to allow for this actor. This only works with direct actor calls. The max concurrency defaults to 1 for threaded execution, and 1000 for asyncio execution. Note that the execution order is not guaranteed when max_concurrency > 1.

  • name – The globally unique name for the actor, which can be used to retrieve the actor via ray.get_actor(name) as long as the actor is still alive.

  • namespace – Override the namespace to use for the actor. By default, actors are created in an anonymous namespace. The actor can be retrieved via ray.get_actor(name=name, namespace=namespace).

  • lifetime – Either None, which defaults to the actor will fate share with its creator and will be deleted once its refcount drops to zero, or “detached”, which means the actor will live as a global object independent of the creator.

  • runtime_env (Dict[str, Any]) – Specifies the runtime environment for this actor or task and its children. See Runtime environments for detailed documentation.

  • scheduling_strategy – Strategy about how to schedule a remote function or actor. Possible values are None: ray will figure out the scheduling strategy to use, it will either be the PlacementGroupSchedulingStrategy using parent’s placement group if parent has one and has placement_group_capture_child_tasks set to true, or “DEFAULT”; “DEFAULT”: default hybrid scheduling; “SPREAD”: best effort spread scheduling; PlacementGroupSchedulingStrategy: placement group based scheduling; NodeAffinitySchedulingStrategy: node id based affinity scheduling.

  • _metadata – Extended options for Ray libraries. For example, _metadata={“workflows.io/options”: <workflow options>} for Ray workflows.

Examples:

@ray.remote(num_cpus=2, resources={"CustomResource": 1})
class Foo:
    def method(self):
        return 1
# Class Bar will require 1 cpu instead of 2.
# It will also require no custom resources.
Bar = Foo.options(num_cpus=1, resources=None)