Ë
    ÿÍ:j°  ã            	       óX  — d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	m
Z
 ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlmZmZ  ej.                  e«      Z	 	 dd	e
eef   d
ede	e   defd„Zdededefd„Zdeeef   deddfd„Zdedefd„Z ddede
eef   dedefd„Z!dedefd„Z"y)z)Utilities related to data saving/loading.é    N)ÚPath)ÚIOÚAnyÚOptionalÚUnion)Ú	url_to_fs)ÚAbstractFileSystem)Úmodule_available)Ú_MAP_LOCATION_TYPEÚ_PATHÚpath_or_urlÚmap_locationÚweights_onlyÚreturnc                 ó¸  — t        | t        t        f«      st        j                  | ||¬«      S t        | «      j                  d«      rH|€d}t        j                  d| › d�«       t        j                  j                  t        | «      ||¬«      S t        | «      }|j                  | d«      5 }t        j                  |||¬«      cddd«       S # 1 sw Y   yxY w)aÜ  Loads a checkpoint.

    Args:
        path_or_url: Path or URL of the checkpoint.
        map_location: a function, ``torch.device``, string or a dict specifying how to remap storage locations.
        weights_only: If ``True``, restricts loading to ``state_dicts`` of plain ``torch.Tensor`` and other primitive
            types. If loading a checkpoint from a trusted source that contains an ``nn.Module``, use
            ``weights_only=False``. If loading checkpoint from an untrusted source, we recommend using
            ``weights_only=True``. For more information, please refer to the
            `PyTorch Developer Notes on Serialization Semantics <https://docs.pytorch.org/docs/main/notes/serialization.html#id3>`_.

    )r   r   ÚhttpNFz:Defaulting to `weights_only=False` for remote checkpoint: z\. If loading a checkpoint from an untrustted source, we recommend using `weights_only=True`.Úrb)Ú
isinstanceÚstrr   ÚtorchÚloadÚ
startswithÚlogÚdebugÚhubÚload_state_dict_from_urlÚget_filesystemÚopen)r   r   r   ÚfsÚfs        úx/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/lightning_fabric/utilities/cloud_io.pyÚ_loadr"   "   sÞ   € ô" �k¤C¬ ;Ô/ä�z‰zØØ%Ø%ô
ð 	
ô
 ˆ;Ó×"Ñ" 6Ô*ØÐØ ˆLÜ�I‰IØLÈ[ÈMð Znð oôô
 �y‰y×1Ñ1Ü�ÓØ%Ø%ð 2ó 
ð 	
ô
 
˜Ó	$€BØ	�‰�˜dÓ	#ð 
 qÜ�z‰zØØ%Ø%ô
÷
÷ 
ò 
ús   Â.CÃCÚpathÚkwargsc                 ó6   — t        t        | «      fi |¤Ž\  }}|S )N)r   r   )r#   r$   r   Ú_s       r!   r   r   P   s   € Ü”c˜$“iÑ* 6Ñ*�E€BˆØ€Ió    Ú
checkpointÚfilepathc                 ó  — t        j                  «       }t        j                  d|› �«       t	        j
                  | |«       	 t        j                  j                  t        |«      «      \  }}|j                  5  d}t        d«      rddlm} t        ||«      }t        |«      r#|s!|j!                  ||j#                  «       «       n:|j%                  |d«      5 }|j'                  |j#                  «       «       ddd«       ddd«       y# 1 sw Y   ŒxY w# 1 sw Y   yxY w# t(        $ r]}t        |j*                  t,        «      r9t/        |j*                  dd«      t0        j2                  k(  rt5        d	«      |‚Y d}~yY d}~yd}~ww xY w)
