L ixUddlZddlmZddlmZddlmZddlZddlm Z ddl m Z m Z m Z mZgZeeed<eGddZe j(egGd d Zee fd ed ed ededdf dZ dddd eded edededef dZy)N) dataclass)BufferedIOBase)Any)_load_saveDEFAULT_PROTOCOL MAP_LOCATION__all__c,eZdZUeed<eed<eed<y)_Entrykey is_storagelengthN)__name__ __module__ __qualname__str__annotations__boolintf/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/distributed/_serialization.pyr r s H Krr ceZdZddZdedededdfdZdeddfd Z deddfd Z dede fd Z dedefd Z ded ededejfdZdefdZy)_PseudoZipFilereturnNci|_yNrecordsselfs r__init__z_PseudoZipFile.__init__s 68 rr datarc&||f|j|<yrr)r"r r$rs r write_recordz_PseudoZipFile.write_records!6N Srfc ng}|jjD]=\}\}}|jt|t |t j |?tj||t|jjD]\}\}}t |tr|j|+t |tr!|j|jd\t |t j r|j|dddtdt!|y)N)r rr)protocolutf-8Fzunknown type: )r itemsappendr isinstancetorchUntypedStoragepickledumprbyteswriterencode _write_file TypeErrortype)r"r'entriesr r$rs rwrite_toz_PseudoZipFile.write_tos#'<<#5#5#7  C$ NN)$0D0DE!    GQ)9:#'<<#5#5#7 ? C$$& D#& G,-D%"6"67  E5!4.d =>> ?rctj|}|D]}|j|j}|jrYt j |t jj}||jf|j|j<||jf|j|j<y)Ndtype) _weights_only_unpicklerloadreadrrr/ frombufferuint8untyped_storager r )r"r'r9entryr$storages r read_fromz_PseudoZipFile.read_from6s)..q1 ?E66%,,'D**++"/# LL+ UYY' ,0*> UYY' ?rc||jvSrrr"r s r has_recordz_PseudoZipFile.has_recordHsdll""rc&|j|dS)NrrrHs r get_recordz_PseudoZipFile.get_recordKs||C ##r_length_typecltj|j|dtjS)Nrr<)r/tensorr rB)r"r rLrMs rget_storage_from_recordz&_PseudoZipFile.get_storage_from_recordNs'||DLL-a0 DDrcy)Ntorchftrr!s rserialization_idz_PseudoZipFile.serialization_idSsr)rN)rrrr#robjectrr&rr:rFrrIrKr/TensorrPrSrrrrrs9++6+3+4+?.?T?.?>?d?$#c#d#$c$f$EE!$E-0E E #rrobjr' pickle_modulepickle_protocolrcZt}t||||d|j|y)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_filerWrX_disable_byteorder_recordN)rrr:)rVr'rWrXrZs r_streaming_saver\Ws3*H  #'"'  arT) weights_only map_locationr]pickle_load_argsc |r| tdt}n|t}d|jvrd|d<t }|j |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. zDCan not safely load weights when explicit pickle_module is specifiedencodingr*)rZr^rWr) RuntimeErrorr>r1keysrrFr)r'r^rWr]r_rZs r_streaming_loadrdws   $V 0  "M)..00'.$H q  !#    r)NN)r1 dataclassesriortypingrr/torch._weights_only_unpicklerr>torch.serializationrrrr r listrrr _add_safe_globalsrrTrr\rrdrrrrls ! ?LLc   *))6(3<<D +     D"&$  $$$$  $  $ $r