� ��g>����ddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z ddl m Z mZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlm Z ddl!m"Z"Gd�d e��Z#d Z$d e%d ee%ee%ffd �Z&ed��Z'ed��Z(dee'gee(fdee'd ee(fd�Z)dee'gee(fdee'd ee(fd�Z*ej+dege%fd edfd���Z,ded efd�Z-ej.d���de%d e"fd���Z/de%d e0fd�Z1Gd�d��Z2 d5ded ee%d e2fd!�Z3 d6d#ed$e0d%e0d e%fd&�Z4 d7d#ed$e0d%e0d'e0d e%f d(�Z5d)eeefd$e0d%e0d'e0d e%f d*�Z6d)eeeeeeed+ffd$e0d%e0d'e0d e%f d,�Z7d-ee%d$e0d%e0d'e0d.e%d/e%d e%fd0�Z8Gd1�d2��Z9Gd3�d4ee'��Z:dS)8�N)� Namespace)�fields� is_dataclass)�auto�Enum)�Any�Callable�Dict�Generic�Iterable�Iterator�List�Literal�NoReturn�Optional�Sequence�Set�Tuple�TypeVar�Union)�Self)� CodeTemplatec��eZdZe��Ze��Ze��Ze��Ze��Ze��Z dS)�TargetN) �__name__� __module__� __qualname__r� DEFINITION� DECLARATION� REGISTRATION�ANONYMOUS_DEFINITION�NAMESPACED_DEFINITION�NAMESPACED_DECLARATION���^/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/torchgen/utils.pyrr)sU����������J��$�&�&�K��4�6�6�L��4�6�6�� �D�F�F��!�T�V�V���r%rz(^|\W){}($|\W)�schema�returnc��tjd|��}|�td|�����|���\}}}||�d��fS)Nz(\w+)(\.\w+)?\((.*)\)zUnsupported function schema: �, )�re�match� RuntimeError�groups�split)r'�m�name�_�paramss r&�split_name_paramsr4<sZ�� ��)�6�2�2�A��y��C�6�C�C�D�D�D��h�h�j�j�O�D�!�V� ����d�#�#� #�#r%�T�S�func�xsc#�6K�|D]}||��}|�|V��dS�Nr$)r7r8�x�rs r&�mapMayber=Ls;���� ���� �D��G�G�� �=��G�G�G���r%c#�6K�|D]}||��Ed{V���dSr:r$)r7r8r;s r&� concatMapr?TsB���� �����4��7�7����������r%�msg_fnc#��K� dV�dS#t$rX}|��}tj|d��}|jr|jd�d|��n|}|f|jdd�z|_�d}~wwxYw)Nz r� �)� Exception�textwrap�indent�args)r@�e�msgs r&�contextrJ\s������ ������� �����f�h�h���o�c�4�(�(��'(�v�6�����#�#�c�#�#�#�3����!�&����*�$��� ����� ���s� � A,�AA'�'A,r;c�J�tdt|��j�����)NzUnhandled type: )�AssertionError�typer)r;s r&� assert_neverrNls"�� �>�D��G�G�,<�>�>� ?� ?�?r%)�maxsize� template_fnc�*�tj|��Sr:)r� from_file)rPs r&�_read_templaterSps�� � !�+� .� .�.r%�sc��tj|�d�������}t�|d���S)N�latin1�little)� byteorder)�hashlib�sha1�encode�digest�int� from_bytes)rTrZs r&�string_stable_hashr_vs?�� �<�����*�*� +� +� 2� 2� 4� 4�D� �>�>�$�(�>� 3� 3�3r%c��eZdZUeed<eed<eed<eeed<dedededdfd�Zded eddfd �Zd ed e ge ee ee fffdefd �Z ded ed e ge ee ee fffddfd�Zded e ge ee ee fffddfd�Zdd�dedeede egefd e ege eeeffdedee ee fdeeddfd�Zdededdfd�Zdefd�ZdS)� FileManager� install_dir� template_dir�dry_run� filenamesr(Nc�V�||_||_t��|_||_dSr:)rbrc�setrerd)�selfrbrcrds r&�__init__zFileManager.__init__�s(��&���(���������� � � r%�filename�contentsc�� t|��5}|���}ddd��n #1swxYwYn#t$rd}YnwxYw||krstjtj�|��d���t|d��5}|�|��ddd��dS#1swxYwYdSdS)NT)�exist_ok�w)�open�read�OSError�os�makedirs�path�dirname�write)rhrjrk�f� old_contentss r&�_write_if_changedzFileManager._write_if_changed�sP�� ��h��� (�1� �v�v�x�x� � (� (� (� (� (� (� (� (� (� (� (���� (� (� (� (���� � � ��L�L�L� ���� �|� #� #� �K������1�1�D� A� A� A� A��h��$�$� "������!�!�!� "� "� "� "� "� "� "� "� "� "� "� "���� "� "� "� "� "� "� $� #s9�>�2� >�6�>�6�>� A � A �B<�<C�CrP� env_callablec��tj�|j|��}|��}t |t ��rTd|vr,d}|dtj�|����z }||d<t|��}|�|��St |t��r|St|��dS)N�generated_commentz@generated by torchgen/gen.pyz from ) rrrt�joinrc� isinstance�dict�basenamerS� substitute�strrN)rhrPrz� template_path�env�comment�templates r&�substitute_with_templatez$FileManager.substitute_with_template�s����� � �T�%6� �D�D� ��l�n�n�� �c�4� � � �"�#�-�-�>���E�B�G�$4�$4�]�$C�$C�E�E�E��+2��'�(�%�m�4�4�H��&�&�s�+�+� +� ��S� !� !� ��J� �� � � � � r%c���|j�d|��}||jvs Jd���|j�|��|js0|�||���}|�||���dSdS)N�/zduplicate file write {filename})rPrz)rjrk)rbre�addrdr�ry)rhrjrPrz�substitute_outs r&�write_with_templatezFileManager.write_with_template�s��� �&�3�3��3�3���t�~�-�-�-�/P�-�-�-� ����8�$�$�$��|� O�!�:�:�'�)�;���N� � "� "�H�~� "� N� N� N� N� N�  O� Or%c�4�|�|||��dSr:)r�)rhrjrzs r&rvzFileManager.write�s"�� � � ��8�\�B�B�B�B�Br%)�base_env�items�key_fn� num_shardsr�� sharded_keysc����ddi}d�t|��D��} |g| z} |�| D]���|����D]S} | D]N�| �vrCt�| t��s Jd����| ����| <�Ig�| <�O�Tdt t tt fdt t tt fddf�fd� } |jrd }|D]H} || ��} t| ��|z}|| ��}| | ||��| ||���I|� d ��}|d krt|��}|d|�}||d�}| D]*��d}|� |�|�|��|�fd ����+|j �|j�d |�d|����dS)N�shard_id� Everythingc��g|] }dd|��i�� S)r�r2r$)�.0�is r&� <listcomp>z-FileManager.write_sharded.<locals>.<listcomp>�s0��( �( �( �&'�Z��Q��� !�( �( �( r%z'sharded keys in base_env must be a list�into�from_r(c�~��|���D]&\}}|�vs Jd|�����||xx|z cc<�'dS)Nzundeclared sharded key )r�)r�r��k�vr�s �r&� merge_envz,FileManager.write_sharded.<locals>.merge_env�sa���� � � � � � ���1��L�(�(�(�*G�A�*G�*G�(�(�(��Q����1� ����� � r%r$�.�����c����Sr:r$)�shards�r&�<lambda>z+FileManager.write_sharded.<locals>.<lambda>�s���5�r%r�)�range�updater~�list�copyr r�rrdr_�rfind�lenr�re�discardrb)rhrjr�r�rzr�r�r�� everything�shards� all_shards�keyr��item�sidr��dot_pos� base_filename� extensionr�r�s ` @r&� write_shardedzFileManager.write_sharded�s�����'1�,�%?� �( �( �+0��+<�+<�( �( �( ��!�\�F�*� � � �#� '� '��� � �X�&�&�&�&�� $� $�C�#� $� $���%�<�<�%��c� �D���A�A�@�A�A��"'�s����!2�!2�E�#�J�J�!#�E�#�J�J� $� �D��d�3�i��0� ��c�4��9�n�9M� �RV� � � � � � � �<� ��E�� '� '�D��&��,�,�C�$�S�)�)�J�6�C��,�t�$�$�C� �I�f�S�k�3� '� '� '� �I�j�#� &� &� &� &��.�.��%�%�� �b�=�=��(�m�m�G� ��'��*� ��W�X�X�&� �� � �E��Z�(�H� � $� $� �7�(�7�I�7�7��=�=�=�=� � � � � ������ F� F�-� F� F�9� F� F� � � � � r%� variable_namec ��d�|d�d�t|j��D������}|�||��dS)z[Write a file containing the list of all outputs which are generated by this script.zset({} {})z c3�&K�|] }d|zdzV�� dS)�"Nr$)r�r1s r&� <genexpr>z,FileManager.write_outputs.<locals>.<genexpr>s+����N�N�t�#��*�s�*�N�N�N�N�N�Nr%N)�formatr}�sortedrery)rhr�rj�contents r&� write_outputszFileManager.write_outputssb��$�*�*� � �M�M�N�N�v�d�n�7M�7M�N�N�N� N� N� � �� ���x��1�1�1�1�1r%c��tj�|jtj�t ����S)z� This needs to be deterministic. The template dir is an absolute path that varies across builds. So, just use the path relative to this file, which will point to the codegen source but will be stable. )rrrt�relpathrcru�__file__�rhs r&�template_dir_for_commentsz%FileManager.template_dir_for_comments s+�� �w���t�0�"�'�/�/�(�2K�2K�L�L�Lr%)rrrr��__annotations__�boolrriryr rr rr�r�rvr r5rr]rr�r�r�r$r%r&rara~s���������������� �M�M�M��3�x�����C��s��T��d����� "�#� "�� "�� "� "� "� "����.6�r�5��d�3�PS�8�n�AT�;U�7U�.V�� �����$O��O��O��r�5��d�3��8�n�)<�#=�=�>� O� � O�O�O�O� C��C��r�5��d�3��8�n�)<�#=�=�>�C� � C�C�C�C�.2�? �? �? ��? ���{�? � �!��c��"� ? � ��s�D��d�3�i��$8�8�9� ? ��? ��4��S��>�*�? ��#�h�? � �? �? �? �? �B2�3�2�#�2�$�2�2�2�2�M�3�M�M�M�M�M�Mr%ra�optionsrbc��tj�|jd��}|r|n|j}t |||j���S)N� templates)rbrcrd)rrrtr}� source_pathrbrard)r�rbrcs r&�make_file_managerr�sM���7�<�<�� 3�[�A�A�L�!,�E�+�+�'�2E�K� ��l�G�O� � � �r%�P�objrF�widthc�l�tjdkrddlm}||||��St |||���S)N)�� r)�pformat)rFr�)�sys� version_info�pprintr��_pformat)r�rFr�r�s r&�dataclass_reprr� sM��  ��7�"�"�"�"�"�"�"�"��w�s�F�E�*�*�*� �C��e� 4� 4� 4�4r%� curr_indentc���t���sJdt���������jj}|t |��dzz }�fd�t ���D��}g}|D]�\}}|t |��zdz} t|��rt |||| ��} nlt|t��rt|||| ��} nDt|tttf��rt|||| ��} nt|��} |�|�d| ������|dz} d| ���|��} |�d| �d�S) Nz%obj should be a dataclass, received: rCc�V��g|]%}|j� |jt�|j��f��&Sr$)�reprr1�getattr)r�rwr�s �r&r�z_pformat.<locals>.<listcomp>:s3���Q�Q�Q�a�!�&�Q�A�F�G�C���0�0�1�Q�Q�Qr%�=� z, �(�))rrM� __class__rr�rr�r~r� _format_dictr�rg�tuple� _format_listr��appendr}) r�rFr�r�� class_name� fields_list� fields_strr1�attr� _curr_indent�str_repr� indent_str�bodys ` r&r�r�.s���� �� � �Q�Q�Q�d�3�i�i�Q�Q�Q�Q� ���'�J��3�z�?�?�Q�&�&�K�Q�Q�Q�Q�6�#�;�;�Q�Q�Q�K��J�!� 0� 0� ��d�#�S��Y�Y�.��2� � �� � � "���f�e�\�B�B�H�H� ��d� #� #� "�#�D�&�%��F�F�H�H� ��t�S�%�0� 1� 1� "�#�D�&�%��F�F�H�H��D�z�z�H����T�.�.�H�.�.�/�/�/�/��s�"�J� �� � � "� "�:� .� .�D�� "� "�4� "� "� "�"r%r�c �D�||dzz }g}|���D]n\}}t|��}t|��r"t||||t |��z��nt|��}|�|�d|�����ot ||||dd��S)Nr�z: �{�})r�r�rr�r�r��_format) r�rFr�r�� dict_reprr�r��k_repr�v_strs r&r�r�Qs��� �6�A�:��K��I�� � � � �/�/���1��a�����A��� �H�Q���{�S��[�[�'@� A� A� A��a��� � ���F�-�-�e�-�-�.�.�.�.� �9�f�e�[�#�s� C� C�Cr%.c�������dzz ����fd�|D��}t|t��rdnd\}}t|���||��S)NrCc�p��g|]2}t|��rt|�����nt|����3Sr$)rr�r�)r��lr�rFr�s ���r&r�z _format_list.<locals>.<listcomp>lsN������ �4@��?�?�O���F�E�;�/�/�/��Q�����r%)�[�])r�r�)r~r�r�)r�rFr�r�� list_repr�start�ends ``` r&r�r�es}����� �6�A�:��K�����������I� *�$��5�5�E���:�J�E�3� �9�f�e�[�%�� E� E�Er%r�r�r�c��d\}}tt|����|krd}d|z}d|z}d|�|���|��} |�|�| �|��S)N)�r�rBr�r*)r�r�r}) r�rFr�r�r�r�� delimiter�curr_indent_strr�r�s r&r�r�ts|��"(��I�� �4� � � ����%�%�� �� �+���v��J� ,� � ,�?� ,� ,� 1� 1�*� =� =�D�� ,�Z� ,�� ,�s� ,� ,�,r%c��eZdZdZddededefd�Ze ddeded dfd ���Ze d efd ���Z e d efd ���Z e d efd ���Z dded efd�Z dS)�NamespaceHelperaA helper for constructing the namespace open and close strings for a nested set of namespaces. e.g. for namespace_str torch::lazy, prologue: namespace torch { namespace lazy { epilogue: } // namespace lazy } // namespace torch r��� namespace_str� entity_name� max_levelc�L�|�d��}t|��|ksJd|�d|�d����||_d�d�|D����|_d�d�t |��D����|_||_||_dS)N�::z"Codegen doesn't support more than z# level(s) of custom namespace. Got r�rBc��g|]}d|�d��� S)z namespace z {r$�r��ns r&r�z,NamespaceHelper.__init__.<locals>.<listcomp>�s$��#P�#P�#P�A�$7��$7�$7�$7�#P�#P�#Pr%c��g|]}d|����S)z} // namespace r$r s r&r�z,NamespaceHelper.__init__.<locals>.<listcomp>�s!�� F� F� F�� #�� #� #� F� F� Fr%) r/r��cpp_namespace_r}� prologue_�reversed� epilogue_� namespaces_� entity_name_)rhrrr�cpp_namespacess r&rizNamespaceHelper.__init__�s���&�,�,�T�2�2�� �� � �9� ,� ,� ,� n� � n� n�^k� n� n� n� -� ,� ,�+������#P�#P��#P�#P�#P�Q�Q������ F� F�X�n�-E�-E� F� F� F� � ���*���'����r%�namespaced_entityr(c��|�d��}|d}d�|dd���}t|||���S)zq Generate helper from nested namespaces as long as class/function name. E.g.: "torch::lazy::add" rr�N)rrr)r/r}r)rr�namesrrs r&�from_namespaced_entityz&NamespaceHelper.from_namespaced_entity�sW��"�'�'��-�-���B�i� �� � �%����*�-�-� ��'�[�I� � � � r%c��|jSr:)r r�s r&�prologuezNamespaceHelper.prologue�� ���~�r%c��|jSr:)rr�s r&�epiloguezNamespaceHelper.epilogue�rr%c��|jSr:)rr�s r&rzNamespaceHelper.entity_name�s ��� � r%�defaultc�"�|jr|jn|S)z� Return the namespace string from joining all the namespaces by "::" (hence no leading "::"). Return default if namespace string is empty. )r )rhrs r&�get_cpp_namespacez!NamespaceHelper.get_cpp_namespace�s�� '+�&9�F�t�"�"�w�Fr%N)r�r)r)r�)rrr�__doc__r�r]ri� staticmethodr�propertyrrrrr$r%r&rr�s1������ � � (� (�c� (�� (�S� (� (� (� (��12�  �  ��  �+.�  � �  �  �  ��\�  ���#�����X����#�����X���!�S�!�!�!��X�!�G�G��G�c�G�G�G�G�G�Gr%rc���eZdZUeeedfed<ddeeefd�Z dede fd�Z de efd�Z dd �Zdeddfd �Zdd �Zedd���Zdd�Zdd defd�Zdede fd�ZdS)� OrderedSetN�storage�iterablec�Z�|� i|_dSt�|��|_dSr:)r%r�fromkeys)rhr&s r&rizOrderedSet.__init__�s*�� � ��D�L�L�L��=�=��2�2�D�L�L�Lr%r�r(c��||jvSr:�r%�rhr�s r&� __contains__zOrderedSet.__contains__�s���t�|�#�#r%c�N�t|j�����Sr:)�iterr%�keysr�s r&�__iter__zOrderedSet.__iter__�s���D�L�%�%�'�'�(�(�(r%r�� OrderedSet[T]c�D�|j�|j��dSr:)r%r�)rhr�s r&r�zOrderedSet.update�s �� � ���E�M�*�*�*�*�*r%c��d|j|<dSr:r*r+s r&r�zOrderedSet.add�s��!�� �T���r%c�^�t��}|j���|_|Sr:)r$r%r�)rh�rets r&r�zOrderedSet.copy�s%��'�\�\���l�'�'�)�)�� �� r%rGc�~�|d���}|dd�D]}|�|���|S)NrrC)r�r�)rGr5rTs r&�unionzOrderedSet.union�s@���1�g�l�l�n�n���a�b�b�� � �A� �J�J�q�M�M�M�M�� r%�otherc�8�t�||��Sr:)r$r7�rhr8s r&�__or__zOrderedSet.__or__�s������e�,�,�,r%c�0�|�|��|Sr:)r�r:s r&�__ior__zOrderedSet.__ior__�s�� � � �E����� r%c��t|t��r|j|jkSt|j�����|kSr:)r~r$r%rgr/r:s r&�__eq__zOrderedSet.__eq__�sD�� �e�Z� (� (� 5��<�5�=�0� 0��t�|�(�(�*�*�+�+�u�4� 4r%r:)r�r1r(N)r(r1)rGr1r(r1)r8r1r(r1)rrrr r5rr�rr rir�r,r r0r�r�r�r!r7r;rr=�objectr?r$r%r&r$r$�s\������� �!�W�T�]�"� #�#�#�#�3�3��(�1�+�!6�3�3�3�3� $��$�t�$�$�$�$�)�(�1�+�)�)�)�)�+�+�+�+�"��"�d�"�"�"�"����� �����\�� -�-�-�-��_�������5�F�5�t�5�5�5�5�5�5r%r$r:)rr�)r);� contextlib� functoolsrYrrr+r�rE�argparser� dataclassesrr�enumrr�typingrr r r r r rrrrrrrrr�typing_extensionsr�torchgen.code_templaterr� IDENT_REGEXr�r4r5r6r=r?�contextmanagerrJrN� lru_cacherSr]r_rar�r�r�r�r�r�rr$r$r%r&�<module>rLs��������������� � � � � � � � � � � � �����������,�,�,�,�,�,�,�,�������������������������������������������"#�"�"�"�"�"�/�/�/�/�/�/� $� $� $� $� $�T� $� $� $� � �$�c�$�e�C��c��N�&;�$�$�$�$� �G�C�L�L�� �G�C�L�L���8�Q�C��!��,�-��8�A�;��8�A�;������H�a�S�(�1�+�-�.��H�Q�K��H�Q�K����� �� �H�R��W�%� �(�4�.� � � ��� �@�H�@��@�@�@�@����T�"�"�"�/��/� �/�/�/�#�"�/� 4�#�4�#�4�4�4�4�SM�SM�SM�SM�SM�SM�SM�SM�p6:��� ��%-�c�]��������� 5� 5� � 5� � 5� � 5� � 5� 5� 5� 5�$� #� #� � #� � #� � #�� #�  � #� #� #� #�FD� �s�C�x�.�D� �D� �D�� D�  � D�D�D�D�( F� ��S� �3�s�8�U�3��8�_�4� 5� F� � F� � F�� F�  � F� F� F� F�-��S� �-� �-� �-�� -� � -� � -� �-�-�-�-�&<G�<G�<G�<G�<G�<G�<G�<G�~,5�,5�,5�,5�,5����,5�,5�,5�,5�,5r%
Memory