aœ  Saves a checkpoint atomically, avoiding the creation of incomplete checkpoints.

    Args:
        checkpoint: The object to save.
            Built to be used with the ``dump_checkpoint`` method, but can deal with anything which ``torch.save``
            accepts.
        filepath: The path to which the checkpoint will be saved.
            This points to the file that the checkpoint will be stored in.

    zSaving checkpoint: FÚadlfsr   ©ÚAzureBlobFileSystemÚwbNÚerrnoz]Upgrade fsspec to enable cross-device local checkpoints: pip install "fsspec[http]>=2025.5.0")ÚioÚBytesIOr   r   r   ÚsaveÚfsspecÚcorer   r   Útransactionr
   r+   r-   r   Ú_is_object_storageÚpipeÚgetvaluer   ÚwriteÚPermissionErrorÚ__context__ÚOSErrorÚgetattrr/   ÚEXDEVÚRuntimeError)	r(   r)   Úbytesbufferr   ÚurlpathÚis_azurer-   r    Úes	            r!   Ú_atomic_saverD   U   sD  € ô —*‘*“,€KÜ‡I�IÐ# H :Ð.Ô/Ü	‡J�Jˆz˜;Ô'ðä—k‘k×+Ñ+¬C°«MÓ:‰ˆˆGØ�^‰^ñ 	4ØˆHÜ Ô(Ý5ä% bÐ*=Ó>�ä! "Ô%©hð —‘˜ ×!5Ñ!5Ó!7Õ8à—W‘W˜W dÓ+ð 4¨qØ—G‘G˜K×0Ñ0Ó2Ô3÷4÷	4ð 	4÷4ð 4ú÷	4ð 	4ûô ò Ü�a—m‘m¤WÔ-´'¸!¿-¹-ÈÐRVÓ2WÔ[`×[fÑ[fÒ2fÜØoóàðô 3gÔ-ûðúsP   Á7D$ Á;A DÃ DÃ;DÄD$ ÄD	ÄDÄD!ÄD$ Ä!D$ Ä$	F
Ä-AFÆF
r   c                 ó¸   — t        d«      rddlm} t        | |«      ryt        d«      rddlm} t        | |«      ryt        d«      rddlm} t        | |«      ryy	)
Nr+   r   r,   TÚgcsfs)ÚGCSFileSystemÚs3fs)ÚS3FileSystemF)r
   r+   r-   r   rF   rG   rH   rI   )r   r-   rG   rI   s       r!   r6   r6   }   sN   € Ü˜Ô Ý-ä�bÐ-Ô.Øä˜Ô Ý'ä�b˜-Ô(Øä˜ÔÝ%ä�b˜,Ô'Øàr'   Ústrictc                 ó„   — t        | «      r%|r| j                  |«      S | j                  |«       S | j                  |«      S )a¤  Check if a path is directory-like.

    This function determines if a given path is considered directory-like, taking into account the behavior
    specific to object storage platforms. For other filesystems, it behaves similarly to the standard `fs.isdir`
    method.

    Args:
        fs: The filesystem to check the path against.
        path: The path or URL to be checked.
        strict: A flag specific to Object Storage platforms. If set to ``False``, any non-existing path is considered
            as a valid directory-like path. In such cases, the directory (and any non-existing parent directories)
            will be created on the fly. Defaults to False.

    )r6   ÚisdirÚisfile)r   r#   rJ   s      r!   Ú_is_dirrN   “   s>   € ô& ˜"ÔÙØ—8‘8˜D“>Ð!ð —9‘9˜T“?Ð"Ð"à�8‰8�D‹>Ðr'   c                 óX   — t         j                  j                  t        | «      «      dk(  S )NÚfile)r3   ÚutilsÚget_protocolr   )r#   s    r!   Ú_is_local_file_protocolrS   ±   s    € Ü�<‰<×$Ñ$¤S¨£YÓ/°6Ñ9Ð9r'   )NN)F)#Ú__doc__r/   r0   ÚloggingÚpathlibr   Útypingr   r   r   r   r3   Úfsspec.utilsr   Úfsspec.corer   Úfsspec.implementations.localr	   Ú lightning_utilities.core.importsr
   Ú lightning_fabric.utilities.typesr   r   Ú	getLoggerÚ__name__r   Úboolr"   r   Údictr   rD   r6   rN   rS   © r'   r!   ú<module>rb      s  ðñ 0ã Û 	Û Ý ß +Ó +ã Û Û Ý !Ý ;Ý =ç Fà€g×Ñ˜Ó!€ð
 (,Ø#'ñ+
Ø�r˜5�yÑ!ð+
à$ð+
ð ˜4‘.ð+
ð 	ó	+
ð\˜ð ¨#ð Ð2Dó ð
%˜T # s (™^ð %°uð %Àó %ðPÐ-ð °$ó ñ,Ð"ð ¨%°°T°	Ñ*:ð ÀDð ÐUYó ð<: %ð :¨Dô :r'   