� J��g����UddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlmZmZmZddlmZddlmZmZddlmZmZddlmZddlmZGd �d ��Z dd l m Z n #e!$reZ YnwxYwgd �Z"ej#d ��Z$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,da-ee.e/d<ej0d���Z1d�Z2d�Z3d�Z4d�Z5d�Z6d�Z7d�Z8d�Z9dAd"�Z:dBd$�Z;d%�Z<d&�Z=d'�Z>d(�Z?d)�Z@dCd*�ZAdDd+�ZBd,dd!d d!d-�d.�ZCd/�ZD dEd0e.d1e.d2ee.d3eEd4df d5�ZFd6e.d4eEfd7�ZGed8eH�9��d6e.d:e.d;ed<eEd4ee.eff d=���ZI dFd0e.d:ee.d;ed3eEd>eEd?ee.d<eEd4ee.effd@�ZJdS)G�N)�Path)�Dict�Optional�Any)� deprecated)� HTTPError�URLError)�urlopen�Request)�urlparse)� MAP_LOCATIONc�>�eZdZ d d�Zd�Zd�Zd�Zd�Zd�Zd �Z dS) � _FaketqdmNFc�0�||_||_d|_dS�Nr)�total�disable�n)�selfrr�unit�args�kwargss �Y/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/torch/hub.py�__init__z_Faketqdm.__init__s���� ��� ������c�X�|jrdS|xj|z c_|j�*tj�d|jd�d���nAtj�dd|jzt |j��z d�d���tj���dS)N� z.1fz bytes�d�%)rrr�sys�stderr�write�float�flush)rrs r�updatez_Faketqdm.update s��� �<� � �F� ���!� ��� �:� � �J� � �4�$�&�4�4�4�4� 5� 5� 5� 5� �J� � �I�#���,��t�z�1B�1B�"B�I�I�I�I� J� J� J� � �������rc��dS�N�)rrrs r�set_descriptionz_Faketqdm.set_description,s�� �rc�J�tj�|�d���dS�N� )r r!r")r�ss rr"z_Faketqdm.write/s$�� � ���A����"�"�"�"�"rc��d|_dS�NT)r�rs r�closez_Faketqdm.close2s ���� � � rc��|Sr'r(r0s r� __enter__z_Faketqdm.__enter__5s��� rc�V�|jrdStj�d��dSr+)rr r!r")r�exc_type�exc_val�exc_tbs r�__exit__z_Faketqdm.__exit__8s-�� �<� � �F� � ��������r)NFN) �__name__� __module__� __qualname__rr%r)r"r1r3r8r(rrrrs�������+0������ � � � � � �#�#�#�����������rr)�tqdm)�download_url_to_file�get_dir�help�list�load�load_state_dict_from_url�set_dirz-([a-f0-9]*)\.)�facebookresearch�facebookincubator�pytorch� fairinternal� GITHUB_TOKEN� TORCH_HOME�XDG_CACHE_HOMEz~/.cache� dependenciesz hubconf.pyi�_hub_dirc#��K�tj�d|�� dV�tj�|��dS#tj�|��wxYwr)r �path�insert�remove�rNs r�_add_to_sys_pathrR[s^�����H�O�O�A�t����� ���� ����������������������s �A � !A*c���ddl}ddlm}|j�||��}|�J�|j�|��}t |j|��sJ�|j�|��|S)Nr)�Loader) �importlib.util� importlib.abcrT�util�spec_from_file_location�module_from_spec� isinstance�loader� exec_module)�namerN� importlibrT�spec�modules r�_import_moduleraes�������$�$�$�$�$�$� �>� 1� 1�$�� =� =�D� � � � � �^� ,� ,�T� 2� 2�F� �d�k�6� *� *�*�*� *��K���F�#�#�#� �Mrc���tj�|��rKtj�|��rtj|��dSt j|��dSdSr')�osrN�exists�isfilerP�shutil�rmtreerQs r�_remove_if_existsrhps_�� �w�~�~�d��� � �7�>�>�$� � � � �I�d�O�O�O�O�O� �M�$� � � � � �  � rc��d|�d|�d|��S)N�https://github.com/�/z /zipball/r()� repo_owner� repo_name�refs r�_git_archive_linkroxs �� G�� G� G�i� G� G�#� G� G�Grc�H�|t|��vrdSt||��Sr')�dir�getattr)r`� func_names r�_load_attr_from_modulert}s(����F� � �#�#��t� �6�9� %� %�%rc ���tj�tjttj�tjt t��d������}|S)N�torch)rcrN� expanduser�getenv�ENV_TORCH_HOME�join�ENV_XDG_CACHE_HOME�DEFAULT_CACHE_DIR)� torch_homes r�_get_torch_homer~�sb����#�#� � �.��'�,�,�r�y�);�):� <� <�=D�F�F� G� G�H�H�J� �rc ��d|vr|�d��\}}n|d}}|�d��\}}|�� td|�d|�d���5d}ddd��n #1swxYwYn�#t$r}|jdkrd}n�Yd}~n{d}~wt$rk}dD]<}t j�t���d|�d |�d |����r|}n�=|� td t���d ���|�Yd}~nd}~wwxYw|||fS) N�:rkrjz /tree/main/�maini��master)r�r��_z\It looks like there is no internet connection and the repo could not be found in the cache (�)) �splitr r�coder rcrNrdr>� RuntimeError)�github� repo_infornrlrm�e� possible_refs r�_parse_repo_infor��s��� �f�}�}����c�*�*�� �3�3���3� �%�O�O�C�0�0��J� � �{� ��R�z�R�R�I�R�R�R�S�S� � ��� � � � � � � � � � � ���� � � � ���� � � ��v��}�}��������������� � � � 2� � � ��7�>�>�W�Y�Y�"X�"X��"X�"X�i�"X�"X�,�"X�"X�Y�Y��&�C��E���{�"�J�=D�Y�Y�J�J�J������{�{�{�{����� ���� �y�#� %�%sH�A.�A"� A.�"A&�&A.�)A&�*A.�. D�8B � D�A!C?�?Dc���t|��5}|����|j�d����cddd��S#1swxYwYdS)Nzutf-8)r �read�decode�headers�get_content_charset)�url�rs r� _read_urlr��s��� ����G���v�v�x�x���q�y�<�<�W�E�E�F�F�G�G�G�G�G�G�G�G�G�G�G�G����G�G�G�G�G�Gs�?A�A �#A c ��ddi}tj�t��}|�d|��|d<d|�d|�d�d|�d|�d�fD]{}d } |d z }|�d |��}t jt t||� ������}|sn7|D]3} | d|ks!| dd�|��rdS�4�v�|td|�d|�d|�d����)N�Acceptzapplication/vnd.github.v3+jsonztoken � Authorizationzhttps://api.github.com/repos/rkz /branchesz/tagsrT�z?per_page=100&page=�r�r]�commit�shaz Cannot find z in https://github.com/zX. If it's a commit from a forked repo, please call hub.load() with forked repo directly.) rc�environ�get�ENV_GITHUB_TOKEN�json�loadsr�r � startswith� ValueError) rlrmrnr��token� url_prefix�pager��response�brs r�_validate_not_a_forked_repor��sm���9�:�G� �J�N�N�+� ,� ,�E� ��#3�E�#3�#3��� � M�J� M� M�� M� M� M� I�J� I� I�� I� I� I�K� � � ��� � �A�I�D��:�:�D�:�:�C��z�)�G�C��,I�,I�,I�"J�"J�K�K�H�� ��� � ���f�:��$�$��8� �U�(;�(F�(F�s�(K�(K�$��F�F�F�%� � � �o�C�o�o� �o�o�Y�o�o�o� p� p�prTFc�<�t��}tj|d���t|��\}}} | �dd��} d�||| g��} tj�|| ��} t||| ||���| otj�| ��} | r'|r#tj � d| �d����n�|st||| ��tj�|| dz��}t|�� t||| ��}tj � d |�d |�d���t||d � ��ne#t $rX}|jd krBt%jd| �d���d| ��}t|||���}t||d � ��n�Yd}~nd}~wwxYwt)j|��5}|���dj}tj�||��}t|��|�|��ddd��n #1swxYwYt|��t| ��t3j|| ��| S)NT��exist_okrkr�)� trust_repo� calling_fnzUsing cache found in r,z.zip�Downloading: "�" to F��progressi,zThe ref a is ambiguous. Perhaps it is both a tag and a branch in the repo? Torchhub will now assume that it's a branch. You can disambiguate tags and branches by explicitly passing refs/heads/branch_name or refs/tags/tag_name as the ref. That might require using skip_validation=True.z refs/heads/)rnr)r>rc�makedirsr��replacerzrN�_check_repo_is_trustedrdr r!r"r�rhror=rr��warnings�warn�zipfile�ZipFile�infolist�filename� extractallrf�move)r�� force_reloadr�r��verbose�skip_validation�hub_dirrlrmrn� normalized_br�owner_name_branch�repo_dir� use_cache� cached_filer��err�disambiguated_branch_ref�cached_zipfile�extraced_repo_name�extracted_repos r�_get_cache_or_reloadr��s���i�i�G��K��$�'�'�'�'�!1�&�!9�!9��J� �3� �K�K��S�)�)�M� ���*�i��!G�H�H���w�|�|�G�%6�7�7�H��:�y�2C�PZ�gq�r�r�r�r�!�!�?�r�w�~�~�h�'?�'?�I��*.� � C� �J� � �A�X�A�A�A� B� B� B��� D� '� �I�s� C� C� C��g�l�l�7�M�F�,B�C�C� ��+�&�&�&� �#�J� �3�?�?�C� �J� � �G�c�G�G� �G�G�G� H� H� H� ��k�E� B� B� B� B� B��� � � ��x�3��� � �d�s�d�d�d���� ,?��+>�+>�(�'� �I�C[�\�\�\��$�S�+��F�F�F�F�F��G�F�F�F�F����� ����$�_�[� )� )� /�^�!/�!8�!8�!:�!:�1�!=�!F� ��W�\�\�'�3E�F�F�N� �n� -� -� -� � %� %�g� .� .� .�  /� /� /� /� /� /� /� /� /� /� /���� /� /� /� /� �+�&�&�&��(�#�#�#�� �N�H�-�-�-� �Os-�+A E5�5 G�?AG�G�.A$I�I"�%I"rAc���t��}tj�|d��}tj�|��s!t |�����t|��5}td�|D����}ddd��n #1swxYwYttj |����d} d�||g��} | |vp || vp|tv} |�| stj d|�d|�d���dS|dus|d kru| sstd | �d ���} | ���d vr| rt!d ��n8| ���dvrt#d���t%d| �d����| sCt|d��5}|�| dz��ddd��dS#1swxYwYdSdS)N� trusted_listc3�>K�|]}|���V��dSr')�strip)�.0�lines r� <genexpr>z)_check_repo_is_trusted.<locals>.<genexpr>s*����<�<�t�d�j�j�l�l�<�<�<�<�<�<rr�r�a)You are about to download and run code from an untrusted repository. In a future release, this won't be allowed. To add the repository to your trusted list, change the command to {calling_fn}(..., trust_repo=False) and a command prompt will appear asking for an explicit confirmation of trust, or zi(..., trust_repo=True), which will assume that the prompt is to be answered with 'yes'. You can also use z�(..., trust_repo='check') which will only prompt for confirmation if the repo is not already trusted. This will eventually be the default behaviourF�checkzThe repository z� does not belong to the list of trusted repositories and as such cannot be downloaded. Do you trust this repository and wish to add it to the trusted list of repositories (y/N)?)�y�yesz"The repository is already trusted.)r�no�zUntrusted repository.zUnrecognized response �.�ar,)r>rcrNrzrdr�touch�open�tuple�next�walk�_TRUSTED_REPO_OWNERSr�r��input�lower�print� Exceptionr�r") rlrmr�r�r�r��filepath�file� trusted_repos�trusted_repos_legacy� owner_name� is_trustedr�s rr�r�s����i�i�G��w�|�|�G�^�4�4�H� �7�>�>�(� #� #�� �X�������� �h���=�4��<�<�t�<�<�<�<�<� �=�=�=�=�=�=�=�=�=�=�=����=�=�=�=�  ���� 0� 0�1�1�!�4�����:�y�1�2�2�J��m�#� .� � 4� 4� .� �-� -����� s� �M�r�!�r�r�,6� r�r�r� s� s� s� ���e����w�!6�!6�z�!6�� i�j� i� i� i�j�j�� �>�>� � �|� +� +�� <��:�;�;�;�� �^�^� � �� 0� 0��3�4�4� 4��A�h�A�A�A�B�B� B� �*� �(�C� � � *�D� �J�J�z�D�(� )� )� )� *� *� *� *� *� *� *� *� *� *� *� *���� *� *� *� *� *� *�*�*s$�>B$�$B(�+B(�0G�G�Gc�B�ddl}|j�|��duSr)rUrW� find_spec)r]r^s r�_check_module_existsr�Bs)������ �>� #� #�D� )� )�� 5�5rc��t|t��}|�@d�|D��}t|��r'tdd�|�������dSdS)Nc�0�g|]}t|���|��Sr()r�)r��pkgs r� <listcomp>z'_check_dependencies.<locals>.<listcomp>Ks'��U�U�U��;O�PS�;T�;T�U��U�U�UrzMissing dependencies: z, )rt�VAR_DEPENDENCY�lenr�rz)�mrK� missing_depss r�_check_dependenciesr�Gsr��)�!�^�<�<�L���U�U�|�U�U�U� � �|� � � S��Q�� � �,�8O�8O�Q�Q�R�R� R� �� S� Src���t|t��std���t|��t ||��}|�t |��st d|�d����|S)Nz8Invalid input: model should be a string of function namezCannot find callable z in hubconf)rZ�strr�r�rt�callabler�)r��model�funcs r�_load_entry_from_hubconfr�Psq�� �e�S� !� !�U��S�T�T�T� ����� !�!�U� +� +�D� �|�8�D�>�>�|��E�5�E�E�E�F�F�F� �Krc���tjd��rtjd��t�tStj�t��d��S)a� Get the Torch Hub cache directory used for storing downloaded models & weights. If :func:`~torch.hub.set_dir` is not called, default path is ``$TORCH_HOME/hub`` where environment variable ``$TORCH_HOME`` defaults to ``$XDG_CACHE_HOME/torch``. ``$XDG_CACHE_HOME`` follows the X Design Group specification of the Linux filesystem layout, with a default value ``~/.cache`` if the environment variable is not set. � TORCH_HUBz:TORCH_HUB is deprecated, please use env TORCH_HOME insteadN�hub)rcrxr�r�rLrNrzr~r(rrr>r>bsO�� �y����T�� �R�S�S�S����� �7�<�<��)�)�5� 1� 1�1rc�D�tj�|��adS)z� Optionally set the Torch Hub directory used to save downloaded models & weights. Args: d (str): path to a local folder to save downloaded models & weights. N)rcrNrwrL)�ds rrCrCus���w�!�!�!�$�$�H�H�Hrc�*��t|||d||���}t|��5tj�|t ��}t t |���ddd��n #1swxYwY�fd�t���D��}|S)a* List all callable entrypoints available in the repo specified by ``github``. Args: github (str): a string with format "repo_owner/repo_name[:ref]" with an optional ref (tag or branch). If ``ref`` is not specified, the default branch is assumed to be ``main`` if it exists, and otherwise ``master``. Example: 'pytorch/vision:0.10' force_reload (bool, optional): whether to discard the existing cache and force a fresh download. Default is ``False``. skip_validation (bool, optional): if ``False``, torchhub will check that the branch or commit specified by the ``github`` argument properly belongs to the repo owner. This will make requests to the GitHub API; you can specify a non-default GitHub token by setting the ``GITHUB_TOKEN`` environment variable. Default is ``False``. trust_repo (bool, str or None): ``"check"``, ``True``, ``False`` or ``None``. This parameter was introduced in v1.12 and helps ensuring that users only run code from repos that they trust. - If ``False``, a prompt will ask the user whether the repo should be trusted. - If ``True``, the repo will be added to the trusted list and loaded without requiring explicit confirmation. - If ``"check"``, the repo will be checked against the list of trusted repos in the cache. If it is not present in that list, the behaviour will fall back onto the ``trust_repo=False`` option. - If ``None``: this will raise a warning, inviting the user to set ``trust_repo`` to either ``False``, ``True`` or ``"check"``. This is only present for backward compatibility and will be removed in v2.0. Default is ``None`` and will eventually change to ``"check"`` in v2.0. verbose (bool, optional): If ``False``, mute messages about hitting local caches. Note that the message about first download cannot be muted. Default is ``True``. Returns: list: The available callables entrypoint Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> entrypoints = torch.hub.list('pytorch/vision', force_reload=True) r@�r�r�Nc�x��g|]6}tt�|�����|�d���4|��7S)r�)r�rrr�)r��f� hub_modules �rr�zlist.<locals>.<listcomp>�sE���l�l�l���'�*�a�:P�:P�1Q�1Q�l�Z[�Zf�Zf�gj�Zk�Zk�l�1�l�l�lr)r�rRrcrNrz�MODULE_HUBCONFrarq) r�r�r�r�r�r�� hubconf_path� entrypointsrs @rr@r@�s����V$�F�L�*�f�V]�4C�E�E�E�H� �(� #� #�B�B��w�|�|�H�n�=�=� �#�N�L�A�A� �B�B�B�B�B�B�B�B�B�B�B����B�B�B�B� m�l�l�l�c�*�o�o�l�l�l�K� �s�;A-�-A1�4A1c��t|||dd|���}t|��5tj�|t ��}t t |��}ddd��n #1swxYwYt||��}|jS)aT Show the docstring of entrypoint ``model``. Args: github (str): a string with format <repo_owner/repo_name[:ref]> with an optional ref (a tag or a branch). If ``ref`` is not specified, the default branch is assumed to be ``main`` if it exists, and otherwise ``master``. Example: 'pytorch/vision:0.10' model (str): a string of entrypoint name defined in repo's ``hubconf.py`` force_reload (bool, optional): whether to discard the existing cache and force a fresh download. Default is ``False``. skip_validation (bool, optional): if ``False``, torchhub will check that the ref specified by the ``github`` argument properly belongs to the repo owner. This will make requests to the GitHub API; you can specify a non-default GitHub token by setting the ``GITHUB_TOKEN`` environment variable. Default is ``False``. trust_repo (bool, str or None): ``"check"``, ``True``, ``False`` or ``None``. This parameter was introduced in v1.12 and helps ensuring that users only run code from repos that they trust. - If ``False``, a prompt will ask the user whether the repo should be trusted. - If ``True``, the repo will be added to the trusted list and loaded without requiring explicit confirmation. - If ``"check"``, the repo will be checked against the list of trusted repos in the cache. If it is not present in that list, the behaviour will fall back onto the ``trust_repo=False`` option. - If ``None``: this will raise a warning, inviting the user to set ``trust_repo`` to either ``False``, ``True`` or ``"check"``. This is only present for backward compatibility and will be removed in v2.0. Default is ``None`` and will eventually change to ``"check"`` in v2.0. Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> print(torch.hub.help('pytorch/vision', 'resnet18', force_reload=True)) r?TrN) r�rRrcrNrzrrar��__doc__) r�r�r�r�r�r�rr�entrys rr?r?�s���J$�F�L�*�f�VZ�4C�E�E�E�H� �(� #� #�B�B��w�|�|�H�n�=�=� �#�N�L�A�A� �B�B�B�B�B�B�B�B�B�B�B����B�B�B�B� %�Z�� 7� 7�E� �=�s�;A,�,A0�3A0r�)�sourcer�r�r�r�c��|���}|dvrtd|�d����|dkrt|||d||���}t||g|�Ri|��}|S)a� Load a model from a github repo or a local directory. Note: Loading a model is the typical use case, but this can also be used to for loading other objects such as tokenizers, loss functions, etc. If ``source`` is 'github', ``repo_or_dir`` is expected to be of the form ``repo_owner/repo_name[:ref]`` with an optional ref (a tag or a branch). If ``source`` is 'local', ``repo_or_dir`` is expected to be a path to a local directory. Args: repo_or_dir (str): If ``source`` is 'github', this should correspond to a github repo with format ``repo_owner/repo_name[:ref]`` with an optional ref (tag or branch), for example 'pytorch/vision:0.10'. If ``ref`` is not specified, the default branch is assumed to be ``main`` if it exists, and otherwise ``master``. If ``source`` is 'local' then it should be a path to a local directory. model (str): the name of a callable (entrypoint) defined in the repo/dir's ``hubconf.py``. *args (optional): the corresponding args for callable ``model``. source (str, optional): 'github' or 'local'. Specifies how ``repo_or_dir`` is to be interpreted. Default is 'github'. trust_repo (bool, str or None): ``"check"``, ``True``, ``False`` or ``None``. This parameter was introduced in v1.12 and helps ensuring that users only run code from repos that they trust. - If ``False``, a prompt will ask the user whether the repo should be trusted. - If ``True``, the repo will be added to the trusted list and loaded without requiring explicit confirmation. - If ``"check"``, the repo will be checked against the list of trusted repos in the cache. If it is not present in that list, the behaviour will fall back onto the ``trust_repo=False`` option. - If ``None``: this will raise a warning, inviting the user to set ``trust_repo`` to either ``False``, ``True`` or ``"check"``. This is only present for backward compatibility and will be removed in v2.0. Default is ``None`` and will eventually change to ``"check"`` in v2.0. force_reload (bool, optional): whether to force a fresh download of the github repo unconditionally. Does not have any effect if ``source = 'local'``. Default is ``False``. verbose (bool, optional): If ``False``, mute messages about hitting local caches. Note that the message about first download cannot be muted. Does not have any effect if ``source = 'local'``. Default is ``True``. skip_validation (bool, optional): if ``False``, torchhub will check that the branch or commit specified by the ``github`` argument properly belongs to the repo owner. This will make requests to the GitHub API; you can specify a non-default GitHub token by setting the ``GITHUB_TOKEN`` environment variable. Default is ``False``. **kwargs (optional): the corresponding kwargs for callable ``model``. Returns: The output of the ``model`` callable when called with the given ``*args`` and ``**kwargs``. Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> # from a github repo >>> repo = 'pytorch/vision' >>> model = torch.hub.load(repo, 'resnet50', weights='ResNet50_Weights.IMAGENET1K_V1') >>> # from a local directory >>> path = '/some/local/path/pytorch/vision' >>> # xdoctest: +SKIP >>> model = torch.hub.load(path, 'resnet50', weights='ResNet50_Weights.DEFAULT') )r��localzUnknown source: "z&". Allowed values: "github" | "local".r�rAr)r�r�r�� _load_local) � repo_or_dirr�r r�r�r�r�rrs rrArA�s���N�\�\�^�^�F� �(�(�(�� N�� N� N� N�P�P� P�����*�;� �j�RX�3:�O�]�]�]� � � �U� <�T� <� <� <�V� <� <�E� �Lrc���t|��5tj�|t��}t t|��}t ||��}||i|��}ddd��n #1swxYwY|S)a� Load a model from a local directory with a ``hubconf.py``. Args: hubconf_dir (str): path to a local directory that contains a ``hubconf.py``. model (str): name of an entrypoint defined in the directory's ``hubconf.py``. *args (optional): the corresponding args for callable ``model``. **kwargs (optional): the corresponding kwargs for callable ``model``. Returns: a single model with corresponding pretrained weights. Example: >>> # xdoctest: +SKIP("stub local path") >>> path = '/some/local/path/pytorch/vision' >>> model = _load_local(path, 'resnet50', weights='ResNet50_Weights.IMAGENET1K_V1') N)rRrcrNrzrrar�)� hubconf_dirr�rrrrr s rrr>s���( �+� &� &�'�'��w�|�|�K��@�@� �#�N�L�A�A� �(��U�;�;����t�&�v�&�&�� '�'�'�'�'�'�'�'�'�'�'����'�'�'�'� �Ls�AA/�/A3�6A3r��dst� hash_prefixr��returnc�4�d}t|ddi���}t|��}|���}t|d��r|�d��}n|�d��}|�(t |��dkrt|d��}tj � |��}ttj ��D]F} |dztj��jzd z} t#| d ��} n#t$$rY�AwxYwnt%t&jd ��� |�t+j��} t/|| d d d���5} |�t2��}t |��dkrnO| �|��|�| �|��| �t |�����} ddd��n #1swxYwY| ���|�E| ���}|dt |���|krt=d|�d|�d����t?j | j!|��| ���tj �"| j!��rtj#| j!��dSdS#| ���tj �"| j!��rtj#| j!��wwxYw)a�Download object at the given URL to a local path. Args: url (str): URL of the object to download dst (str): Full path where object will be saved, e.g. ``/tmp/temporary_file`` hash_prefix (str, optional): If not None, the SHA256 downloaded file should start with ``hash_prefix``. Default: None progress (bool, optional): whether or not to display a progress bar to stderr Default: True Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> # xdoctest: +REQUIRES(POSIX) >>> torch.hub.download_url_to_file('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth', '/tmp/temporary_file') Nz User-Agentz torch.hubr�� getheaderszContent-Lengthrr�z.partialzw+bz#No usable temporary file name found�BTi)rrr� unit_scale� unit_divisorzinvalid hash value (expected "z", got "z"))$r r �info�hasattrr�get_allr��intrcrNrw�range�tempfile�TMP_MAX�uuid�uuid4�hexr��FileExistsError�errno�EEXIST�hashlib�sha256r<r��READ_DATA_CHUNKr"r%r1� hexdigestr�rfr�r]rdrP)r�rrr�� file_size�req�u�meta�content_length�seq�tmp_dstrr)�pbar�buffer�digests rr=r=\sA��$�I� �#� �k�:� ;� ;� ;�C��� � �A� �6�6�8�8�D��t�\�"�"�8����)9�:�:������&6�7�7���!�c�.�&9�&9�A�&=�&=���q�)�*�*� � �'� � �S� !� !�C��X�%�&�&�S�S����)�d�j�l�l�.�.��;�� ��W�e�$�$�A�A��� � � � �H� ���� ���e�l�,Q�R�R�R�� � "��^�%�%�F� � �x�<��t�$�@�@�@� )�CG� )�����0�0���v�;�;�!�#�#����������*��M�M�&�)�)�)�� � �C��K�K�(�(�(� )�� )� )� )� )� )� )� )� )� )� )� )���� )� )� )� )� ��� � � � � "��%�%�'�'�F��'�s�;�'�'�'�(�K�7�7�"�#c�K�#c�#c�Y_�#c�#c�#c�d�d�d�� �A�F�C� � � � ��� � � � �7�>�>�!�&� !� !� � �I�a�f� � � � � � � �� ��� � � � �7�>�>�!�&� !� !� � �I�a�f� � � � � ���sE�:D � D�D�8*K�"A?G.�" K�.G2�2K�5G2�6A8K�ALr�c���tj|��rTtj|�����}t |��dko|d��� SdS)Nr�rF)r�� is_zipfiler�r�r��is_dir)r�r�s r�_is_legacy_zip_formatr9�s^����(�#�#�?��?�8�,�,�5�5�7�7���8�}�}��!�>�(�1�+�*<�*<�*>�*>�&>�>� �5rz�Falling back to the old format < 1.6. This support will be deprecated in favor of default zipfile format introduced in 1.6. Please redo torch.save() to save it in the new zipfile format.)�category� model_dir� map_location� weights_onlyc�x�tj|��5}|���}t|��dkrt d���|�|��|dj}tj� ||��}ddd��n #1swxYwYtj |||���S)Nr�z0Only one file(not dir) is allowed in the zipfiler�r<r=) r�r�r�r�r�r�r�rcrNrzrvrA)r�r;r<r=r�members� extraced_name�extracted_files r�_legacy_zip_loadrC�s��� ��� "� "�@�a��*�*�,�,�� �w�<�<�1� � ��Q�R�R� R� � � �Y������ �+� �����i��?�?�� @�@�@�@�@�@�@�@�@�@�@����@�@�@�@� �:�n�<�l� [� [� [�[s�A9B�B�!B� check_hash� file_namec��tjd��rtjd��|�.t ��}tj�|d��}tj|d���t|��}tj� |j��} |�|} tj�|| ��} tj� | ��sptj � d|�d| �d ���d} |r3t�| ��} | r| �d ��nd} t#|| | |� ��t%| ��rt'| |||��St)j| ||� ��S) aSLoads the Torch serialized object at the given URL. If downloaded file is a zip file, it will be automatically decompressed. If the object is already present in `model_dir`, it's deserialized and returned. The default value of ``model_dir`` is ``<hub_dir>/checkpoints`` where ``hub_dir`` is the directory returned by :func:`~torch.hub.get_dir`. Args: url (str): URL of the object to download model_dir (str, optional): directory in which to save the object map_location (optional): a function or a dict specifying how to remap storage locations (see torch.load) progress (bool, optional): whether or not to display a progress bar to stderr. Default: True check_hash(bool, optional): If True, the filename part of the URL should follow the naming convention ``filename-<sha256>.ext`` where ``<sha256>`` is the first eight or more digits of the SHA256 hash of the contents of the file. The hash is used to ensure unique names and to verify the contents of the file. Default: False file_name (str, optional): name for the downloaded file. Filename from ``url`` will be used if not set. weights_only(bool, optional): If True, only weights will be loaded and no complex pickled objects. Recommended for untrusted sources. See :func:`~torch.load` for more details. Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> state_dict = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth') �TORCH_MODEL_ZOOz@TORCH_MODEL_ZOO is deprecated, please use env TORCH_HOME insteadN� checkpointsTr�r�r�r,r�r�r?)rcrxr�r�r>rNrzr�r �basenamerdr r!r"� HASH_REGEX�search�groupr=r9rCrvrA) r�r;r<r�rDrEr=r��partsr�r�rr�s rrBrB�sq��P �y�"�#�#�Z�� �X�Y�Y�Y����)�)���G�L�L��-�8�8� ��K� �D�)�)�)�)� �S�M�M�E��w���� �+�+�H������'�,�,�y�(�3�3�K� �7�>�>�+� &� &�O� � ���C�#�C�C�K�C�C�C�D�D�D�� � � 4��!�!�(�+�+�A�()�3�!�'�'�!�*�*�*�t�K��S�+�{�X�N�N�N�N��[�)�)�T�� �Y� �l�S�S�S� �:�k� �<� X� X� X�Xr)TF)rA)FFNT)FFNr/)NNTFNF)K� contextlibr&r(r�rc�rerfr r rvr"r�r��pathlibr�typingrrr�typing_extensionsr� urllib.errorrr �urllib.requestr r � urllib.parser �torch.serializationr rr<� ImportError�__all__�compilerJr�r�ryr{r|r�rr*rLr��__annotations__�contextmanagerrRrarhrortr~r�r�r�r�r�r�r�r�r>rCr@r?rAr�boolr=r9� FutureWarningrCrBr(rr�<module>r^s ������� � � � ����� � � � � � � � � � � � � � � � � � � � ����� � � � � � � � ���������������&�&�&�&�&�&�&�&�&�&�(�(�(�(�(�(�,�,�,�,�,�,�,�,�+�+�+�+�+�+�+�+�!�!�!�!�!�!�,�,�,�,�,�,�%�%�%�%�%�%�%�%�N������������� �D�D�D����� � � ���R�Z�)� *� *� �[��!����%������������(�3�-���� ���������� � � �H�H�H� &�&�&����&�&�&�BG�G�G� p�p�p�2B�B�B�B�J/*�/*�/*�/*�d6�6�6� S�S�S����$2�2�2�&%�%�%�5�5�5�5�p.�.�.�.�b,4��SX�bf��R�R�R�R�R�j���<KO�*.�D�D�c�D��D�(�3�-�D�#'�D�37�D�D�D�D�T�C��D����� ��E�� ��� \�s� \�s� \�,� \�^b� \�gk�lo�qt�lt�gu� \� \� \� �� \� $�!%���#��@Y�@Y� �@Y���}�@Y��@Y�� @Y� � @Y� ��}� @Y��@Y� �#�s�(�^�@Y�@Y�@Y�@Y�@Y�@Ys�6A=�=B�B
Memory