§
    “©ºj°  ã            	       ón  — 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"dS )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          | ¦  «                             d¦  «        rQ|€ d}t                               d| › d�¦  «         t          j         	                    t          | ¦  «        ||¬¦  «        S t          | ¦  «        }|                     | d¦  «        5 }t          j        |||¬¦  «        cddd¦  «         S # 1 swxY w Y   dS )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        ús/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/lightning_fabric/utilities/cloud_io.pyÚ_loadr"   "   sj  € õ" �k¥C­ ;Ñ/Ô/ð 
åŒzØØ%Ø%ð
ñ 
ô 
ð 	
õ
 ˆ;ÑÔ×"Ò" 6Ñ*Ô*ð 
ØÐØ ˆLÝ�IŠIðoÈ[ð oð oð oñô ð õ
 Œy×1Ò1Ý�ÑÔØ%Ø%ð 2ñ 
ô 
ð 	
õ
 
˜Ñ	$Ô	$€BØ	�Š�˜dÑ	#Ô	#ð 
 qÝŒzØØ%Ø%ð
ñ 
ô 
ð
ð 
ð 
ð 
ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
øøøð 
ð 
ð 
ð 
ð 
ð 
s   ÃC0Ã0C4Ã7C4ÚpathÚkwargsc                 ó@   — t          t          | ¦  «        fi |¤Ž\  }}|S )N)r   r   )r#   r$   r   Ú_s       r!   r   r   P   s&   € Ý•c˜$‘i”iÐ*Ð* 6Ð*Ð*�E€BˆØ€Ió    Ú
checkpointÚfilepathc                 ót  — t          j        ¦   «         }t                               d|› �¦  «         t	          j        | |¦  «         	 t          j                             t          |¦  «        ¦  «        \  }}|j
        5  d}t          d¦  «        rddlm} t          ||¦  «        }t          |¦  «        r+|s)|                     ||                     ¦   «         ¦  «         nU|                     |d¦  «        5 }|                     |                     ¦   «         ¦  «         ddd¦  «         n# 1 swxY w Y   ddd¦  «         dS # 1 swxY w Y   dS # t(          $ r_}t          |j        t,          ¦  «        r4t/          |j        dd¦  «        t0          j        k    rt5          d	¦  «        |‚Y d}~dS Y d}~dS 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   s]  € õ ”*‘,”,€KÝ‡I‚IÐ. HÐ.Ð.Ñ/Ô/Ð/Ý	„Jˆz˜;Ñ'Ô'Ð'ðå”k×+Ò+­C°©M¬MÑ:Ô:‰ˆˆGØŒ^ð 	4ð 	4ØˆHÝ Ñ(Ô(ð ?Ø5Ð5Ð5Ð5Ð5Ð5å% bÐ*=Ñ>Ô>�å! "Ñ%Ô%ð 4¨hð 4ð —’˜ ×!5Ò!5Ñ!7Ô!7Ñ8Ô8Ð8Ð8à—W’W˜W dÑ+Ô+ð 4¨qØ—G’G˜K×0Ò0Ñ2Ô2Ñ3Ô3Ð3ð4ð 4ð 4ñ 4ô 4ð 4ð 4ð 4ð 4ð 4ð 4øøøð 4ð 4ð 4ð 4ð	4ð 	4ð 	4ñ 	4ô 	4ð 	4ð 	4ð 	4ð 	4ð 	4ð 	4ð 	4øøøð 	4ð 	4ð 	4ð 	4ð 	4ð 	4øõ ð ð ð Ý�a”m¥WÑ-Ô-ð 	µ'¸!¼-ÈÐRVÑ2WÔ2WÕ[`Ô[fÒ2fÐ2fÝØoñô àðð	ð 	ð 	ð 	ð 	ð 	Ð2fÐ2fÐ2fÐ2fÐ2fÐ2føøøøðøøøsb   Á6E Á=A8EÃ5(D)ÄEÄ)D-	Ä-EÄ0D-	Ä1EÄ4E ÅEÅE ÅEÅ	E Å
F7ÅAF2Æ2F7r   c                 óð   — t          d¦  «        rddlm} t          | |¦  «        rdS t          d¦  «        rddlm} t          | |¦  «        rdS t          d¦  «        rddlm} t          | |¦  «        rdS d	S )
Nr+   r   r,   TÚgcsfs)ÚGCSFileSystemÚs3fs)ÚS3FileSystemF)r
   r+   r-   r   rF   rG   rH   rI   )r   r-   rG   rI   s       r!   r6   r6   }   s³   € Ý˜Ñ Ô ð Ø-Ð-Ð-Ð-Ð-Ð-å�bÐ-Ñ.Ô.ð 	Ø�4å˜Ñ Ô ð Ø'Ð'Ð'Ð'Ð'Ð'å�b˜-Ñ(Ô(ð 	Ø�4å˜ÑÔð Ø%Ð%Ð%Ð%Ð%Ð%å�b˜,Ñ'Ô'ð 	Ø�4àˆ5r'   FÚstrictc                 ó¤   — t          | ¦  «        r-|r|                      |¦  «        S |                      |¦  «         S |                      |¦  «        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   “   sQ   € õ& ˜"ÑÔð #Øð 	"Ø—8’8˜D‘>”>Ð!ð —9’9˜T‘?”?Ð"Ð"à�8Š8�D‰>Œ>Ðr'   c                 ób   — t           j                             t          | ¦  «        ¦  «        dk    S )NÚfile)r3   ÚutilsÚget_protocolr   )r#   s    r!   Ú_is_local_file_protocolrS   ±   s#   € ÝŒ<×$Ò$¥S¨¡Y¤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Ð FÐ FÐ FÐ FÐ FÐ FÐ Fà€gÔ˜Ñ!Ô!€ð
 (,Ø#'ð+
ð +
Ø�r˜5�yÔ!ð+
à$ð+
ð ˜4”.ð+
ð 	ð	+
ð +
ð +
ð +
ð\˜ð ¨#ð Ð2Dð ð ð ð ð
%˜T # s (œ^ð %°uð %Àð %ð %ð %ð %ðPÐ-ð °$ð ð ð ð ð,ð Ð"ð ¨%°°T°	Ô*:ð ÀDð ÐUYð ð ð ð ð<: %ð :¨Dð :ð :ð :ð :ð :ð :r'   