o
    c²“iÓ  ã                   @   sX   d dl mZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ dZG dd„ deƒZdS )	é    )ÚOptionalN)Úbinary_to_hexÚhex_to_binary)ÚPreprocessor)Ú
CheckpointÚpreprocessor_pklc                   @   s0   e Zd ZdZdee fdd„Zdefdd„ZdS )	ÚFrameworkCheckpointaË  A checkpoint to preserve the functionality of legacy
    framework-specific checkpoints.

    Example:

        >>> import tempfile
        >>> checkpoint = FrameworkCheckpoint(tempfile.mkdtemp())
        >>> checkpoint.get_preprocessor() is None
        True
        >>> preprocessor = Preprocessor()
        >>> preprocessor._attr = 1234
        >>> checkpoint.set_preprocessor(preprocessor)
        >>> checkpoint.get_preprocessor()._attr
        1234
    Úreturnc                 C   s,   |   ¡ }| t¡}|du rdS t t|ƒ¡S )zºReturn the preprocessor stored in the checkpoint.

        Returns:
            The preprocessor stored in the checkpoint, or ``None`` if no
            preprocessor was stored.
        N)Úget_metadataÚgetÚPREPROCESSOR_KEYÚ
ray_pickleÚloadsr   )ÚselfÚmetadataÚpreprocessor_bytes© r   ú\/home/ubuntu/.local/lib/python3.10/site-packages/ray/train/_internal/framework_checkpoint.pyÚget_preprocessor   s
   
z$FrameworkCheckpoint.get_preprocessorÚpreprocessorc                 C   s   |   ttt |¡ƒi¡ dS )z)Store a preprocessor with the checkpoint.N)Úupdate_metadatar   r   r   Údumps)r   r   r   r   r   Úset_preprocessor)   s   ÿz$FrameworkCheckpoint.set_preprocessorN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r      s    r   )Útypingr   Úray.cloudpickleÚcloudpickler   Úray._common.utilsr   r   Úray.data.preprocessorr   Úray.train._checkpointr   r   r   r   r   r   r   Ú<module>   s    