
    Aܶi                     .   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     e/root/projects/openclaw-proxy/venv/lib64/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|                    |           0t	          |t                    r)|                    |                    d                     nt	          |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   valuesbyteswriter   encode_write_file	TypeErrortype)r"   r'   entriesr   r$   r   _s          r   write_toz_PseudoZipFile.write_to   sZ   #'<#5#5#7#7 	 	C$NN)$0DEE!      	GQ)9::::|**,, 	? 	?GD!$&& ?D#&& ?G,,----D%"677 ?  E5!4444 =d = =>>>	? 	?r   c                 x   t          j        |          }|D ]}|                    |j                  }|j        ri|j        dk    rt          j        d          }n2t          j        |t
          j                  	                                }||j        f| j
        |j        <   ||j        f| j
        |j        <   d S Nr   )dtype)_weights_only_unpicklerloadreadr   r   r/   r0   
frombufferuint8untyped_storager    r   )r"   r'   r:   entryr$   storages         r   	read_fromz_PseudoZipFile.read_from6   s    ).q11 	? 	?E66%,''D ?<1$$#2155GG#.#k   &o''  L+UY''
 ,0*>UY''!	? 	?r   c                     || j         v S r   r   r"   r   s     r   
has_recordz_PseudoZipFile.has_recordK   s    dl""r   c                 (    | j         |         d         S )Nr   r   rJ   s     r   
get_recordz_PseudoZipFile.get_recordN   s    |C ##r   _length_typec                 d    t          j        | j        |         d         t           j                  S r>   )r/   tensorr    rD   )r"   r   rN   rO   s       r   get_storage_from_recordz&_PseudoZipFile.get_storage_from_recordQ   s'     |DL-a0DDDDr   c                     dS )Ntorchftr   r!   s    r   serialization_idz_PseudoZipFile.serialization_idV   s    yr   )r   N)r   r   r   r#   r   objectr   r&   r   r<   rH   r   rK   rM   r/   TensorrR   rU   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_filerY   rZ   _disable_byteorder_recordN)r   r   r<   )rX   r'   rY   rZ   r\   s        r   _streaming_saver^   Z   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*   )r\   r`   rY   r   )RuntimeErrorr@   r1   r   rH   r   )r'   r`   rY   r_   ra   r\   s         r   _streaming_loadre   z   s       #$V   0 "M)))'.$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   rV   r   r^   r   re   r   r   r   <module>rm      s    ! ! ! ! ! !              ? ? ? ? ? ? L L L L L L L L L L L L c            *  )6( 3 3 3? ? ? ? ? ? ? ?J  +	 	  	
 
   D "&$
 $ $ $$$ $
 $ $ $ $ $ $ $ $r   