MCPcopy
hub / github.com/ray-project/ray / ActorPoolStrategy

Class ActorPoolStrategy

python/ray/data/_internal/compute.py:65–202  ·  view source on GitHub ↗

Specify the actor-based compute strategy for a Dataset transform. ActorPoolStrategy specifies that an autoscaling pool of actors should be used for a given Dataset transform. This is useful for stateful setup of callable classes. For a fixed-sized pool of size ``n``, use ``ActorPoo

Source from the content-addressed store, hash-verified

63
64@PublicAPI
65class ActorPoolStrategy(ComputeStrategy):
66 """Specify the actor-based compute strategy for a Dataset transform.
67
68 ActorPoolStrategy specifies that an autoscaling pool of actors should be used
69 for a given Dataset transform. This is useful for stateful setup of callable
70 classes.
71
72 For a fixed-sized pool of size ``n``, use ``ActorPoolStrategy(size=n)``.
73
74 To autoscale from ``m`` to ``n`` actors, use
75 ``ActorPoolStrategy(min_size=m, max_size=n)``.
76
77 To autoscale from ``m`` to ``n`` actors, with an initial size of ``initial``, use
78 ``ActorPoolStrategy(min_size=m, max_size=n, initial_size=initial)``.
79
80 To increase opportunities for pipelining task dependency prefetching with
81 computation and avoiding actor startup delays, set max_tasks_in_flight_per_actor
82 to 2 or greater; to try to decrease the delay due to queueing of tasks on the worker
83 actors, set max_tasks_in_flight_per_actor to 1.
84
85 The `enable_true_multi_threading` argument primarily exists to prevent GPU OOM issues with multi-threaded actors.
86 The life cycle of an actor task involves 3 main steps:
87
88 1. Batching Inputs
89 2. Running actor UDF
90 3. Batching Outputs
91
92 The `enable_true_multi_threading` flag affects step 2. If set to `True`, then the UDF can be run concurrently.
93 By default, it is set to `False`, so at most 1 actor UDF is running at a time per actor. The `max_concurrency`
94 flag on `ray.remote` affects steps 1 and 3. Below is a matrix summary:
95
96 - [`enable_true_multi_threading=False or True`, `max_concurrency=1`] = 1 actor task running per actor. So at most 1
97 of steps 1, 2, or 3 is running at any point in time.
98 - [`enable_true_multi_threading=False`, `max_concurrency>1`] = multiple tasks running per actor
99 (respecting GIL) but UDF runs 1 at a time. This is useful for doing CPU and GPU work,
100 where you want to use a large batch size but want to hide the overhead of *batching*
101 the inputs. In this case, CPU *batching* is done concurrently, while GPU *inference*
102 is done 1 at a time. Concretely, steps 1 and 3 can have multiple threads, while step 2 is done serially.
103 - [`enable_true_multi_threading=True`, `max_concurrency>1`] = multiple tasks running per actor.
104 Unlike bullet #3 ^, the UDF runs concurrently (respecting GIL). No restrictions on steps 1, 2, or 3
105
106 NOTE: `enable_true_multi_threading` does not apply to async actors
107 """
108
109 def __init__(
110 self,
111 *,
112 size: Optional[int] = None,
113 min_size: Optional[int] = None,
114 max_size: Optional[int] = None,
115 initial_size: Optional[int] = None,
116 max_tasks_in_flight_per_actor: Optional[int] = None,
117 enable_true_multi_threading: bool = False,
118 ):
119 """Construct ActorPoolStrategy for a Dataset transform.
120
121 Args:
122 size: Specify a fixed size actor pool of this size. It is an error to

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…