o
    1 i                     @   s
  d dl Z d dlmZmZmZmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZ e eZedZedZeeee e	gee f eee e	egee f edee f f ZeG d	d
 d
ZeG dd deZeG dd deZdeeef defddZdS )    N)AnyCallableIterableOptionalTypeVarUnion)TaskContext)BlockUserDefinedFunction)DeveloperAPI	PublicAPITU.c                   @   s   e Zd ZdS )ComputeStrategyN)__name__
__module____qualname__ r   r   f/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/ray/data/_internal/compute.pyr      s    r   c                   @   sF   e Zd ZdZ	ddee fddZdedefdd	Z	de
fd
dZdS )TaskPoolStrategya;  Specify the task-based compute strategy for a Dataset transform.

    TaskPoolStrategy executes dataset transformations using Ray tasks that are
    scheduled through a pool. Provide ``size`` to cap the number of concurrent
    tasks; leave it unset to allow Ray Data to scale the task count
    automatically.
    Nsizec                 C   s$   |dur|dk rt d||| _dS )zConstruct TaskPoolStrategy for a Dataset transform.

        Args:
            size: Specify the maximum size of the task pool.
        N   z`size` must be >= 1)
ValueErrorr   )selfr   r   r   r   __init__)   s   


zTaskPoolStrategy.__init__otherreturnc                 C   s(   t |tr| j|jkp|dko| jd u S )Ntasks)
isinstancer   r   r   r   r   r   r   __eq__7   s   zTaskPoolStrategy.__eq__c                 C   s   d| j  dS )NzTaskPoolStrategy(size=))r   r   r   r   r   __repr__<   s   zTaskPoolStrategy.__repr__Nr   r   r   __doc__r   intr   r   boolr    strr#   r   r   r   r   r      s    

r   c                   @   sp   e Zd ZdZdddddddee dee dee dee dee f
d	d
ZdedefddZ	de
fddZdS )ActorPoolStrategya{  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 ``ActorPoolStrategy(size=n)``.

    To autoscale from ``m`` to ``n`` actors, use
    ``ActorPoolStrategy(min_size=m, max_size=n)``.

    To autoscale from ``m`` to ``n`` actors, with an initial size of ``initial``, use
    ``ActorPoolStrategy(min_size=m, max_size=n, initial_size=initial)``.

    To increase opportunities for pipelining task dependency prefetching with
    computation and avoiding actor startup delays, set max_tasks_in_flight_per_actor
    to 2 or greater; to try to decrease the delay due to queueing of tasks on the worker
    actors, set max_tasks_in_flight_per_actor to 1.
    N)r   min_sizemax_sizeinitial_sizemax_tasks_in_flight_per_actorr   r+   r,   r-   r.   c                C   s6  |dur#|dk rt d||dus|dus|durt d|}|}|}|dur0|dk r0t d||durD|du r:d}||krDt d|||durQ|dk rQt d||pTd| _|p[td| _|dur|| jk rrt d	| d
| j d| jtdkr|| jkrt d	| d| j d|p| j| _|| _d| _d| _dS )aa  Construct ActorPoolStrategy for a Dataset transform.

        Args:
            size: Specify a fixed size actor pool of this size. It is an error to
                specify both `size` and `min_size` or `max_size`.
            min_size: The minimum size of the actor pool.
            max_size: The maximum size of the actor pool.
            initial_size: The initial number of actors to start with. If not specified,
                defaults to min_size. Must be between min_size and max_size.
            max_tasks_in_flight_per_actor: The maximum number of tasks to concurrently
                send to a single actor worker. Increasing this will increase
                opportunities for pipelining task dependency prefetching with
                computation and avoiding actor startup delays, but will also increase
                queueing delay.
        Nr   zsize must be >= 1zMmin_size, max_size, and initial_size cannot be set at the same time as `size`zmin_size must be >= 1zmin_size must be <= max_sizez1max_tasks_in_flight_per_actor must be >= 1, got: infzinitial_size (z) must be >= min_size (r!   z) must be <= max_size (r   g?)r   r+   floatr,   r-   r.   num_workersready_to_total_workers_ratio)r   r   r+   r,   r-   r.   r   r   r   r   V   sL   




zActorPoolStrategy.__init__r   r   c                 C   s:   t |to| j|jko| j|jko| j|jko| j|jkS r$   )r   r*   r+   r,   r-   r.   r   r   r   r   r       s   


zActorPoolStrategy.__eq__c                 C   s6   d| j  d| j d| j d| j d| j d| j dS )NzActorPoolStrategy(min_size=z, max_size=z, initial_size=z , max_tasks_in_flight_per_actor=z)num_workers=z, ready_to_total_workers_ratio=r!   )r+   r,   r-   r.   r1   r2   r"   r   r   r   r#      s   
zActorPoolStrategy.__repr__r%   r   r   r   r   r*   @   s(    
E	r*   compute_specr   c                 C   sT   t | ttfstd|  d| r| dkrt S | dkrt S t | tr&| S td)NzXIn Ray 2.5, the compute spec must be either TaskPoolStrategy or ActorPoolStrategy, was: .r   Zactorsz;compute must be one of [`tasks`, `actors`, ComputeStrategy])r   r   r*   r   r   )r3   r   r   r   get_compute   s   
r5   )loggingtypingr   r   r   r   r   r   Z'ray.data._internal.execution.interfacesr   Zray.data.blockr	   r
   Zray.util.annotationsr   r   	getLoggerr   loggerr   r   ZBlockTransformr   r   r*   r)   r5   r   r   r   r   <module>   s*     
 n