
    }Yhx                     .   U d dl Z d dlmZ d dlmZ d dlmZ d dlZd dlm	Z	 d dl
mZmZmZmZ g Zee         ed<   e G d d                      Z e	j        eg            G d	 d
          Ze efdededededdf
dZ	 	 ddddedededededefdZdS )    N)	dataclass)BufferedIOBase)Any)_load_saveDEFAULT_PROTOCOLMAP_LOCATION__all__c                   .    e Zd ZU eed<   eed<   eed<   dS )_Entrykey
is_storagelengthN)__name__
__module____qualname__str__annotations__boolint     r/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/distributed/_serialization.pyr   r      s.         	HHHKKKKKr   r   c                       e Zd ZddZdedededdfdZdeddfd	Z	deddfd
Z
dedefdZdedefdZdedededej        fdZdefdZdS )_PseudoZipFilereturnNc                     i | _         d S Nrecordsselfs    r   __init__z_PseudoZipFile.__init__   s    68r   r   datar   c                     ||f| j         |<   d S r   r   )r"   r   r$   r   s       r   write_recordz_PseudoZipFile.write_record   s    !6NSr   fc           
         g }| j                                         D ]E\  }\  }}|                    t          |t	          |t
          j                  |                     Ft          j        ||t                     | j                                         D ]\  }\  }}t	          |t                    r|                    |           3t	          |t                    r)|                    |                    d                     qt	          |t
          j                  r|                    |ddd           t          dt!          |                     d S )N)r   r   r   )protocolutf-8F   zunknown type: )r    itemsappendr   
isinstancetorchUntypedStoragepickledumpr   byteswriter   encode_write_file	TypeErrortype)r"   r'   entriesr   r$   r   s         r   write_toz_PseudoZipFile.write_to   s_   #'<#5#5#7#7 	 	C$NN)$0DEE!      	GQ)9::::#'<#5#5#7#7 	? 	?C$$&& ?D#&& ?G,,----D%"677 ?  E5!4444 =d = =>>>	? 	?r   c                 8   t          j        |          }|D ]}|                    |j                  }|j        rIt          j        |t
          j                                                  }||j        f| j	        |j
        <   l||j        f| j	        |j
        <   d S )Ndtype)_weights_only_unpicklerloadreadr   r   r/   
frombufferuint8untyped_storager    r   )r"   r'   r9   entryr$   storages         r   	read_fromz_PseudoZipFile.read_from6   s    ).q11 	? 	?E66%,''D ?*+   "/##  L+UY''
 ,0*>UY''	? 	?r   c                     || j         v S r   r   r"   r   s     r   
has_recordz_PseudoZipFile.has_recordH   s    dl""r   c                 (    | j         |         d         S )Nr   r   rH   s     r   
get_recordz_PseudoZipFile.get_recordK   s    |C ##r   _length_typec                 d    t          j        | j        |         d         t           j                  S )Nr   r<   )r/   tensorr    rB   )r"   r   rL   rM   s       r   get_storage_from_recordz&_PseudoZipFile.get_storage_from_recordN   s'     |DL-a0DDDDr   c                     dS )Ntorchftr   r!   s    r   serialization_idz_PseudoZipFile.serialization_idS   s    yr   )r   N)r   r   r   r#   r   objectr   r&   r   r:   rF   r   rI   rK   r/   TensorrP   rS   r   r   r   r   r      s9       9 9 9 9+ +6 +3 +4 + + + +?. ?T ? ? ? ?.?> ?d ? ? ? ?$#c #d # # # #$c $f $ $ $ $EE!$E-0E	E E E E
#      r   r   objr'   pickle_modulepickle_protocolr   c                 t    t                      }t          | |||d           |                    |           dS )a5  
    Save the object to a file-like object in a streaming fashion compatible with
    network sockets.

    This behaves similarly to :func:`torch.save` with a few notable differences:

    * A non-seekable file like object can be used when loading.
    * No forwards/backwards compatibility is provided for the serialization
      format. This is only intended to be used with a single version of PyTorch
      with transient storage (i.e. sockets or temp files).
    * mmap is not supported

    See :func:`torch.save` for more details on specific arguments.
    F)zip_filerW   rX   _disable_byteorder_recordN)r   r   r:   )rV   r'   rW   rX   rZ   s        r   _streaming_saver\   W   sQ    * H	#'"'    ar   T)weights_onlymap_locationr]   pickle_load_argsc                    |r|t          d          t          }n	|t          }d|                                vrd|d<   t	                      }|                    |            t          d|||d|S )a  
    Load the object from a file-like object in a streaming fashion compatible with
    network sockets.

    See :func:`_streaming_save` for more details about the streaming behavior.

    See :func:`torch.load` for more details on specific arguments.
    NzDCan not safely load weights when explicit pickle_module is specifiedencodingr*   )rZ   r^   rW   r   )RuntimeErrorr>   r1   keysr   rF   r   )r'   r^   rW   r]   r_   rZ   s         r   _streaming_loadrd   w   s       #$V   0 "M)..0000'.$Hq !#  	  r   )NN)r1   dataclassesr   ior   typingr   r/   torch._weights_only_unpicklerr>   torch.serializationr   r   r   r	   r
   listr   r   r   _add_safe_globalsr   rT   r   r\   r   rd   r   r   r   <module>rl      s    ! ! ! ! ! !              ? ? ? ? ? ? L L L L L L L L L L L L c            *  )6( 3 3 3< < < < < < < <D  +	 	  	
 
   D "&$
 $ $ $$$ $
 $ $ $ $ $ $ $ $r   