� J��gz����UddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZddlmZddlmZddlmZddlmZddlmZdd lmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$dd l%m&Z&m'Z'ddl(Z(ddl)Z)ddl*m+Z+d Z,ej-d ��j.Z/ej-d ��j.Z0ej-d��j.Z1dZ2dZ3dZ4e"e5ej6ee#e7fZ8e&e9d<ee"eee5gefej:e5ee5e5ffZ;e&e9d<e"eej<j=ej>fZ?e&e9d<ej@dkZAeAs ddlBmCZCmDZDnd\ZCZDgd�ZEGd�deF��ZGed���ZHgZIe$e!eJee?gee5fee?e5gee?ffe9d<Gd�de��ZKdaLeeKe9d<d eeKfd!�ZMd"�ZNeDaOeJe9d#<d eJfd$�ZPd%eJfd&�ZQd~d'�ZRd e$efd(�ZSd)e$ed dfd*�ZTd eUfd+�ZVd,eJd-ee?gee5fd.ee?e5gee?ffd/�ZWdd1�ZXd2�ZYd3�ZZd4�Z[d5�Z\d6�Z]d7�Z^d8�Z_d9�Z`d:�Zad;�Zbd<�ZceWd=eYe]��eWd>ejde\d?��ejdecd?����eWd@eZe^��eWdAe[e_��eWdBejde\dC��ejdecdC����eWdDejde\dE��ejdecdE����eWdFejde\dG��ejdecdG����dHe"eej<j=ej>ffdI�ZedJ�ZfdK�ZgdL�Zhd e'e"e5ej6ffdM�ZiGdN�dO��ZjGdP�dQej��ZkGdR�dSej��ZlGdT�dUej��ZmdV�ZnGdW�dXej��ZoGdY�dZej��ZpGd[�d\ej��Zqd]�Zrd eUfd^�Zsd_�Ztd eUfd`�Zud~da�Zvdb�Zwe)e,d0dcfddexdee8dfedgeJdheUdieUd dfdj�Zyd~dk�Zzdl�Z{ ddddm�dee8dne;dfedoeeUdpeeUdqed efdr�Z|ds�Z}ie}_~e(j)ejdt���du�Z�dve"e7e5fd e5fdw�Z�dx�Z�Gdy�dz��Z�d�d|�Z�d}�Z�dS)��N)�closing�contextmanager)�Enum�)�_import_dotted_name)�get_source_lines_and_file)�Storage)�#_get_dtype_from_pickle_storage_type) �Any�BinaryIO�Callable�cast�Dict�Optional�Type�Tuple�Union�IO�List)� TypeAlias� TypeGuard�z=lz=iz=hll|9 �QC i��,� FILE_LIKE� MAP_LOCATION�STORAGE�win32)� MAP_SHARED� MAP_PRIVATE)NN)�SourceChangeWarning�mkdtemp�register_package�%check_module_version_greater_or_equal�validate_cuda_device�validate_hpu_device� location_tag�default_restore_location�normalize_storage_type�storage_to_tensor_type�save�load� StorageType�LoadEndianness�get_default_load_endianness�set_default_load_endianness�clear_safe_globals�get_safe_globals�add_safe_globalsc��eZdZdS)r N)�__name__� __module__� __qualname__���c/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/torch/serialization.pyr r Fs�������Dr8r c#�K�tj��} |V�tj|��dS#tj|��wxYw�N)�tempfiler!�shutil�rmtree��paths r9r!r!JsN���� � � � �D��� � � �� �d�������� �d�������s �1�A�_package_registryc��eZdZdZdZdZdS)r-rr�N)r4r5r6�NATIVE�LITTLE�BIGr7r8r9r-r-Us������ �F� �F� �C�C�Cr8r-�_default_load_endian�returnc��tS)a Get fallback byte order for loading files If byteorder mark is not present in saved checkpoint, this byte order is used as fallback. By default, it's "native" byte order. Returns: default_load_endian: Optional[LoadEndianness] )rGr7r8r9r.r.\s �� �r8c�V�t|t��s|�td���|adS)z� Set fallback byte order for loading files If byteorder mark is not present in saved checkpoint, this byte order is used as fallback. By default, it's "native" byte order. Args: endianness: the new fallback byte order Nz=Invalid argument type in function set_default_load_endianness)� isinstancer-� TypeErrorrG)� endiannesss r9r/r/is7�� �j�.� 1� 1�Y�j�6L��W�X�X�X�%���r8�_default_mmap_optionsc��tS)z� Get default mmap options for :func:`torch.load` with ``mmap=True``. Defaults to ``mmap.MAP_PRIVATE``. Returns: default_mmap_options: int )rNr7r8r9�get_default_mmap_optionsrP{s �� !� r8�flagsc��trtd���|tkr|tkrt d|�����|adS)a� Set default mmap options for :func:`torch.load` with ``mmap=True`` to flags. For now, only either ``mmap.MAP_PRIVATE`` or ``mmap.MAP_SHARED`` are supported. Please open an issue if you need any other option to be added here. .. note:: This feature is currently not supported for Windows. Args: flags: ``mmap.MAP_PRIVATE`` or ``mmap.MAP_SHARED`` zHChanging the default mmap options is currently not supported for WindowszmInvalid argument in function set_default_mmap_options, expected mmap.MAP_PRIVATE or mmap.MAP_SHARED, but got N)� IS_WINDOWS� RuntimeErrorrr� ValueErrorrN)rQs r9�set_default_mmap_optionsrV�sg���g��e�f�f�f� �����*�!4�!4��Z�RW�Z�Z�[�[� [�!���r8c�,�tj��dS)zM Clears the list of globals that are safe for ``weights_only`` load. N)�_weights_only_unpickler�_clear_safe_globalsr7r8r9r0r0�s���/�1�1�1�1�1r8c�(�tj��S)zY Returns the list of user-added globals that are safe for ``weights_only`` load. )rX�_get_safe_globalsr7r8r9r1r1�s�� #� 4� 6� 6�6r8� safe_globalsc�.�tj|��dS)ai Marks the given globals as safe for ``weights_only`` load. For example, functions added to this list can be called during unpickling, classes could be instantiated and have state set. Args: safe_globals (List[Any]): list of globals to mark as safe Example: >>> # xdoctest: +SKIP("Can't torch.save(t, ...) as doctest thinks MyTensor is defined on torch.serialization") >>> import tempfile >>> class MyTensor(torch.Tensor): ... pass >>> t = MyTensor(torch.randn(2, 3)) >>> with tempfile.NamedTemporaryFile() as f: ... torch.save(t, f.name) # Running `torch.load(f.name, weights_only=True)` will fail with # Unsupported global: GLOBAL __main__.MyTensor was not an allowed global by default. # Check the code and make sure MyTensor is safe to be used when loaded from an arbitrary checkpoint. ... torch.serialization.add_safe_globals([MyTensor]) ... torch.load(f.name, weights_only=True) # MyTensor([[-0.5024, -1.8152, -0.5455], # [-0.8234, 2.0500, -0.3657]]) N)rX�_add_safe_globals)r\s r9r2r2�s��2�-�l�;�;�;�;�;r8c��|���}d}|�t|����}|�|��||kS)NsPK)�tell�read�len�seek)�f�start�local_header_magic_number� read_bytess r9� _is_zipfilerh�sL�� �F�F�H�H�E� -������5�6�6�7�7�J��F�F�5�M�M�M� �2� 2�2r8�priority�tagger� deserializerc�v�|||f}t�|��t���dS)a� Registers callables for tagging and deserializing storage objects with an associated priority. Tagging associates a device with a storage object at save time while deserializing moves a storage object to an appropriate device at load time. :attr:`tagger` and :attr:`deserializer` are run in the order given by their :attr:`priority` until a tagger/deserializer returns a value that is not `None`. To override the deserialization behavior for a device in the global registry, one can register a tagger with a higher priority than the existing tagger. This function can also be used to register a tagger and deserializer for new devices. Args: priority: Indicates the priority associated with the tagger and deserializer, where a lower value indicates higher priority. tagger: Callable that takes in a storage object and returns its tagged device as a string or None. deserializer: Callable that takes in storage object and a device string and returns a storage object on the appropriate device or None. Returns: `None` Example: >>> def ipu_tag(obj): >>> if obj.device.type == 'ipu': >>> return 'ipu' >>> def ipu_deserialize(obj, location): >>> if location.startswith('ipu'): >>> ipu = getattr(torch, "ipu", None) >>> assert ipu is not None, "IPU device module is not loaded" >>> assert torch.ipu.is_available(), "ipu is not available" >>> return obj.ipu(location) >>> torch.serialization.register_package(11, ipu_tag, ipu_deserialize) N)rA�append�sort)rirjrk� queue_elems r9r"r"�s=��P�F�L�1�J����Z�(�(�(��������r8Tc �d�� |j�d���t�fd�t|��D����}||k}nd#t$rW}d|j�d|j�dt |����}|rt|��|�tj |dz��d}Yd}~nd}~wwxYw|S) a� Check if a module's version satisfies requirements Usually, a module's version string will be like 'x.y.z', which would be represented as a tuple (x, y, z), but sometimes it could be an unexpected format. If the version string does not match the given tuple's format up to the length of the tuple, then error and exit or emit a warning. Args: module: the module to check the version of req_version_tuple: tuple (usually of ints) representing the required version error_if_malformed: whether we should exit if module version string is malformed Returns: requirement_is_met: bool �.c3�Z�K�|]%\}}t|���|��V��&dSr;)�type)�.0�idx� req_field� version_strss �r9� <genexpr>z8check_module_version_greater_or_equal.<locals>.<genexpr>sM����� � �3A�3� �O�D��O�O�L��-� .� .� � � � � � r8�'z&' module version string is malformed 'z$' and cannot be compared with tuple z1, but continuing assuming that requirement is metTN) � __version__�split�tuple� enumerate� Exceptionr4�strrT�warnings�warn)�module�req_version_tuple�error_if_malformed�module_version�requirement_is_met�e�messagerws @r9r#r#s���"&��)�/�/��4�4� �� � � � �EN�O`�Ea�Ea� � � � � ��,�/@�@���� � &� &� &� 4��� 4� 4�v�GY� 4� 4��0�1�1� 4� 4� � � &��w�'�'�Q� .� �M�'�$W�W� X� X� X�!%� � � � � � ����� &���� �s�AA � B-�A B(�(B-c�*�|jjdkrdSdS�N�cpu��devicers��objs r9�_cpu_tagr�'��� �z��%����u� �r8c�*�|jjdkrdSdS�N�mpsr�r�s r9�_mps_tagr�,r�r8c�*�|jjdkrdSdS)N�metar�r�s r9� _meta_tagr�1s�� �z��&� � ��v�!� r8c���|dkrtj���}|jj|kr-|jj�|S|dzt |jj��zSdS)N� privateuse1�:)�torch�_C�_get_privateuse1_backend_namer�rs�indexr)� backend_namer�s r9� _backend_tagr�6se���}�$�$��x�=�=�?�?� � �z��,�&�&� �:� � #�� ��#�%��C�J�,<�(=�(=�=� =� '�&r8c��|dkr|SdSr�r7�r��locations r9�_cpu_deserializer�@s���5���� ��r8c�X�|�d��r|���SdSr�)� startswithr�r�s r9�_mps_deserializer�Es0�����5�!�!���w�w�y�y���r8c�b�|dkr(tj|���d���SdS)Nr��r�)r��UntypedStorage�nbytesr�s r9�_meta_deserializer�Js3���6����#�C�J�J�L�L��@�@�@�@��r8c ���tt|��s%td|����d����t t|��}t|d��rFt|jd��r1|j�|d��}tj||��}n$tj|��}|jr|jnd}t|d��r<|� ��s(td|����d |�d ����t|d ��rH|� ��}||kr.td |����d |�d|�d|�d� ���|S)a Check whether the device index of specified backend is valid In case of privateuse1 backend, your must first register a device_module for privateuse1 using torch._register_device_module. Implement the following methods in device_module like cuda: device_module._utils._get_device_index(location, True), device_module.device_count(). Args: location: string of device backend_name: the backend name or the name of privateuse1, which can be renamed Returns: device_index: int zThe z� device module is not registered. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.�_utils�_get_device_indexTr� is_availablez&Attempting to deserialize object on a z device but torch.z�.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.� device_countz$Attempting to deserialize object on z device z but torch.z.device_count() is zU. Please use torch.load with map_location to map your storages to an existing device.) �hasattrr�rT�upper�getattrr�r�r�r�r�r�)r�r�� device_module� device_indexr�r�s r9�_validate_devicer�Os��� �5�,� '� '�?��>�,�"4�"4�"6�"6�>�>�>�?�?� ?��E�<�0�0�M��}�h�'�'�;�G�M�4H�J]�,^�,^�;�$�+�=�=�h��M�M� ���l�L�9�9�����h�'�'��'-�|�:�v�|�|�� ��}�n�-�-�?�m�6P�6P�6R�6R�?��>�L�DV�DV�DX�DX�>�>�/;�>�>�>�?�?� ?� �}�n�-�-�9�$�1�1�3�3� � �<� '� '�� 8�l�FX�FX�FZ�FZ� 8� 8�".� 8� 8�;G� 8� 8�\h� 8� 8� 8�9�9� 9� �Mr8c�,�t|d��jS)N�cuda�r�r��r�s r9r$r${s�� �H�f� -� -� 3�3r8c�,�t|d��jS)N�hpur�r�s r9r%r%s�� �H�e� ,� ,� 2�2r8c���|dkrtj���}|�|��r&t ||��}|�|���SdS)Nr�r�)r�r�r�r�r��to)r�r�r�r�s r9� _deserializer��sc���}�$�$��x�=�=�?�?� ����<�(�(�%�!�(�L�9�9���v�v�V�v�$�$�$�%�%r8� �r����r��r���xpu�storagec��tD]\}}}||��}|r|cS�tdtj|��z���)Nz-don't know how to determine data location of �rArTr��typename)r��_rjr�s r9r&r&�sa��)��� ��6�1��6�'�?�?�� � ��O�O�O� � �F����0�0�1� 2� 2�2r8c��tD]\}}}|||��}|�|cS�tdtj|��zdz|zdz���)Nz+don't know how to restore data location of z (tagged with �)r�)r�r�r��fn�results r9r'r'�s|��%�����1�b���G�X�&�&�� � ��M�M�M� � �D����0�0�1�3C�D�!�"�$'�(� )� )�)r8c�6�tt|j��Sr;)r�r�r4)� storage_types r9r(r(�s�� �5�,�/� 0� 0�0r8c��t|��}t|j��}t||j�dd����S)Nr �Tensor)rsrr5r�r4�replace)r�r�r�s r9r)r)�s@����=�=�L� ��!8� 9� 9�F� �6�<�0�8�8��H�M�M� N� N�Nr8c�D�t|ttjf��Sr;)rKr�os�PathLike)�name_or_buffers r9�_is_pathr��s�� �n�s�B�K�&8� 9� 9�9r8c� �eZdZd�Zd�Zd�ZdS)�_openerc��||_dSr;�� file_like)�selfr�s r9�__init__z_opener.__init__�s ��"����r8c��|jSr;r��r�s r9� __enter__z_opener.__enter__�s ���~�r8c��dSr;r7�r��argss r9�__exit__z_opener.__exit__�s�� �r8N)r4r5r6r�r�r�r7r8r9r�r��sA������#�#�#���� � � � � r8r�c�$��eZdZ�fd�Zd�Z�xZS)� _open_filec�f��t���t||����dSr;)�superr��open)r��name�mode� __class__s �r9r�z_open_file.__init__�s+��� ������d�D�)�)�*�*�*�*�*r8c�8�|j���dSr;)r��closer�s r9r�z_open_file.__exit__���� ��������r8�r4r5r6r�r�� __classcell__�r�s@r9r�r��sG�������+�+�+�+�+�������r8r�c���eZdZ�fd�Z�xZS)�_open_buffer_readerc�h��t���|��t|��dSr;)r�r��_check_seekable)r��bufferr�s �r9r�z_open_buffer_reader.__init__�s/��� ������ � � �������r8�r4r5r6r�r�r�s@r9r�r��s8������� � � � � � � � � r8r�c��eZdZd�ZdS)�_open_buffer_writerc�8�|j���dSr;)r��flushr�s r9r�z_open_buffer_writer.__exit__�r�r8N)r4r5r6r�r7r8r9rr�s#����������r8rc��t|��rt||��Sd|vrt|��Sd|vrt|��St d|�����)N�w�rz$Expected 'r' or 'w' in mode but got )r�r�rr�rT)r�r�s r9�_open_file_liker�sh������N��.�$�/�/�/� �$�;�;�&�~�6�6� 6� �D�[�[�&�~�6�6� 6��L�d�L�L�M�M� Mr8c� ��eZdZd�fd� Z�xZS)�_open_zipfile_readerrHNc���t���tj�|����dSr;)r�r�r�r��PyTorchFileReader)r�r�r�s �r9r�z_open_zipfile_reader.__init__�s1��� �������3�3�N�C�C�D�D�D�D�Dr8�rHNr�r�s@r9rr�sG�������E�E�E�E�E�E�E�E�E�Er8rc�(��eZdZd�fd� Zdd�Z�xZS)�_open_zipfile_writer_filerHNc����d|_t|��|_ |j�d��t ���t j�|j����dS#t$rgtj |jd���|_t ���t j�|j����YdSwxYw)N�asciir)r�) � file_streamrr��encoder�r�r�r��PyTorchFileWriter�UnicodeEncodeError�io�FileIO)r�r�r�s �r9r�z"_open_zipfile_writer_file.__init__�s���������I�I�� � D� �I� � �W� %� %� %� �G�G� � �U�X�7�7�� �B�B� C� C� C� C� C��"� K� K� K� "�y����=�=�=�D� � �G�G� � �U�X�7�7��8H�I�I� J� J� J� J� J� J�  K���s�A=�=A-C.�-C.c�|�|j���|j�|j���dSdSr;)r��write_end_of_filerr�r�s r9r�z"_open_zipfile_writer_file.__exit__�sB�� ��(�(�*�*�*� � � '� � � "� "� $� $� $� $� $� (� 'r8r r�r�s@r9r r �sW������� D� D� D� D� D� D�%�%�%�%�%�%�%�%r8r c�(��eZdZd�fd� Zdd�Z�xZS)�_open_zipfile_writer_bufferrHNc���tt|dd����sadtt|�����d���d�}t |d��st |���t|���||_t��� tj � |����dS)N�writez Buffer of z<>z" has no callable attribute 'write')�callabler�rrs�stripr��AttributeErrorrLr�r�r�r�r�r)r�r��msgr�s �r9r�z$_open_zipfile_writer_buffer.__init__�s���������6�6�7�7� !�`�s�4��<�<�0�0�6�6�t�<�<�`�`�`�C��6�7�+�+� *�$�S�)�)�)��C�.�.� ��� � �������3�3�F�;�;�<�<�<�<�<r8c�j�|j���|j���dSr;)r�rr�rr�s r9r�z$_open_zipfile_writer_buffer.__exit__s0�� ��(�(�*�*�*� � �������r8r r�r�s@r9rr�sQ�������=�=�=�=�=�=��������r8rc�T�t|��rt}nt}||��Sr;)r�r r)r�� containers r9�_open_zipfile_writerr#s.������0�-� � �/� � �9�^� $� $�$r8c�>�dg} |j|vS#t$rYdSwxYw)N�gzipF)r5r)rd�compress_moduless r9�_is_compressed_filer's?���x����|�/�/�/�� �����u�u����s �� �c��t|��rdS |���dkS#tj$rYdSt$rYdSwxYw)z� Checks if f is a file that should be read directly. It should be read directly if it is backed by a real file (has a fileno) and is not a a compressed file (e.g. gzip) Fr)r'�filenor�UnsupportedOperationr�rds r9�_should_read_directlyr,sn�� �1�����u���x�x�z�z�Q���� � "�����u�u� �����u�u����s�+�A � A � A c���d�} |�|�����dS#tjtf$r}|ddg|��Yd}~nd}~wwxYwdS)Nc��|D]C}|t|��vr0t|��dzdzdz}t|��|����D|�)Nz7. You can only torch.load from a file that is seekable.z; Please pre-load the data into a buffer like io.BytesIO andz try to load from it instead.)rrs)�patternsr��prs r9� raise_err_msgz&_check_seekable.<locals>.raise_err_msg*se��� #� #�A��C��F�F�{�{��1�v�v� Y�Y�"_�`�"A�B���d�1�g�g�c�l�l�"� � �r8Trcr`F)rcr`rr*r)rdr1r�s r9r�r�(s������+� ���q�v�v�x�x�����t�� � #�^� 4�+�+�+�� �v�v�&��*�*�*�*�*�*�*�*�����+���� �5s�'.�A�A�Ac���|�c|jdkrZd}t||d��sItd�d�d�|D����|j�����dSdSdS)z�Checks if using dill as the pickle module, and if so, checks if it is the correct version. If dill version is lower than 0.3.1, a ValueError is raised. Args: pickle_module: module used for pickling metadata and objects N�dill)rrCrFz\'torch' supports dill >= {}, but you have dill {}. Please upgrade dill or switch to 'pickle'rqc�,�g|]}t|����Sr7)r)rt�nums r9� <listcomp>z'_check_dill_version.<locals>.<listcomp>Js��D�D�D�s�#�c�(�(�D�D�Dr8)r4r#rU�format�joinrz)� pickle_module�required_dill_versions r9�_check_dill_versionr;;s���� �]�%;�v�%E�%E� )��4�]�DY�[`�a�a� ��=��f����D�D�.C�D�D�D�E�E��)����� �!� �%E�%E� � r8c�f�t|��st|d��std���dSdS)NrzOexpected 'f' to be string, path, or a file-like object with a 'write' attribute)r�r�rr+s r9�_check_save_fileliker=OsL�� �A�;�;�#�w�q�'�2�2�#�� "�#�#� #�#�#�#�#r8Fr�rdr9�pickle_protocol�_use_new_zipfile_serialization�_disable_byteorder_recordc�v�tj�d��t|��t |��|r>t |��5}t |||||�� ddd��dS#1swxYwYdSt|d��5}t||||��ddd��dS#1swxYwYdS)aPsave(obj, f, pickle_module=pickle, pickle_protocol=DEFAULT_PROTOCOL, _use_new_zipfile_serialization=True) Saves an object to a disk file. See also: :ref:`saving-loading-tensors` Args: obj: saved object f: a file-like object (has to implement write and flush) or a string or os.PathLike object containing a file name pickle_module: module used for pickling metadata and objects pickle_protocol: can be specified to override the default protocol .. note:: A common PyTorch convention is to save tensors using .pt file extension. .. note:: PyTorch preserves storage sharing across serialization. See :ref:`preserve-storage-sharing` for more details. .. note:: The 1.6 release of PyTorch switched ``torch.save`` to use a new zipfile-based file format. ``torch.load`` still retains the ability to load files in the old format. If for any reason you want ``torch.save`` to use the old format, pass the kwarg ``_use_new_zipfile_serialization=False``. Example: >>> # xdoctest: +SKIP("makes cwd dirty") >>> # Save to file >>> x = torch.tensor([0, 1, 2, 3, 4]) >>> torch.save(x, 'tensor.pt') >>> # Save to io.BytesIO buffer >>> buffer = io.BytesIO() >>> torch.save(x, buffer) z torch.saveN�wb) r�r��_log_api_usage_oncer;r=r#�_saver� _legacy_save)r�rdr9r>r?r@�opened_zipfile� opened_files r9r*r*Vsc��` �H� � ��.�.�.�� �&�&�&������%�K� !�!� $� $� �� �#�~�}�o�G`� a� a� a� � � � � � � � � � � � � ���� � � � � � ��Q�� %� %� K�� ��k�=�/� J� J� J� K� K� K� K� K� K� K� K� K� K� K� K���� K� K� K� K� K� Ks$�A1�1A5�8A5�B.�.B2�5B2c �:� � � ��ddlm� i� i� i�dtdttf� � � �fd� }t t tjdkt ttt������}|� t||���|� t ||���|� |||���|�||���}||_|� |��t!� �����}|� |||���|���|D]O}� |\} } | �|t)|��d t*j�| �����PdS) Nrr�rHc�b��t|t��r�t|�j��rn|�vrdSd�|<dx}} t |��\}}}d�|��}n/#t $r"tjd|j zdz��YnwxYwd|||fSt|tj j ��stj |���r�t|tj j ��rS|j}|j}|���}t#t|��}|j} |���} n�t|tj��rK|}tj}t+t|����}tj} |���} nt/dt|�������|���dkr[|����vr.|�|���krt3d���n|�|���<d} t5|j��} t9|��} | �vr|| f�| <|j|jk}|r*t5|j��| |���f}nd}d || | | |f}|SdS) NT��4Couldn't retrieve source code for container of type �3. It won't be checked for correctness upon loading.r�ztype not recognized: r�SCannot save multiple tensors or storages that view the same data as different typesr�)rKrs� issubclass�Modulerr8r~r�r�r4r�r�� TypedStorage� is_storage�_untyped_storage�dtype�_pickle_storage_typer��_sizer��uint8r(r�rL�data_ptrrTr�_cdatar&)r�� source_file�source� source_linesr�r�� storage_dtype�storage_type_strr�rS� storage_numel�offset� storage_keyr��is_view� view_metadata�res�nn�serialized_container_types�serialized_storages�storage_dtypess ����r9� persistent_idz#_legacy_save.<locals>.persistent_id�s��� �c�4� � � 8�Z��R�Y�%?�%?� 8��0�0�0��t�.2� &�s� +�#'� '�K�&� ?�/H��/M�/M�,� �a������.�.����� ?� ?� ?�� �&�(+� �5�8>�>�?�?�?�?�?� ?�����c�;��7� 7� �c�5�=�5� 6� 6�U �%�:J�3�:O�:O�U ��#�u�}�9�:�:� E��.�� #� � �#&�#;�#;�#=�#=� �&�u�.>�?�?� �� �� #� � � � � � ��C��!5�6�6� E��� %� � �5�d�3�i�i�@�@� �� �� '��� 0� 0� � �� C��S� � � C� C�D�D�D� ���!�!�Q�&�&��#�#�%�%��7�7�$��w�7G�7G�7I�7I�(J�J�J�*�D�E�E�E�K� :G�N�7�#3�#3�#5�#5�6� �F��g�n�-�-�K�#�G�,�,�H�>�"5�5�5�4;�U�3C�#�K�0��n���6�G�� %�!$�W�^�!4�!4�f�g�n�n�>N�>N� O� � � $� ����� � � "�C� �J��ts�(A%�%)B�B�little)�short�int�long)�protocol_version� little_endian� type_sizes��protocolT)�torch.nnrdr rr�dict�PROTOCOL_VERSION�sys� byteorder� SHORT_SIZE�INT_SIZE� LONG_SIZE�dump� MAGIC_NUMBER�Picklerrh�sorted�keysr� _write_filer,r�r�� _element_size)r�rdr9r>rh�sys_info�pickler�serialized_storage_keys�keyr�rSrdrerfrgs @@@@r9rErE�s�������������!#���� .0�N�j�3�j�8�E�?�j�j�j�j�j�j�j�j�j�X�)��m�x�/����� � � ����H����|�Q���A�A�A����'��_��E�E�E����x��_��=�=�=��#�#�A��#�@�@�G�)�G�� �L�L�����$�%8�%=�%=�%?�%?�@�@�����.��O��L�L�L��G�G�I�I�I�&�b�b��,�S�1�������A�4�Q�7�7��u�|�?Y�?Y�Z_�?`�?`�a�a�a�a�b�br8c��� ���i�i� i�� ��fd�}tj��}|�||���}||_|�|��|���}|�d|t|����|sbtj dvrtdtj z���|�dtj ttj ����t�� ����D]^} d| ��} �| } | j jdkr| ���} | ���} |�| | | ���_dS) Nc�H��t|tjj��stj|���rlt|tjj��rL|j}|j}|���}tt|��}|� ��}n>|}tj }tt|����}|� ��}|���dkr[|���� vr.|� |���krtd���n|� |���<��|jt%t'�������}t)|��}|� |<d||||fSdS)NrrMr�)rKr�r�rPrQrRrSrTr�rUrVr(rsr�rWrT� setdefaultrXrrbr&) r�r�r\r]r�r^r`r��id_maprfrgs ���r9rhz_save.<locals>.persistent_id-s���� �c�5�=�5� 6� 6�% #�%�:J�3�:O�:O�% #��#�u�}�9�:�:� 1��.�� #� � �#&�#;�#;�#=�#=� �&�u�.>�?�?� � #� � � � � � ��� %� � �5�d�3�i�i�@�@� � '��� 0� 0� � ���!�!�Q�&�&��#�#�%�%��7�7�$��w�7G�7G�7I�7I�(J�J�J�*�D�E�E�E�K� :G�N�7�#3�#3�#5�#5�6� �+�+�G�N�C��F� � �<L�<L�M�M�K�#�G�,�,�H�/6� � � ,�� ���!� #� #� �tr8rp�data.pkl)ri�big�Unknown endianness type: rv�data/r�)r�BytesIOr|rhrz�getvalue� write_recordrbrurvrUr}r~r�rsr�r�)r��zip_filer9r>r@rh�data_bufr�� data_valuer�r�r�� num_bytesr�rfrgs @@@r9rDrD#s���������F� .0�N�-�-�-�-�-�-�-�`�z�|�|�H��#�#�H��#�G�G�G�)�G�� �L�L������"�"�$�$�J� ���*�j�#�j�/�/�B�B�B� %�N� �=� 1� 1� 1��8�3�=�H�I�I� I����k�3�=�#�c�m�:L�:L�M�M�M��)�.�.�0�0�1�1� 8� 8���s�}�}��%�c�*�� �>� �%� '� '��k�k�m�m�G��N�N�$�$� ����d�G�Y�7�7�7�7� 8� 8r8)� weights_only�mmap� map_locationr�r��pickle_load_argsc � ���tj�d��d�d�dtdtf��fd� }|�d\}}nd }t jd d �����d vrd }|r|�td���n'|�%|rtj dtd���t}|�d }t|��d|� ��vrd|d<t|d��5}t|���r�|���} d} t#|��5} t%| ��rhtj dt&��|�| ��tj�||���cddd��cddd��S|r�t/|��st1d���tj�|��} t6st9��t:k} nd } tj�t j |��| | ��} |rl tC| |tDfd| i|��cddd��cddd��S#t$r0}tj#|t|������d�d}~wwxYwtC| ||fd| i|��cddd��cddd��S#1swxYwY|r/tI|t��sdn|�d�}td|�d����|r^ tK||tDfi|��cddd��S#t$r0}tj#|t|������d�d}~wwxYwtK|||fi|��cddd��S#1swxYwYdS)aSload(f, map_location=None, pickle_module=pickle, *, weights_only=False, mmap=None, **pickle_load_args) Loads an object saved with :func:`torch.save` from a file. :func:`torch.load` uses Python's unpickling facilities but treats storages, which underlie tensors, specially. They are first deserialized on the CPU and are then moved to the device they were saved from. If this fails (e.g. because the run time system doesn't have certain devices), an exception is raised. However, storages can be dynamically remapped to an alternative set of devices using the :attr:`map_location` argument. If :attr:`map_location` is a callable, it will be called once for each serialized storage with two arguments: storage and location. The storage argument will be the initial deserialization of the storage, residing on the CPU. Each serialized storage has a location tag associated with it which identifies the device it was saved from, and this tag is the second argument passed to :attr:`map_location`. The builtin location tags are ``'cpu'`` for CPU tensors and ``'cuda:device_id'`` (e.g. ``'cuda:2'``) for CUDA tensors. :attr:`map_location` should return either ``None`` or a storage. If :attr:`map_location` returns a storage, it will be used as the final deserialized object, already moved to the right device. Otherwise, :func:`torch.load` will fall back to the default behavior, as if :attr:`map_location` wasn't specified. If :attr:`map_location` is a :class:`torch.device` object or a string containing a device tag, it indicates the location where all tensors should be loaded. Otherwise, if :attr:`map_location` is a dict, it will be used to remap location tags appearing in the file (keys), to ones that specify where to put the storages (values). User extensions can register their own location tags and tagging and deserialization methods using :func:`torch.serialization.register_package`. Args: f: a file-like object (has to implement :meth:`read`, :meth:`readline`, :meth:`tell`, and :meth:`seek`), or a string or os.PathLike object containing a file name map_location: a function, :class:`torch.device`, string or a dict specifying how to remap storage locations pickle_module: module used for unpickling metadata and objects (has to match the :attr:`pickle_module` used to serialize file) weights_only: Indicates whether unpickler should be restricted to loading only tensors, primitive types, dictionaries and any types added via :func:`torch.serialization.add_safe_globals`. mmap: Indicates whether the file should be mmaped rather than loading all the storages into memory. Typically, tensor storages in the file will first be moved from disk to CPU memory, after which they are moved to the location that they were tagged with when saving, or specified by ``map_location``. This second step is a no-op if the final location is CPU. When the ``mmap`` flag is set, instead of copying the tensor storages from disk to CPU memory in the first step, ``f`` is mmaped. pickle_load_args: (Python 3 only) optional keyword arguments passed over to :func:`pickle_module.load` and :func:`pickle_module.Unpickler`, e.g., :attr:`errors=...`. .. warning:: :func:`torch.load()` unless `weights_only` parameter is set to `True`, uses ``pickle`` module implicitly, which is known to be insecure. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling. Never load data that could have come from an untrusted source in an unsafe mode, or that could have been tampered with. **Only load data you trust**. .. note:: When you call :func:`torch.load()` on a file which contains GPU tensors, those tensors will be loaded to GPU by default. You can call ``torch.load(.., map_location='cpu')`` and then :meth:`load_state_dict` to avoid GPU RAM surge when loading a model checkpoint. .. note:: By default, we decode byte strings as ``utf-8``. This is to avoid a common error case ``UnicodeDecodeError: 'ascii' codec can't decode byte 0x...`` when loading files saved by Python 2 in Python 3. If this default is incorrect, you may use an extra :attr:`encoding` keyword argument to specify how these objects should be loaded, e.g., :attr:`encoding='latin1'` decodes them to strings using ``latin1`` encoding, and :attr:`encoding='bytes'` keeps them as byte arrays which can be decoded later with ``byte_array.decode(...)``. Example: >>> # xdoctest: +SKIP("undefined filepaths") >>> torch.load('tensors.pt', weights_only=True) # Load all tensors onto the CPU >>> torch.load('tensors.pt', map_location=torch.device('cpu'), weights_only=True) # Load all tensors onto the CPU, using a function >>> torch.load('tensors.pt', map_location=lambda storage, loc: storage, weights_only=True) # Load all tensors onto GPU 1 >>> torch.load('tensors.pt', map_location=lambda storage, loc: storage.cuda(1), weights_only=True) # Map tensors from GPU 1 to GPU 0 >>> torch.load('tensors.pt', map_location={'cuda:1': 'cuda:0'}, weights_only=True) # Load tensor from io.BytesIO object # Loading from a buffer setting weights_only=False, warning this can be unsafe >>> with open('tensor.pt', 'rb') as f: ... buffer = io.BytesIO(f.read()) >>> torch.load(buffer, weights_only=False) # Load a module with 'ascii' encoding for unpickling # Loading from a module setting weights_only=False, warning this can be unsafe >>> torch.load('module.pt', encoding='ascii', weights_only=False) z torch.loadz�Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.z� Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.r�rHc�j��d}tj||��du}|r d��d�|z}n d��d�|z}|�zS)Nz2GLOBAL (\S+) was not an allowed global by default.z]Weights only load failed. This file can still be loaded, to do so you have two options (1) z� (2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message. WeightsUnpickler error: zWeights only load failed. z� Please file an issue with the following so that we can make `weights_only=True` compatible with your use case: WeightsUnpickler error: )�re�search)r��pattern�has_unsafe_global�updated_message� DOCS_MESSAGE�UNSAFE_MESSAGEs ��r9�_get_wo_messagezload.<locals>._get_wo_message�s����G���I�g�w�7�7�t�C�� � �d�)�d�d�d��� �O��^����#�$� � ��-�-r8N)FTF�TORCH_FORCE_WEIGHTS_ONLY_LOAD�0)�1�y�yes�trueTzDCan not safely load weights when explicit pickle_module is specifiedaWYou are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.r)� stacklevel�encodingzutf-8�rbz�'torch.load' received a zip file that looks like a TorchScript archive dispatching to 'torch.jit.load' (call 'torch.jit.load' directly to silence this warning))r�z7f must be a file path in order to use the mmap argument�overall_storagerJz, z8mmap can only be used with files saved with `torch.save(zn_use_new_zipfile_serialization=True), please torch.save your checkpoint with this option in order to use mmap.)&r�r�rCrr��getenv�lowerrTr�r�� FutureWarning�pickler;r~rrhr`r�_is_torchscript_zip� UserWarningrc�jitr+r�rUr@�getsizerSrPrr�� from_file�fspath�_loadrX�UnpicklingErrorrK� _legacy_load)rdr�r9r�r�r�r��warn_weights_onlyrG� orig_positionr�rF�size�sharedr��f_namer�r�s @@r9r+r+ys�����V �H� � ��.�.�.� ��  R�� .��.��.�.�.�.�.�.�.�$��*5�'� �'�'�!�� �y�0�#�6�6�<�<�>�>�B[�[�[�� ��#� � $��e�f�f� f� %� � � � �� � j�"� � � � � �#�M� �|���� �&�&�&��)�.�.�0�0�0�0�'.���$� ��D� !� !�3 �[� �{� #� #�% �(�,�,�.�.�M�"�O�%�k�2�2� �n�&�~�6�6�R��M�#;�<G�I�I�I� �$�$�]�3�3�3� �9�>�>�+�L�>�Q�Q�  � � � � � � �3 �3 �3 �3 �3 �3 �3 �3 ��a�#�A�;�;�d�(�)b�c�c�c��7�?�?�1�-�-�D�%�'�!9�!;�!;�z�!I���!&��&+�&:�&D�&D�R�Y�q�\�\�SY�[_�&`�&`�O��X�X�$�^�%1�%<� 9� 9�6E� 9�(8�  9� 9�% � � � � � � �3 �3 �3 �3 �3 �3 �3 �3 ��<(�X�X�X�$�4�_�_�S��V�V�5L�5L�M�M�SW�W�����X�����"� �!���%4� � '� ��3 � � � � � � �3 �3 �3 �3 �3 �3 �3 �3 � � � � ���� � � � �@ � k�)�!�S�1�1�?�R�R�!�x�x�x�F�� j�.4� j� j� j�k�k� k� � P� P�#�K��?V�k�k�Zj�k�k�]3 �3 �3 �3 �3 �3 �3 �3 ��^ � P� P� P��,�_�_�S��V�V�-D�-D�E�E�4�O����� P����� ��}� � �8H� � �c3 �3 �3 �3 �3 �3 �3 �3 �3 �3 �3 �3 ����3 �3 �3 �3 �3 �3 s��)6M8�AK�> M8�BK�-I� M8� J�%+J�J�K�( M8�K �M8�K � 6M8�L � M�*+M�M�M8�8M<�?M<c���tj}|sMtj���D].}t |tj��r||t|��<�/||S)z@Get layout extension object from its string representation. )� _get_layout�cacher��__dict__�valuesrK�layoutr)r�r��vs r9r�r�as_�� � �E� �"���&�&�(�(� "� "�A��!�U�\�*�*� "� !��c�!�f�f� �� ��;�r8c�0�tt|��ffSr;)r�rr�s r9�<lambda>r�ms��+��C���{�)C�r8c ���������i�t|���Gd�d�j���d�������fd�}i����fd�}t|��t|��}|ru|���dkr] ||��S#t j$r?t|��rt|j �d���d�|� d��YnwxYwt|d��s:d tj cxkrd kr#nn td t|���d �����j|fi���}|t krtd ����j|fi���}|t"krtd|������j|fi���} �|fi���} || _| ���} �j|fi���} t&j�����|r|���nd} | D]e}|�vsJ��|}|j�|| |t&j�|j����| �|���} �ft&j���| S)Nc���eZdZ�fd�Z�xZS)�&_legacy_load.<locals>.UnpicklerWrapperc���t|��tur$d|vr t|��S#t$rYnwxYwt ���||��S�Nr )rsrr,�KeyErrorr�� find_class)r��mod_namer�r�s �r9r�z1_legacy_load.<locals>.UnpicklerWrapper.find_classwsk����D�z�z�S� � �Y�$�%6�%6��&�t�,�,�,�������D������7�7�%�%�h��5�5� 5� �,� 9�9�r4r5r6r�r�r�s@r9�UnpicklerWrapperr�us8������� 6� 6� 6� 6� 6� 6� 6� 6� 6r8r�c�� d�t|��d��}n0#t$r#tjd|jzdz��YdSwxYw||k�rg|j�r'|jdz}tj|� d��|� d��||d���}d�|��} t|d��5}|� dd ��}|� d��|dkr|� |��n2|t|��ks|���|krt�ddd��n #1swxYwYd |zd z|zd z} n#t$r d |zdz} YnwxYwd} dt!j|���d| ��} tj| t$��dSdS)NrJrrKrLz.patch� )�linetermza+rzSaved a reverse patch to z. Run `patch -p0 < z` to revert your changes.z;Tried to save a patch, but couldn't create a writable file zD. Make sure it doesn't exist and your working directory is writable.z�you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.zsource code of class 'z' has changed. )r8rr~r�r�r4� dump_patches�difflib� unified_diffr{r�rcrrbra�OSErrorr�r�r ) �container_typerY�original_source�current_source� file_name�diff�linesrd� file_sizers r9�_check_container_sourcez-_legacy_load.<locals>._check_container_sourcesl�� ��W�W�%>�~�%N�%N�q�%Q�R�R�N�N��� � � � �M�"�$2�$;�<�?:�:� ;� ;� ;� �F�F�  ���� �n� ,� ,��*� <�*�3�h�>� ��+�N�,@�,@��,F�,F�,;�,A�,A�$�,G�,G�,7�,7�"�F�F�F��� � �$����(��i��.�.�*�!�$%�F�F�1�a�L�L� ����q� � � �$��>�>��G�G�E�N�N�N�N�&�#�e�*�*�4�4������E�8I�8I�")�M� *�*�*�*�*�*�*�*�*�*�*����*�*�*�*�7��B�F/�/�1:�;�>&�&�C�C���(�(�(�,�.7�8�;'�'�C�C�C�(���� ;��`�5�>�.�+I�+I�_�_�Z]�_�_�C� �M�#�2� 3� 3� 3� 3� 3�= -� ,sF�(+�)A�A� E9�A:E� E9�E#�#E9�&E#�'E9�9F� Fc ��� �i� �"� fd�}ttj|dtj�����5}t ��5}|�d|���tt j�|d��dd��5}�$j |fi�#��}t|��D]�}�$j |fi�#��}|\}}} | j } tttj���|tj�| ����} �%| |��} tj�| | d� ��� |<���$j |fi�#��} | D]u\} }}}� |}tj�|j��}||z}tj�|j||||zz�|jd� ��� | <�v ddd��n #1swxYwY|�d |���tt j�|d ��dd��5}�$j |fi�#��}t|��D�]!}�$j |fi�#��}|\}}}� |}t/jd |�d ����\}|�d ��t/jd |�d�|�d|z����}t/jd |�d�|�d|z����}t/jd|�d����\}tjd|j����|j|||��}|� |<��# ddd��n #1swxYwY|�d��}�!|fi�#��}||_|� ��}|cddd��cddd��S#1swxYwYddd��dS#1swxYwYdS)Nc���t|t��r$t|dd���r�|�|dS�t|��S)Nrr)rKr|�allrk)�saved_idr��deserialized_objectss ��r9�persistent_loadz:_legacy_load.<locals>.legacy_load.<locals>.persistent_load�sV����(�E�*�*� #��x����|�$�$�7�+�+�X�6�6���{�"�'��H� � �6� 6r8zr:)�fileobjr�r7�storagesr?r�rT�� wrap_storagerS� _internal�tensorsz<i��<�q�z<q)r�rSr�)r�tarfiler�� PAX_FORMATr!�extractr�r@r8r+�range�_dtyperr r�r��_new_with_filer�r�r�rPrSrR�struct�unpackra�empty�set_� extractfiler�)&rdr��tar�tmpdir� num_storages�ir�r�r�r�rSr�� storage_views� target_cdata� root_cdatar_�numel�root� element_size� offset_bytes� num_tensorsr�� storage_id�original_tensor_typer��ndim�stride�storage_offset�tensor� pickle_file� unpicklerr�r�r�r�r�r9�restore_locations& @�����r9� legacy_loadz!_legacy_load.<locals>.legacy_load�s`����/1�� 7� 7� 7� 7� 7� 7��W�\�!�$�w�?Q�R�R�R� S� S�4 �WZ�� � �4 �#� �K�K� ��K� 0� 0� 0��b�g�l�l�6�:�6�6��a�@�@� (�A�1�}�1�!�H�H�7G�H�H� ��|�,�,� (� (�A�-�=�-�a�D�D�3C�D�D�D�26�/�C��<�(�/�E��w��(<�=�=�L�L�Q�PU�P\�Pj�Pj�kp�Pq�Pq�r�r�C�*�*�3��9�9�C�16� �0J�0J�%(�#�"&�1K�1(�1(�(��-�-� !3� � 2�1� I� I�8H� I� I� �?L� (� (�;�L�*�f�e�/� �;�D�#(�<�#=�#=�d�j�#I�#I�L�#)�L�#8�L�:?��9S�9S�%)�%:�<� �W\�_k�Wk�Hk�;k�%l�"�j�"&�:T�:(�:(�(��6�6� (�! (� (� (� (� (� (� (� (� (� (� (���� (� (� (� (�6 �K�K� ��K� /� /� /��b�g�l�l�6�9�5�5�t�Q�?�?� 7�1�0�m�0��G�G�6F�G�G� ��{�+�+� 7� 7�A�-�=�-�a�D�D�3C�D�D�D�<@�9�C��%9�2�:�>�G�"�M�$����q� � �:�:�E�D��F�F�1�I�I�I�"�M�+�d�+�+�+�q�v�v�a�$�h�7G�7G�H�H�E�#�]�;�t�;�;�;����q�4�x�8H�8H�I�I�F�&,�m�D�!�&�&��)�)�&D�&D�O�N�"�[��W�]�C�C�C�H�H��0�.�%��Q�Q�F�06�(��-�-� 7� 7� 7� 7� 7� 7� 7� 7� 7� 7� 7� 7���� 7� 7� 7� 7� �/�/�(�3�3�K�(�(��I�I�8H�I�I�I�(7�I� %��^�^�%�%�F��i4 �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 �4 ����4 �4 �4 �4 �4 �4 s��O4�AO�EG� O�G# �#O�&G# �'A O�0EM>�2 O�>N �O�N �=O� O4�O � O4�#O �$O4�4O8�;O8c���t|t��sJ�t|d��}|dd�}|dkr$t|dd���r�|�|dS|dk�r�|\}}}}}t|��}|j}|t j�|��z} |�vr�t j� ���*ttt j | d�����} n:ttt j | ����} d| _ �| |��} t j�| |d���} | �|<nL�|} | ���dkr,t j�| jj|d� ��} |��|\} } }| t j�|��z}|t j�|��z}| �vr5t j�| j|||z�|d����| <�| }n| }|St'd |d�����) Nrrr�r�r�r�Tr�)r�rSr�zUnknown saved id type: )rKr|�_maybe_decode_asciir�rSr�r�r��_guards�active_fake_moderr r��_torch_load_uninitializedr�rP� _data_ptrrRr�rT)r�r��datar��root_keyr�rrbrSr�r�� typed_storage�view_keyr_� view_sizer�view_size_bytesrcr�r�rs ���r9r�z%_legacy_load.<locals>.persistent_load�s|����(�E�*�*�*�*�*�&�x��{�3�3������|�� �x� � ��4����8�}�}� /�'�'��.�.���7�N� �� "� "�EI� B�L�(�H�e�]�*�8�4�4�H� �&�E��U�\�7�7��>�>�>�F��3�3�3��=�1�1�3�3�?��w��(<�V�F�(S�(S�(S�T�T�C�C��w��(<�V�(D�(D�E�E�C�48�C�1�*�*�3��9�9�C�!&� � :� :�!$��"�!;�!$�!$� �2?�$�X�.�.� 4�X� >� � �*�*�,�,��1�1�$)�M�$>�$>�,�=�D�#�"&�%?�%(�%(�M� �(�.;�+��&�)�%�� �(B�(B�5�(I�(I�I� �"+�e�l�.H�.H��.O�.O�"O���#7�7�7�6;�]�5O�5O�%2�%C�L�Q]�`o�Qo�Do�%p�#�"&�6P�6(�6(�(��2�+�8�4���$���J��F��!��F�F�G�G� Gr8rz9 is a zip archive (did you mean to use torch.jit.load()?)�readinto)rCr�r)rCr�rz�torch.load does not work with file-like objects that do not implement readinto on Python 3.8.0 and 3.8.1. Received object of type "zH". Please update to Python 3.8.2 or newer to restore this functionality.z#Invalid magic number; corrupt file?zInvalid protocol version: )�_get_restore_location� Unpicklerr�r,r`r��TarErrorrhrTr�rcr�ru� version_inforsr+r{rtr�r�rrrR�_set_from_filer�r�rS�_validate_loaded_sparse_tensors)rdr�r9r�rr��f_should_read_directly� magic_numberrm� _sys_inforr��deserialized_storage_keysr_r�rr�r�r�rs `` @@@@r9r�r�psp��������+-��,�\�:�:��6�6�6�6�6�=�2�6�6�6�&4�&4�&4�P?�?�?�?�?�?�?�?�?�B��8H�8H�8H�8H�8H�8H�8H�t�A����2�1�5�5��� �!�&�&�(�(�a�-�-� ��;�q�>�>� !���� � � ��1�~�~� d�"��v�X�X�X�Z�Z�_c�d� �F�F�1�I�I�I�I�I�  ���� �1�j� !� !��i�3�3C�&O�&O�&O�&O�i�&O�&O�&O�&O�&O�� �(,�Q��� � � ��� � &�=�%�a�<�<�+;�<�<�L��|�#�#��@�A�A�A�)�}�)�!�@�@�/?�@�@���+�+�+��J�8H�J�J�K�K�K�"� �"�1�9�9�(8�9�9�I� � ��7�7�&6�7�7�I� /�I�� �^�^� � �F� 2� � 2�1� I� I�8H� I� I�� �}�%�%�'�'�/�3�=���������,� "� "�C��.�.�.�.�.�0��5�M� � *� 9� 9��6�1�� �*�*�=�+>�?�?� A� A� A��!�������� �L�0�0�2�2�2� �Ms�9 B�A C�C� bytes_strc�Z�t|t��r|�d��S|S)Nr)rK�bytes�decode)r*s r9rrXs0���)�U�#�#�)�����(�(�(� �r8c������t}nbt�t��r�fd�}nGt�ttf��r�fd�}n%t�t j��r�fd�}n�fd�}|S)Nc�P����||��}t||��Sr;)�getr'�r�r�r�s �r9rz/_get_restore_location.<locals>.restore_locationhs(���#�'�'��(�;�;�H�+�G�X�>�>� >r8c�$��t|���Sr;�r'r1s �r9rz/_get_restore_location.<locals>.restore_locationls���+�G�\�B�B� Br8c�>��t|t�����Sr;)r'rr1s �r9rz/_get_restore_location.<locals>.restore_locationos���+�G�S��5F�5F�G�G� Gr8c�D���||��}|�t||��}|Sr;r3)r�r�r�r�s �r9rz/_get_restore_location.<locals>.restore_locationrs-���!�\�'�8�4�4�F��~�1�'�8�D�D���Mr8)r'rKrsrr,r�r�)r�rs` r9r r ds������3��� �L�$� '� '�� ?� ?� ?� ?� ?� ?� �L�3��,� /� /� � C� C� C� C� C� C� �L�%�,� /� /�� H� H� H� H� H� H� � � � � � �r8c�0�eZdZd�Zed���Zd�ZdS)r,c�.�t|��|_dSr;)r r�)r�r�s r9r�zStorageType.__init__{s��9�$�?�?�� � � r8c��|jSr;)r�r�s r9rSzStorageType.dtype~s ���{�r8c��d|j�d�S)NzStorageType(dtype=r�r�r�s r9�__str__zStorageType.__str__�s��1�D�J�1�1�1�1r8N)r4r5r6r��propertyrSr:r7r8r9r,r,zsP������@�@�@�����X��2�2�2�2�2r8r,r�c �F��� � ����t|���i�d}d� ��|��r>��|��� � dvr$td� ���z���nxt ��t jkst ���d� nKt ��t jkrd� n,t ��t j krntd�����|��s8t ���*tj dkrtj dt��� ����fd ����fd �}d d i� G� fd �d|j��}t!j��|����} || fi|��} || _|t&jj_| ���} t&jj`t&j���t&j�dd����i��| S)Nrv)�little�bigr�r=r>zInvalid load endianness typer�aThe default load endianness for checkpoints without a byteorder mark on big endian machines was changed from 'native' to 'little' endian, to avoid this behavior please use torch.serialization.set_default_load_endianness to set the desired default load endiannessc���d|��}tj�d���9|tj�|��z}tj|d���}n]� �#� �|��}� |||z�}n8� �||tj�����j }� �7� � ��tj kr|� |��tj�� ||��|d���}|���dkr|� |<|S)Nr�r�r�Tr�r)r�r�detect_fake_moder�r�r��get_record_offset�get_storage_from_record�_typed_storagerRr-rurv�byteswapr�rPr)rSrr�r�r�r�r�r r� byteorderdata�loaded_storagesr�rr�s �����r9� load_tensorz_load.<locals>.load_tensor�s=����s�}�}�� �=� )� )�$� /� /� ;��U�\�7�7��>�>�>�F��*�6�&�A�A�A�G�G� � (�%�7�7��=�=�N�%�n�^�e�5K�&K�L�G�G��6�6�t�U�E�DX�Y�Y�h�h�j�j�{�G� � $��#�#�%�%���6�6�� � ��'�'�'�� �2�2�)�)�'�8�<�<���3��� � � "� "� $� $�� )� )�#0�O�C� ��r8c���t|t��sJ�t|d��}|dd�}|dksJd|�d����|\}}}}|tjur tj}n|j}|� vr � |}n=|tj�|��z} � || |t|����}|S)Nrrr�zBUnknown typename for persistent_load, expected 'storage' but got 'ry) rKr|rr�r�rVrSr�r�) r�r�rr�r�r�rrSrr�rGrFs ��r9r�z_load.<locals>.persistent_load�s�����(�E�*�*�*�*�*�&�x��{�3�3������|���9�$�$�$� \�QY� \� \� \�%�$�$�-1�*� �c�8�U� �5�/� /� /��K�E�E� �&�E� �/� !� !�+�C�0�M�M��U�\�7�7��>�>�>�F�'�K��v�s�<O�PX�<Y�<Y�Z�Z�M��r8z torch.tensorz torch._tensorc�"���eZdZ��fd�Z�xZS)�_load.<locals>.UnpicklerWrapperc����t|��tur$d|vr t|��S#t$rYnwxYw��||��}t ���||��Sr�)rsrr,r�r0r�r�)r�r�r�r��load_module_mappings ��r9r�z*_load.<locals>.UnpicklerWrapper.find_class�s�����D�z�z�S� � �Y�$�%6�%6��&�t�,�,�,�������D�����*�.�.�x��B�B�H��7�7�%�%�h��5�5� 5r�r�)r�rLs@�r9r�rJ�s>�������� 6� 6� 6� 6� 6� 6� 6� 6� 6� 6r8r�ztorch.load.metadata�serialization_id)r � has_record� get_recordrUr-r.r-rErFrDrurvr�r�r�r!rr�r�r�r��_thread_local_stater�r+r%r��_log_api_usage_metadatarM)r�r�r9rr�r�� byteordernamer�r�� data_filerr�rErLrGrFrs` ` @@@@@r9r�r��s����������,�\�:�:���O� �M��M����=�)�)� 9� �+�+�M�:�:� � � 3� 3� 3��8�=�;O�;O�;Q�;Q�Q�R�R� R� 4� $� &� &�.�*?� ?� ?� '� )� )� 1�!� � � $� &� &�.�*<� <� <�� � � $� &� &�.�*?� ?� ?� ��7�8�8�8� � � �}� -� -� #� '� )� )� 1� �M�U� "� "� � �<� "�  #� #� #����������6������. ��+�� 6� 6� 6� 6� 6� 6� 6�=�2� 6� 6� 6�� �8�.�.�{�;�;�<�<�I� � ��?�?�.>�?�?�I� /�I��5A�E�L�$�1� �^�^� � �F� � �(�5� �L�0�0�2�2�2� �H�$�$�� 2�H�4M�4M�4O�4O�P���� �Mr8c�.�d|���vS)Nz constants.pkl)�get_all_records)r�s r9r�r��s�� �h�6�6�8�8� 8�8r8r )T)r�N)�r�� functoolsr�rr�r=r�rur�r�r<r�� contextlibrr�enumrr�r�torch._sourcesr� torch.typesr � torch.storager �typingr r r rrrrrrrr�typing_extensionsrr�copyregr��torch._weights_only_unpicklerrX�DEFAULT_PROTOCOL�Structr�ryrxrwr{rt�STORAGE_KEY_SEPARATORrr�r,r�__annotations__r�rr�rPr�r�platformrSr�rr�__all__�Warningr r!rArkr-rGr.r/rNrPrVr0r1r2�boolrhr"r#r�r�r�r�r�r�r�r�r$r%r��partialr&r'r(r)r�r�r�r�rrrr rr#r'r,r�r;r=�objectr*rErDr+r�r�r�r�rr r,r�r�r7r8r9�<module>rjs� ����������� � � � � � � � � � � � � � � � � � � � � � � � � � � � �������������.�.�.�.�.�.�.�.�������'�'�'�'�'�'�4�4�4�4�4�4�������=�=�=�=�=�=�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�^�2�2�2�2�2�2�2�2����� � � � �?�?�?�?�?�?��� �F�M�$� � � $� � �6�=�� � � #�� �V�]�4� � � %� �%� ������S�"�+�x��E��B�C� �9�C�C�C�"�5��7�C�.�'�2I�)J�E�L�Z]�_c�dg�il�dl�_m�)m�#n�o� �i�o�o�o��7�E�M�$>��@T�T�U���U�U�U� �\�W� $� ��)�,�,�,�,�,�,�,�,�,�(��J� � � � ��. � � � � �'� � � �������xz��4��c�8�W�I�x��}�,D�#E�x�QX�Z]�P^�`h�ip�`q�Pq�Gr�r�s�t�y�y�y� � � � � �T� � � � 26��h�~�.�5�5�5�  �X�n�%=�  �  �  �  �&�&�&� )��s�(�(�(� !�#� !� !� !� !�"�C�"�"�"�"�*2�2�2�2� 7�$�s�)�7�7�7�7� <�4��9�<��<�<�<�<�6 3�d� 3� 3� 3� 3� *��*� �g�Y��� �-� .�*��G�S�>�8�G�+<�<�=�*�*�*�*�Z$�$�$�$�N��� ��� ��� >�>�>���� ��� A�A�A� )�)�)�X4�4�4�3�3�3�%�%�%����X�/�0�0�0����&�Y�&�|�V�<�<�>O�i�>O�P\�^d�>e�>e�f�f�f����X�/�0�0�0����Y� 1�2�2�2����&�Y�&�|�]�C�C�EV�Y�EV�Wc�er�Es�Es�t�t�t����&�Y�&�|�U�;�;�=N�Y�=N�|�]b�=c�=c�d�d�d����&�Y�&�|�U�;�;�=N�Y�=N�|�]b�=c�=c�d�d�d�2�%����)C�U�EY� Y�Z�2�2�2�2�)�)�)�1�1�1�O�O�O� :� �%��R�[�0@�*A� B�:�:�:�:� � � � � � � � ���������� � � � � �'� � � � �����'���� N� N� N�E�E�E�E�E�7�E�E�E� %�%�%�%�%��%�%�%�* � � � � �'� � � �%�%�%��d����� � � � �$�����&����(#�#�#� �+�+/�&+� :K�:K� �:K��:K��:K�� :K� %)� :K� $� :K� �:K�:K�:K�:K�zMb�Mb�Mb�Mb�`S8�S8�S8�p"&��c � $(�� c �c �c ��c ��c ��c � �4�.� c � �4�.� c ��c � �c �c �c �c �P���� �����u�|�C�C�D�D�D�e�e�e�P �5����#4� �� � � � ����, 2� 2� 2� 2� 2� 2� 2� 2�v�v�v�v�r9�9�9�9�9r8
Memory