o
    `Û·iK  ã                   @   sZ   d dl Z d dlZd dlmZ d dlmZmZ d dlmZ e  	e
¡ZeG dd„ deƒƒZdS )é    N)ÚInputReader)ÚDeveloperAPIÚoverride)ÚSampleBatchTypec                   @   s>   e Zd ZdZeddedefdd„ƒZeeƒde	fdd	„ƒZ
d
S )ÚShuffledInputz½Randomizes data over a sliding window buffer of N batches.

    This increases the randomization of the data, which is useful if the
    batches were not in random order to start with.
    r   ÚchildÚnc                 C   s   || _ || _g | _dS )z±Initializes a ShuffledInput instance.

        Args:
            child: child input reader to shuffle.
            n: If positive, shuffle input over this many batches.
        N)r   r   Úbuffer)Úselfr   r   © r   úV/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/rllib/offline/shuffled_input.pyÚ__init__   s   
zShuffledInput.__init__Úreturnc                 C   s¤   | j dkr
| j ¡ S t| jƒ| j k r9t d | j ¡¡ t| jƒ| j k r4| j | j ¡ ¡ t| jƒ| j k s#t d¡ t	 
dt| jƒd ¡}| j ¡ | j|< t	 | j¡S )Né   z$Filling shuffle buffer to {} batcheszShuffle buffer filledr   )r   r   ÚnextÚlenr	   ÚloggerÚinfoÚformatÚappendÚrandomÚrandintÚchoice)r
   Úir   r   r   r      s   

ÿ
zShuffledInput.nextN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úintr   r   r   r   r   r   r   r   r      s    r   )Úloggingr   Úray.rllib.offline.input_readerr   Úray.rllib.utils.annotationsr   r   Úray.rllib.utils.typingr   Ú	getLoggerr   r   r   r   r   r   r   Ú<module>   s    
