a
    €þdøÛ  ã                   @   sÖ  U d Z ddlZddlZddlZddlZddlZddlZddlZejdk rPe	dƒ‚ddl
mZmZ ddlmZmZmZmZ ejdkrˆd	Zndd
lmZ ddlmZmZmZmZmZmZmZmZ ddlZg d¢Zejdkr¤e  dd¡Z!ej" #ej$dd¡Z%ej" #ej" &e'¡d¡Z(ej$ej)kr.ej" #ej)dd¡Z*ndZ*e+e,ej"j-e(e%e*gƒƒZ.e/dd„ e.D ƒƒr„ej" #e  dej" #e!dd¡¡dd¡Z0ndZ0ddl1m2Z3 ddl4Z4e3røe/dd„ e.D ƒƒrøe3 5dd¡Z6de6 Z7ej" #e!dd d!e3 ¡Z8ej" #e  e7e8¡d¡Z9ndZ9e. :e,ej"j-e0e9gƒ¡ ej;d"d#d$Z<e=e<d%ƒZ>e< ?d¡Z@ejAe<jB_Ce>rPejAe<jD_Ce.D ]ZEe FeE¡ qTz"e Gd&¡ e Gd'¡ e Gd(¡ W n eHy¤   eId)ƒ Y n0 e4 4ej" #e(d*¡¡ZJd+ZKeJD ]ÖZLd+ZMe>r.e< DeLdd,¡ZNe O¡ ZPeNdu r ePd-kr e QeP¡ZReR jSd.eL› d/7  _SeR‚neNdur.d#ZMeMsÂeKsZd0 #e.ejTd1 g ¡ejTd1< d#ZKe< BeL¡ZNeNdu rÂe Qe O¡ ¡ZReR jSd.eL› d/7  _SeR‚qÂe< ?e@¡ d2d3„ ZUd4d5„ ZVesÆe  d6¡rejdksàe W¡ d7kre X¡ ZYe Zej[ej\B ¡ dd8l]T e ZeY¡ [YnereVƒ  dd8l]T er6ddl]m^Z^ G d9d:„ d:ƒZ_G d;d<„ d<ƒZ`G d=d>„ d>ƒZad?d@„ ZbdAdB„ ZcdCdD„ ZddEdF„ ZedGdH„ ZfzddIl]mgZg W nB ehyÚ   ddl]m^Zi eij'du rÔehe jdJ¡ k¡ ƒd‚‚ Y n0 ele^ƒD ]hZmemd dkräem ndK¡säe oem¡ epe^emƒZqereqeƒs.e seq¡räeqjtdLkräemdMvrädLeq_tqäes¢ele^ƒD ]DZuepe^euƒZvewevƒewe^ƒu r\dNeu› ejxvr\evejxdNeu› < q\dOdP„ ZydQdR„ ZzdSdT„ Z{da|dUdV„ Z}dWdX„ Z~dYdZ„ Zd+d[œd\d]„Z€d^d_„ Zd`da„ Z‚eejƒe„f ddbœdcdd„Z…ejƒdeœdfdg„Z†ej„deœdhdi„Z‡djdk„ Zˆdldm„ Z‰dndo„ ZŠddplm‹Z‹mŒZŒmZmŽZŽ e :g dq¢¡ ddrlmZ ddsl‘m’Z’m“Z“m”Z”m•Z•m–Z– G dtdu„ due”ƒZ—G dvdw„ dwe”ƒZ˜G dxdy„ dye”ƒZ™G dzd{„ d{e”ƒZšG d|d}„ d}e”ƒZ›G d~d„ de”ƒZœG d€d„ de”ƒZG d‚dƒ„ dƒe”ƒZžG d„d…„ d…e”ƒZŸG d†d‡„ d‡e”ƒZ G dˆd‰„ d‰e”ƒZ¡G dŠd‹„ d‹e”ƒZ¢G dŒd„ de”ƒZ£G dŽd„ de”ƒZ¤G dd‘„ d‘e”ƒZ¥G d’d“„ d“e”ƒZ¦G d”d•„ d•e”ƒZ§e•e˜e™e›eœeeže—ešeŸe£e¤e¥e e¢e¡e¦e§e“hZ¨e©ƒ Zªee e«d–< dd—l¬m­Z­m®Z®m¯Z¯m°Z°m±Z± dd˜l²m³Z³m´Z´ dd™lµm¶Z¶ dšd›„ Z·ddœl¸m¹Z¹ eºZ»eƒZ¼e^ ge·ƒ ¡ [·erVdd8l½T e¾Z¿[¾dZÀele^jÁƒD ]nZmem Âdž¡sdemeÀv r‚qdepe^jÁemƒZqdLeq_temdŸkr°eqeÃƒ em< dem ZmeqeÃƒ em< em Âd¡sde oem¡ qddd8lÄT [’[”d d¡„ ZÅddlÆm2Z2 dd¢lÆmÇZÇ dd£lÆmÈZÈ dd¤lÉmÊZÊmËZËmÌZÌmÍZÍ dd¥lÆmÎZÎ dd¦lÆmÏZÏ dd§lÆmÐZÐ dd¨lÆmÑ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Ø dd®lÆmÙZÙ ddlÚZÆdd¯lÆmÛZÛ dd°lÆmÜZÜ dd±lÆmÝZÝ dd²lÆmÞZÞ dd³lÆm¬Z¬ dd´lÆmßZß ddµlÆmàZà ddláZÆddlâZÆddlãZÆddläZÆddlåZÆddlæZÆddlçZÆddlèZÆdd¶lÆméZé dd·lÆmêZê dd¸lÆmëZë dd¹lÆmìZì ddlíZÆddlîZÆddlïZÆddlðZÆe^ ñe+eÆj¨ƒ¡ ddºlòmóZómôZômõZõ [ó[ô[õd»d¼„ Zödd½l÷møZø dd¾lùmúZú dd¿lÆmûZû ddÀlÆmüZü eýZþddÁlÿm Z  e eÆjƒ [ ddÂlmZ eÆjøjjZeÆjøjjZddÃlmZm	Z	 ddÄlòm
Z
 ddÅlmZmZmZmZ ddÆlmZ G dÇdÈ„ dÈƒZdØd+d+dÉddd+dÊœee ejejee„ef ee„df eee„ee„ejƒejf f  ejedËœdÌdÍ„ZdÎdÏ„ ZddÐlòmZ ddÑlòmZ eslddÒlòmZ dÓejTv rœddlm2  mZ e ¡  ddlZÆddÔlÆmZ ddÕlm Z  dÖd×„ Z!dS )Ùa  
The torch package contains data structures for multi-dimensional
tensors and defines mathematical operations over these tensors.
Additionally, it provides many utilities for efficient serialization of
Tensors and arbitrary types, and other useful utilities.

It has a CUDA counterpart, that enables you to run your tensor computations
on an NVIDIA GPU with compute capability >= 3.0.
é    N)é   zGPython 2 has reached end-of-life and is no longer supported by PyTorch.é   )Ú_import_dotted_nameÚclassproperty)Úget_file_pathÚ#prepare_multiprocessing_environmentÚUSE_RTLD_GLOBAL_WITH_LIBTORCHÚUSE_GLOBAL_DEPSÚtorch_deployztorch-deploy-1.8)Ú__version__)ÚAnyÚCallableÚDictÚOptionalÚSetÚTypeÚTYPE_CHECKINGÚUnion)=ÚtypenameÚ	is_tensorÚ
is_storageÚset_default_tensor_typeÚset_default_deviceÚset_rng_stateÚget_rng_stateÚmanual_seedÚinitial_seedÚseedÚsaveÚloadÚset_printoptionsÚchunkÚsplitÚstackÚmatmulÚno_gradÚenable_gradZrandZrandnÚinference_modeÚDoubleStorageÚFloatStorageÚLongStorageÚ
IntStorageÚShortStorageÚCharStorageÚByteStorageÚBoolStorageÚTypedStorageÚUntypedStorageZDoubleTensorZFloatTensorZ
LongTensorZ	IntTensorZShortTensorZ
CharTensorZ
ByteTensorZ
BoolTensorÚTensorÚlobpcgÚuse_deterministic_algorithmsÚ$are_deterministic_algorithms_enabledÚ-is_deterministic_algorithms_warn_only_enabledÚset_deterministic_debug_modeÚget_deterministic_debug_modeÚset_float32_matmul_precisionÚget_float32_matmul_precisionÚset_warn_alwaysÚis_warn_always_enabledÚSymIntÚSymFloatÚSymBoolÚsym_notÚsym_intÚ	sym_floatÚsym_maxÚsym_minÚcompileÚvmapÚwin32ZProgramFileszC:\Program FilesÚLibraryÚbinÚlibÚ c                 C   s$   g | ]}t j t j |d ¡¡ ‘qS )znvToolsExt64_1.dll)ÚosÚpathÚexistsÚjoin©Ú.0Úp© rS   úW/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torch/__init__.pyÚ
<listcomp>K   ó    rU   ZNVTOOLSEXT_PATHzNVIDIA CorporationZ
NvToolsExtÚx64)Úcudac                 C   s"   g | ]}t   tj |d ¡¡ ‘qS )zcudart64*.dll)ÚglobrL   rM   rO   rP   rS   rS   rT   rU   S   rV   Ú.Ú_ZCUDA_PATH_VzNVIDIA GPU Computing ToolkitZCUDAÚvzkernel32.dllT)Úuse_last_errorZAddDllDirectoryzvcruntime140.dllzmsvcp140.dllzvcruntime140_1.dllzµMicrosoft Visual C++ Redistributable is not installed, this may lead to the DLL load failure.
                 It can be downloaded at https://aka.ms/vs/16/release/vc_redist.x64.exez*.dllFi   é~   z Error loading "z" or one of its dependencies.ú;ÚPATHc              	   C   sž   t  ¡ dksJ dƒ‚ddl}d}tjD ]P}tj |d¡}tj |¡sFq&| tj || d|¡¡}|rn|sn|d }|r& qxq&|st|› dtj› ƒ‚t	 
|¡ dS )z8Preloads cuda deps if they could not be found otherwise.ÚLinuxzShould only be called on Linuxr   NZnvidiarJ   z not found in the system path )ÚplatformÚsystemrY   ÚsysrM   rL   rO   rN   Ú
ValueErrorÚctypesÚCDLL)Ú
lib_folderÚlib_namerY   Úlib_pathrM   Znvidia_pathZcandidate_lib_pathsrS   rS   rT   Ú_preload_cuda_depsŠ   s    
rk   c                     sú   t jdkst ¡ dkrd S dt ¡ dkr,dnd } tj t¡}tj tj 	|¡d| ¡}zt
j|t
jd W nŠ tyô ‰  zrd	d
ddddddddddœ}‡ fdd„| ¡ D ƒ}|s´ˆ ‚| ¡ D ]\}} t|| ƒ q¼t
j|t
jd W Y d ‰ Š n
d ‰ Š 0 0 d S )Nr
   ÚWindowsZlibtorch_global_depsÚDarwinz.dylibz.sorJ   ©Úmodezlibcublas.so.*[0-9]zlibcudnn.so.*[0-9]zlibnvrtc.so.*[0-9].*[0-9]zlibcudart.so.*[0-9].*[0-9]zlibcupti.so.*[0-9].*[0-9]zlibcufft.so.*[0-9]zlibcurand.so.*[0-9]zlibcusolver.so.*[0-9]zlibcusparse.so.*[0-9]zlibnccl.so.*[0-9]zlibnvToolsExt.so.*[0-9])ZcublasZcudnnZ
cuda_nvrtcZcuda_runtimeZ
cuda_cuptiZcufftZcurandZcusolverZcusparseZncclZnvtxc                    s(   g | ] }|  d ¡d ˆ jd v r|‘qS )rZ   r   )r"   Úargs)rQ   rJ   ©ÚerrrS   rT   rU   ¹   rV   z%_load_global_deps.<locals>.<listcomp>)rd   Ú
executablerb   rc   rL   rM   ÚabspathÚ__file__rO   Údirnamerf   rg   ÚRTLD_GLOBALÚOSErrorÚvaluesÚitemsrk   )ri   Úhererj   Z	cuda_libsZis_cuda_lib_errrh   rS   rq   rT   Ú_load_global_depsŸ   s4    õr|   ZTORCH_USE_RTLD_GLOBALrl   )Ú*c                   @   sš   e Zd ZdZdd„ Zdd„ Zdd„ Zeej	dœd	d
„Z
ej	dœdd„Zej	dœdd„Zej	dœdd„Zej	dœdd„Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r=   zÇ
    Like an int (including magic methods), but redirects all operations on the
    wrapped node. This is used in particular to symbolically record operations
    in the symbolic shape workflow.
    c                 C   s
   || _ d S ©N)Únode)Úselfr   rS   rS   rT   Ú__init__ó   s    zSymInt.__init__c                 C   s
   | j  ¡ S r~   ©r   Zbool_©r€   rS   rS   rT   Ú__bool__ø   s    zSymInt.__bool__c                 C   s
   | j  ¡ S r~   )r   Úint_rƒ   rS   rS   rT   Ú__int__û   s    zSymInt.__int__©ÚotherÚreturnc                 C   s   t dƒ‚d S ©Nztype stub not overridden©ÚAssertionError©r€   rˆ   rS   rS   rT   Ú__eq__   s    zSymInt.__eq__©r‰   c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   Ú__lt__  s    zSymInt.__lt__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   Ú__gt__  s    zSymInt.__gt__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   Ú__le__	  s    zSymInt.__le__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   Ú__ge__  s    zSymInt.__ge__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   Ú__sym_max__  s    zSymInt.__sym_max__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   Ú__sym_min__  s    zSymInt.__sym_min__c                 C   s   t dƒ‚d S rŠ   r‹   rƒ   rS   rS   rT   Ú__sym_float__  s    zSymInt.__sym_float__c                 C   s
   t | jƒS r~   )Ústrr   rƒ   rS   rS   rT   Ú__repr__  s    zSymInt.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r„   r†   ÚobjectÚbuiltinsÚboolrŽ   r   r‘   r’   r“   r”   r•   r–   r˜   rS   rS   rS   rT   r=   ì   s   r=   c                   @   s’   e Zd ZdZdd„ Zdd„ Zeejdœdd„Z	ejd	œd
d„Z
ejd	œdd„Zejd	œdd„Zejd	œdd„Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r>   zÉ
    Like an float (including magic methods), but redirects all operations on the
    wrapped node. This is used in particular to symbolically record operations
    in the symbolic shape workflow.
    c                 C   s$   ddl m} t||ƒsJ ‚|| _d S ©Nr   )ÚSymNode©Ú%torch.fx.experimental.symbolic_shapesr¡   Ú
isinstancer   ©r€   r   r¡   rS   rS   rT   r   "  s    zSymFloat.__init__c                 C   s
   | j  ¡ S r~   r‚   rƒ   rS   rS   rT   r„   )  s    zSymFloat.__bool__r‡   c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   rŽ   .  s    zSymFloat.__eq__r   c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   r   1  s    zSymFloat.__lt__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   r‘   4  s    zSymFloat.__gt__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   r’   7  s    zSymFloat.__le__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   r“   :  s    zSymFloat.__ge__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   r”   =  s    zSymFloat.__sym_max__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   r•   @  s    zSymFloat.__sym_min__c                 C   s   t dƒ‚d S rŠ   r‹   rƒ   rS   rS   rT   Ú__sym_int__C  s    zSymFloat.__sym_int__c                 C   s
   | j  ¡ S r~   ©r   r—   rƒ   rS   rS   rT   r˜   F  s    zSymFloat.__repr__N)r™   rš   r›   rœ   r   r„   r   rž   rŸ   rŽ   r   r‘   r’   r“   r”   r•   r¦   r˜   rS   rS   rS   rT   r>     s   r>   c                   @   sR   e Zd ZdZdd„ Zdd„ Zd dœdd„Zd dœd	d
„Zd dœdd„Zdd„ Z	dS )r?   an  
    Like an bool (including magic methods), but redirects all operations on the
    wrapped node. This is used in particular to symbolically record operations
    in the symbolic shape workflow.

    Unlike regular bools, regular boolean operators will force extra guards instead
    of symbolically evaluate.  Use the bitwise operators instead to handle this.
    c                 C   s$   ddl m} t||ƒsJ ‚|| _d S r    r¢   r¥   rS   rS   rT   r   S  s    zSymBool.__init__c                 C   s
   | j  ¡ S r~   r‚   rƒ   rS   rS   rT   r„   Z  s    zSymBool.__bool__r   c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   Ú__and__^  s    zSymBool.__and__c                 C   s   t dƒ‚d S rŠ   r‹   r   rS   rS   rT   Ú__or__a  s    zSymBool.__or__c                 C   s   t dƒ‚d S rŠ   r‹   rƒ   rS   rS   rT   Ú__sym_not__u  s    zSymBool.__sym_not__c                 C   s
   | j  ¡ S r~   r§   rƒ   rS   rS   rT   r˜   x  s    zSymBool.__repr__N)
r™   rš   r›   rœ   r   r„   r¨   r©   rª   r˜   rS   rS   rS   rT   r?   I  s   	r?   c                 C   s   t | dƒr|  ¡ S |  S )zi SymInt-aware utility for logical negation.

    Args:
        a (SymBool or bool): Object to negate
    rª   )Úhasattrrª   ©ÚarS   rS   rT   r@   {  s    
r@   c                 C   s(   t | tƒr| S t| dƒr |  ¡ S t| ƒS )zp SymInt-aware utility for float casting.

    Args:
        a (SymInt, SymFloat, or object): Object to cast
    r–   )r¤   r>   r«   r–   Úpy_floatr¬   rS   rS   rT   rB   …  s
    

rB   c                 C   s<   t | tƒr| S t | tƒr4| dkr*t | ¡S t | ¡S t| ƒS )zn SymInt-aware utility for int casting.

    Args:
        a (SymInt, SymFloat, or object): Object to cast
    r   )r¤   r=   r>   ÚmathÚfloorÚceilÚpy_intr¬   rS   rS   rT   rA   ’  s
    

rA   c                 C   s<   t | ttfƒr|  |¡S t |ttfƒr0| | ¡S t | |¡S ©z  SymInt-aware utility for max().)r¤   r=   r>   r”   rž   Úmax©r­   ÚbrS   rS   rT   rC   ž  s
    

rC   c                 C   s<   t | ttfƒr|  |¡S t |ttfƒr0| | ¡S t | |¡S r³   )r¤   r=   r>   r•   rž   Úminrµ   rS   rS   rT   rD   ©  s
    

rD   )Ú_initExtensiona’  
            Failed to load PyTorch C extensions:
                It appears that PyTorch has loaded the `torch/_C` folder
                of the PyTorch repository rather than the C extensions which
                are expected in the `torch._C` namespace. This can occur when
                using the `install` workflow. e.g.
                    $ python setup.py install && python -c "import torch"

                This error can generally be solved using the `develop` workflow
                    $ python setup.py develop && python -c "import torch"  # This should succeed
                or by running Python from a different directory.
            ZBaseÚtorch)ZDisableTorchFunctionSubclassZDisableTorchFunctionÚ	Generatorz	torch._C.c                 C   s‚   t | tjƒr|  ¡ S d}d}t| dƒrN| jdkrN| jdkrN| jd urN| jd }t| dƒr`| j}nt| dƒrr| j}n| jj}|| S )NrK   rš   rž   Ú__builtin__rZ   r›   r™   )	r¤   r¹   r2   Útyper«   rš   r›   r™   Ú	__class__)ÚoÚmoduleÚ
class_namerS   rS   rT   r   å  s     ÿÿ


r   c                 C   s   t | tjƒS )a­  Returns True if `obj` is a PyTorch tensor.

    Note that this function is simply doing ``isinstance(obj, Tensor)``.
    Using that ``isinstance`` check is better for typechecking with mypy,
    and more explicit - so it's recommended to use that instead of
    ``is_tensor``.

    Args:
        obj (Object): Object to test
    Example::

        >>> x = torch.tensor([1, 2, 3])
        >>> torch.is_tensor(x)
        True

    )r¤   r¹   r2   ©ÚobjrS   rS   rT   r   ù  s    r   c                 C   s   t | ƒtv S )zgReturns True if `obj` is a PyTorch storage object.

    Args:
        obj (Object): Object to test
    )r¼   Ú_storage_classesrÁ   rS   rS   rT   r     s    r   c                 C   sF   t durt  ddd¡ | du r&da dS ddlm} || ƒa t  ¡  dS )a®  Sets the default ``torch.Tensor`` to be allocated on ``device``.  This
    does not affect factory function calls which are called with an explicit
    ``device`` argument.  Factory calls will be performed as if they
    were passed ``device`` as an argument.

    To only temporarily change the default device instead of setting it
    globally, use ``with torch.device(device):`` instead.

    The default device is initially ``cpu``.  If you set the default tensor
    device to another device (e.g., ``cuda``) without a device index, tensors
    will be allocated on whatever the current device for the device type,
    even after :func:`torch.cuda.set_device` is called.

    .. warning::

        This function imposes a slight performance cost on every Python
        call to the torch API (not just factory functions).  If this
        is causing problems for you, please comment on
        https://github.com/pytorch/pytorch/issues/92701

    Args:
        device (device or string): the device to set as default

    Example::

        >>> # xdoctest: +SKIP("requires cuda, changes global state")
        >>> torch.tensor([1.2, 3]).device
        device(type='cpu')
        >>> torch.set_default_device('cuda')  # current device is 0
        >>> torch.tensor([1.2, 3]).device
        device(type='cuda', index=0)
        >>> torch.set_default_device('cuda:1')
        >>> torch.tensor([1.2, 3]).device
        device(type='cuda', index=1)

    Nr   )ÚDeviceContext)Ú_GLOBAL_DEVICE_CONTEXTÚ__exit__Ztorch.utils._devicerÄ   Ú	__enter__)ÚdevicerÄ   rS   rS   rT   r     s    &r   c                 C   s    t | tƒrt| ƒ} t | ¡ dS )aé  Sets the default ``torch.Tensor`` type to floating point tensor type
    ``t``. This type will also be used as default floating point type for
    type inference in :func:`torch.tensor`.

    The default floating point tensor type is initially ``torch.FloatTensor``.

    Args:
        t (type or string): the floating point tensor type or its name

    Example::

        >>> # xdoctest: +SKIP("Other tests may have changed the default type. Can we reset it?")
        >>> torch.tensor([1.2, 3]).dtype    # initial default for floating point is torch.float32
        torch.float32
        >>> torch.set_default_tensor_type(torch.DoubleTensor)
        >>> torch.tensor([1.2, 3]).dtype    # a new floating point tensor
        torch.float64

    N)r¤   r—   r   Ú_CZ_set_default_tensor_type)ÚtrS   rS   rT   r   H  s    
r   c                 C   s   t  | ¡ dS )aË  

    Sets the default floating point dtype to :attr:`d`. Supports torch.float32
    and torch.float64 as inputs. Other dtypes may be accepted without complaint
    but are not supported and are unlikely to work as expected.

    When PyTorch is initialized its default floating point dtype is torch.float32,
    and the intent of set_default_dtype(torch.float64) is to facilitate NumPy-like
    type inference. The default floating point dtype is used to:

    1. Implicitly determine the default complex dtype. When the default floating point
       type is float32 the default complex dtype is complex64, and when the default
       floating point type is float64 the default complex type is complex128.
    2. Infer the dtype for tensors constructed using Python floats or complex Python
       numbers. See examples below.
    3. Determine the result of type promotion between bool and integer tensors and
       Python floats and complex Python numbers.

    Args:
        d (:class:`torch.dtype`): the floating point dtype to make the default.
                                  Either torch.float32 or torch.float64.

    Example:
        >>> # xdoctest: +SKIP("Other tests may have changed the default type. Can we reset it?")
        >>> # initial default for floating point is torch.float32
        >>> # Python floats are interpreted as float32
        >>> torch.tensor([1.2, 3]).dtype
        torch.float32
        >>> # initial default for floating point is torch.complex64
        >>> # Complex Python numbers are interpreted as complex64
        >>> torch.tensor([1.2, 3j]).dtype
        torch.complex64

        >>> torch.set_default_dtype(torch.float64)

        >>> # Python floats are now interpreted as float64
        >>> torch.tensor([1.2, 3]).dtype    # a new floating point tensor
        torch.float64
        >>> # Complex Python numbers are now interpreted as complex128
        >>> torch.tensor([1.2, 3j]).dtype   # a new complex tensor
        torch.complex128

    N)rÉ   Z_set_default_dtype)ÚdrS   rS   rT   Úset_default_dtypea  s    ,rÌ   ©Ú	warn_onlyc                C   s   t j| |d dS )as   Sets whether PyTorch operations must use "deterministic"
    algorithms. That is, algorithms which, given the same input, and when
    run on the same software and hardware, always produce the same output.
    When enabled, operations will use deterministic algorithms when available,
    and if only nondeterministic algorithms are available they will throw a
    :class:`RuntimeError` when called.

    .. note:: This setting alone is not always enough to make an application
        reproducible. Refer to :ref:`reproducibility` for more information.

    .. note:: :func:`torch.set_deterministic_debug_mode` offers an alternative
        interface for this feature.

    The following normally-nondeterministic operations will act
    deterministically when ``mode=True``:

        * :class:`torch.nn.Conv1d` when called on CUDA tensor
        * :class:`torch.nn.Conv2d` when called on CUDA tensor
        * :class:`torch.nn.Conv3d` when called on CUDA tensor
        * :class:`torch.nn.ConvTranspose1d` when called on CUDA tensor
        * :class:`torch.nn.ConvTranspose2d` when called on CUDA tensor
        * :class:`torch.nn.ConvTranspose3d` when called on CUDA tensor
        * :func:`torch.bmm` when called on sparse-dense CUDA tensors
        * :func:`torch.Tensor.__getitem__` when attempting to differentiate a CPU tensor
          and the index is a list of tensors
        * :func:`torch.Tensor.index_put` with ``accumulate=False``
        * :func:`torch.Tensor.index_put` with ``accumulate=True`` when called on a CPU
          tensor
        * :func:`torch.Tensor.put_` with ``accumulate=True`` when called on a CPU
          tensor
        * :func:`torch.Tensor.scatter_add_` when called on a CUDA tensor
        * :func:`torch.gather` when called on a CUDA tensor that requires grad
        * :func:`torch.index_add` when called on CUDA tensor
        * :func:`torch.index_select` when attempting to differentiate a CUDA tensor
        * :func:`torch.repeat_interleave` when attempting to differentiate a CUDA tensor
        * :func:`torch.Tensor.index_copy` when called on a CPU or CUDA tensor

    The following normally-nondeterministic operations will throw a
    :class:`RuntimeError` when ``mode=True``:

        * :class:`torch.nn.AvgPool3d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.AdaptiveAvgPool2d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.AdaptiveAvgPool3d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.MaxPool3d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.AdaptiveMaxPool2d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.FractionalMaxPool2d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.FractionalMaxPool3d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.MaxUnpool1d`
        * :class:`torch.nn.MaxUnpool2d`
        * :class:`torch.nn.MaxUnpool3d`
        * :func:`torch.nn.functional.interpolate` when attempting to differentiate a CUDA tensor
          and one of the following modes is used:

          - ``linear``
          - ``bilinear``
          - ``bicubic``
          - ``trilinear``

        * :class:`torch.nn.ReflectionPad1d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.ReflectionPad2d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.ReflectionPad3d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.ReplicationPad1d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.ReplicationPad2d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.ReplicationPad3d` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.NLLLoss` when called on a CUDA tensor
        * :class:`torch.nn.CTCLoss` when attempting to differentiate a CUDA tensor
        * :class:`torch.nn.EmbeddingBag` when attempting to differentiate a CUDA tensor when
          ``mode='max'``
        * :func:`torch.Tensor.put_` when ``accumulate=False``
        * :func:`torch.Tensor.put_` when ``accumulate=True`` and called on a CUDA tensor
        * :func:`torch.histc` when called on a CUDA tensor
        * :func:`torch.bincount` when called on a CUDA tensor
        * :func:`torch.kthvalue` with called on a CUDA tensor
        * :func:`torch.median` with indices output when called on a CUDA tensor
        * :func:`torch.nn.functional.grid_sample` when attempting to differentiate a CUDA tensor
        * :func:`torch.cumsum` when called on a CUDA tensor when dtype is floating point or complex

    A handful of CUDA operations are nondeterministic if the CUDA version is
    10.2 or greater, unless the environment variable ``CUBLAS_WORKSPACE_CONFIG=:4096:8``
    or ``CUBLAS_WORKSPACE_CONFIG=:16:8`` is set. See the CUDA documentation for more
    details: `<https://docs.nvidia.com/cuda/cublas/index.html#cublasApi_reproducibility>`_
    If one of these environment variable configurations is not set, a :class:`RuntimeError`
    will be raised from these operations when called with CUDA tensors:

        * :func:`torch.mm`
        * :func:`torch.mv`
        * :func:`torch.bmm`

    Note that deterministic operations tend to have worse performance than
    nondeterministic operations.

    .. note::

        This flag does not detect or prevent nondeterministic behavior caused
        by calling an inplace operation on a tensor with an internal memory
        overlap or by giving such a tensor as the :attr:`out` argument for an
        operation. In these cases, multiple writes of different data may target
        a single memory location, and the order of writes is not guaranteed.

    Args:
        mode (:class:`bool`): If True, makes potentially nondeterministic
            operations switch to a deterministic algorithm or throw a runtime
            error. If False, allows nondeterministic operations.

    Keyword args:
        warn_only (:class:`bool`, optional): If True, operations that do not
            have a deterministic implementation will throw a warning instead of
            an error. Default: ``False``

    Example::

        >>> # xdoctest: +SKIP
        >>> torch.use_deterministic_algorithms(True)

        # Forward mode nondeterministic error
        >>> torch.randn(10, device='cuda').kthvalue(0)
        ...
        RuntimeError: kthvalue CUDA does not have a deterministic implementation...

        # Backward mode nondeterministic error
        >>> torch.nn.AvgPool3d(1)(torch.randn(3, 4, 5, 6, requires_grad=True).cuda()).sum().backward()
        ...
        RuntimeError: avg_pool3d_backward_cuda does not have a deterministic implementation...
    rÍ   N)rÉ   Ú_set_deterministic_algorithms)ro   rÎ   rS   rS   rT   r4     s    }r4   c                   C   s   t  ¡ S )z˜Returns True if the global deterministic flag is turned on. Refer to
    :func:`torch.use_deterministic_algorithms` documentation for more details.
    )rÉ   Ú_get_deterministic_algorithmsrS   rS   rS   rT   r5     s    r5   c                   C   s   t  ¡ S )z£Returns True if the global deterministic flag is set to warn only.
    Refer to :func:`torch.use_deterministic_algorithms` documentation for more
    details.
    )rÉ   Ú'_get_deterministic_algorithms_warn_onlyrS   rS   rS   rT   r6     s    r6   )Ú
debug_moder‰   c                 C   s¶   t | tjtfƒs"tdt| ƒ› ƒ‚t | tƒrd| dkr:d} n*| dkrHd} n| dkrVd} ntd| › ƒ‚| dkrxt d	¡ n:| dkrtjd
d
d n"| dkr¤t d
¡ ntd| › ƒ‚dS )aö  Sets the debug mode for deterministic operations.

    .. note:: This is an alternative interface for
        :func:`torch.use_deterministic_algorithms`. Refer to that function's
        documentation for details about affected operations.

    Args:
        debug_mode(str or int): If "default" or 0, don't error or warn on
            nondeterministic operations. If "warn" or 1, warn on
            nondeterministic operations. If "error" or 2, error on
            nondeterministic operations.
    z'debug_mode must be str or int, but got Údefaultr   Úwarnr   Úerroré   zQinvalid value of debug_mode, expected one of `default`, `warn`, `error`, but got FTrÍ   z:invalid value of debug_mode, expected 0, 1, or 2, but got N)	r¤   rž   Úintr—   Ú	TypeErrorr¼   ÚRuntimeErrorrÉ   rÏ   )rÒ   rS   rS   rT   r7     s2    
ÿÿÿÿr7   r   c                   C   s"   t  ¡ rt  ¡ rdS dS ndS dS )zªReturns the current value of the debug mode for deterministic
    operations. Refer to :func:`torch.set_deterministic_debug_mode`
    documentation for more details.
    r   rÖ   r   N)rÉ   rÐ   rÑ   rS   rS   rS   rT   r8   E  s
    r8   c                   C   s   t  ¡ S )z¢Returns the current value of float32 matrix multiplication precision. Refer to
    :func:`torch.set_float32_matmul_precision` documentation for more details.
    )rÉ   Z_get_float32_matmul_precisionrS   rS   rS   rT   r:   S  s    r:   c                 C   s   t  | ¡ dS )aÛ  Sets the internal precision of float32 matrix multiplications.

    Running float32 matrix multiplications in lower precision may significantly increase
    performance, and in some programs the loss of precision has a negligible impact.

    Supports three settings:

        * "highest", float32 matrix multiplications use the float32 datatype for
          internal computations.
        * "high", float32 matrix multiplications use the TensorFloat32 or bfloat16_3x
          datatypes for internal computations, if fast matrix multiplication algorithms
          using those datatypes internally are available. Otherwise float32
          matrix multiplications are computed as if the precision is "highest".
        * "medium", float32 matrix multiplications use the bfloat16 datatype for
          internal computations, if a fast matrix multiplication algorithm
          using that datatype internally is available. Otherwise float32
          matrix multiplications are computed as if the precision is "high".

    .. note::

        This does not change the output dtype of float32 matrix multiplications,
        it controls how the internal computation of the matrix multiplication is performed.

    .. note::

        This does not change the precision of convolution operations. Other flags,
        like `torch.backends.cudnn.allow_tf32`, may control the precision of convolution
        operations.

    .. note::

        This flag currently only affects one native device type: CUDA.
        If "high" or "medium" are set then the TensorFloat32 datatype will be used
        when computing float32 matrix multiplications, equivalent to setting
        `torch.backends.cuda.matmul.allow_tf32 = True`. When "highest" (the default)
        is set then the float32 datatype is used for internal computations, equivalent
        to setting `torch.backends.cuda.matmul.allow_tf32 = False`.

    Args:
        precision(str): can be set to "highest" (default), "high", or "medium" (see above).

    N)rÉ   Z_set_float32_matmul_precision)Z	precisionrS   rS   rT   r9   Y  s    +r9   c                 C   s   t  | ¡ dS )a”  When this flag is False (default) then some PyTorch warnings may only
    appear once per process. This helps avoid excessive warning information.
    Setting it to True causes these warnings to always appear, which may be
    helpful when debugging.

    Args:
        b (:class:`bool`): If True, force warnings to always be emitted
                           If False, set to the default behaviour
    N)rÉ   Z_set_warnAlways)r¶   rS   rS   rT   r;   †  s    
r;   c                   C   s   t  ¡ S )z‰Returns True if the global warn_always flag is turned on. Refer to
    :func:`torch.set_warn_always` documentation for more details.
    )rÉ   Z_get_warnAlwaysrS   rS   rS   rT   r<   ’  s    r<   )ÚeÚnanÚinfÚpi)rÚ   rÝ   rÛ   rÜ   )r2   )Ú_StorageBaser0   Ú_LegacyStorager1   Ú_warn_typed_storage_removalc                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )r.   c                 C   s   t ƒ  | jS r~   ©rà   Ú_dtyperƒ   rS   rS   rT   Údtype¬  s    zByteStorage.dtypec                 C   s   t jS r~   )r¹   Zuint8rƒ   rS   rS   rT   râ   ±  s    zByteStorage._dtypeN©r™   rš   r›   r   rã   râ   rS   rS   rS   rT   r.   «  s   
r.   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )r(   c                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   ¶  s    zDoubleStorage.dtypec                 C   s   t jS r~   )r¹   Údoublerƒ   rS   rS   rT   râ   »  s    zDoubleStorage._dtypeNrä   rS   rS   rS   rT   r(   µ  s   
r(   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )r)   c                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   À  s    zFloatStorage.dtypec                 C   s   t jS r~   )r¹   Úfloatrƒ   rS   rS   rT   râ   Å  s    zFloatStorage._dtypeNrä   rS   rS   rS   rT   r)   ¿  s   
r)   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚHalfStoragec                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   Ê  s    zHalfStorage.dtypec                 C   s   t jS r~   )r¹   Zhalfrƒ   rS   rS   rT   râ   Ï  s    zHalfStorage._dtypeNrä   rS   rS   rS   rT   rç   É  s   
rç   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )r*   c                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   Ô  s    zLongStorage.dtypec                 C   s   t jS r~   )r¹   Úlongrƒ   rS   rS   rT   râ   Ù  s    zLongStorage._dtypeNrä   rS   rS   rS   rT   r*   Ó  s   
r*   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )r+   c                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   Þ  s    zIntStorage.dtypec                 C   s   t jS r~   )r¹   r×   rƒ   rS   rS   rT   râ   ã  s    zIntStorage._dtypeNrä   rS   rS   rS   rT   r+   Ý  s   
r+   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )r,   c                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   è  s    zShortStorage.dtypec                 C   s   t jS r~   )r¹   Úshortrƒ   rS   rS   rT   râ   í  s    zShortStorage._dtypeNrä   rS   rS   rS   rT   r,   ç  s   
r,   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )r-   c                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   ò  s    zCharStorage.dtypec                 C   s   t jS r~   )r¹   Zint8rƒ   rS   rS   rT   râ   ÷  s    zCharStorage._dtypeNrä   rS   rS   rS   rT   r-   ñ  s   
r-   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )r/   c                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   ü  s    zBoolStorage.dtypec                 C   s   t jS r~   )r¹   rŸ   rƒ   rS   rS   rT   râ     s    zBoolStorage._dtypeNrä   rS   rS   rS   rT   r/   û  s   
r/   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚBFloat16Storagec                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã     s    zBFloat16Storage.dtypec                 C   s   t jS r~   )r¹   Zbfloat16rƒ   rS   rS   rT   râ     s    zBFloat16Storage._dtypeNrä   rS   rS   rS   rT   rê     s   
rê   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚComplexDoubleStoragec                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã     s    zComplexDoubleStorage.dtypec                 C   s   t jS r~   )r¹   Zcdoublerƒ   rS   rS   rT   râ     s    zComplexDoubleStorage._dtypeNrä   rS   rS   rS   rT   rë     s   
rë   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚComplexFloatStoragec                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã     s    zComplexFloatStorage.dtypec                 C   s   t jS r~   )r¹   Zcfloatrƒ   rS   rS   rT   râ     s    zComplexFloatStorage._dtypeNrä   rS   rS   rS   rT   rì     s   
rì   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚQUInt8Storagec                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   $  s    zQUInt8Storage.dtypec                 C   s   t jS r~   )r¹   Zquint8rƒ   rS   rS   rT   râ   )  s    zQUInt8Storage._dtypeNrä   rS   rS   rS   rT   rí   #  s   
rí   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚQInt8Storagec                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   .  s    zQInt8Storage.dtypec                 C   s   t jS r~   )r¹   Zqint8rƒ   rS   rS   rT   râ   3  s    zQInt8Storage._dtypeNrä   rS   rS   rS   rT   rî   -  s   
rî   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚQInt32Storagec                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   8  s    zQInt32Storage.dtypec                 C   s   t jS r~   )r¹   Zqint32rƒ   rS   rS   rT   râ   =  s    zQInt32Storage._dtypeNrä   rS   rS   rS   rT   rï   7  s   
rï   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚQUInt4x2Storagec                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   B  s    zQUInt4x2Storage.dtypec                 C   s   t jS r~   )r¹   Zquint4x2rƒ   rS   rS   rT   râ   G  s    zQUInt4x2Storage._dtypeNrä   rS   rS   rS   rT   rð   A  s   
rð   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚQUInt2x4Storagec                 C   s   t ƒ  | jS r~   rá   rƒ   rS   rS   rT   rã   L  s    zQUInt2x4Storage.dtypec                 C   s   t jS r~   )r¹   Zquint2x4rƒ   rS   rS   rT   râ   Q  s    zQUInt2x4Storage._dtypeNrä   rS   rS   rS   rT   rñ   K  s   
rñ   Ú_tensor_classes)r   r   r   r   r   )r   r   )r    c                  C   sT   t jdkst ¡ dkrdS tdddƒ} ttdƒƒ tj | ¡sJt	d|  ƒ‚|  
d¡S )	Nr
   rl   rV   r¹   rI   Ztorch_shm_managerz$Unable to find torch_shm_manager at zutf-8)rd   rs   rb   rc   r   r   rL   rM   rN   rÙ   Úencode)rM   rS   rS   rT   Úmanager_pathi  s    rô   )Úautocast)Z
unique_dimÚ__Úsegment_reducec                 C   sH   ddl m}m} t| ƒtjur8|| fƒr8|t| f| |ƒS | sDJ |ƒ‚dS )zFA wrapper around Python's assert which is symbolically traceable.
    r   )Úhas_torch_functionÚhandle_torch_functionN)Z	overridesrø   rù   r¼   r¹   r2   Ú_assert)Ú	conditionÚmessagerø   rù   rS   rS   rT   rú   ²  s    rú   )Úcpu)Úautograd)r%   r&   Úset_grad_enabledr'   )Úfft)Úfutures)Ú_awaits)Únested)Únn)Úwindows)Úoptim)Úmultiprocessing)Úsparse)Úspecial)Úonnx)Újit)Úlinalg)Úhub)Úrandom)Údistributions)Útesting)Ú
__config__)Ú
__future__)Úprofiler)Úao)Ú_torch_docsÚ_tensor_docsÚ_storage_docsc                   C   s   t jS )z?Returns whether PyTorch was built with _GLIBCXX_USE_CXX11_ABI=1)rÉ   Z_GLIBCXX_USE_CXX11_ABIrS   rS   rS   rT   Úcompiled_with_cxx11_abiú  s    r  )Úops)Úclasses)Úquantization)Úquasirandom)Úregister_after_fork)r3   )Úfrom_dlpackÚ	to_dlpack)Úmasked)Úmatrix_rankÚeigÚsolveÚlstsq)Ú_symeigc                   @   sT   e Zd ZdZdd„ Zdd„ Zee dœdd„Zee	ee
f  d	œd
d„Zdd„ ZdS )Ú_TorchCompileInductorWrapperÚinductorc                 C   sH   t ƒ | _|| _|  |¡ |  |¡ |rDd| jd< d|p8dvsDJ dƒ‚d S )NFútriton.cudagraphsrS   z1triton.cudagraphs does not support dynamic shapes)ÚdictÚconfigÚdynamicÚ
apply_modeÚapply_options)r€   ro   Úoptionsr+  rS   rS   rT   r   2  s    


ÿþz%_TorchCompileInductorWrapper.__init__c                 C   s"   t |tƒo | j|jko | j|jkS r~   )r¤   r&  r*  r+  r   rS   rS   rT   rŽ   >  s
    

ÿ
þz#_TorchCompileInductorWrapper.__eq__rn   c                 C   s\   |d u sX|dkrnF|dkr,|   dddœ¡ n,|dkrH|   ddddœ¡ ntd|› d	ƒ‚d S )
NrÓ   zreduce-overheadTF)r(  Zsize_assertszmax-autotune)Zepilogue_fusionZmax_autotuner(  zUnrecognized mode=z:, should be one of: default, reduce-overhead, max-autotune)r-  rÙ   )r€   ro   rS   rS   rT   r,  C  s     þ
ý

ÿz'_TorchCompileInductorWrapper.apply_mode)r.  c           	      C   s²   |sd S ddl m} | ¡ }| ¡ D ]ˆ\}}| dd¡}||vr\td|› dt| ¡ ƒ› ƒ‚t|ƒt|| ƒur¢t|ƒj	}t|| ƒj	}td|› d|› d	|› ƒ‚|| j|< q$d S )
Nr   )r*  ú-r[   zUnexpected optimization option z, known options are zUnexpected type of attr z, got z should be )
Ztorch._inductorr*  Úto_dictrz   ÚreplacerÙ   ÚlistÚkeysr¼   r™   )	r€   r.  r*  Zcurrent_configÚkeyÚvalÚ	attr_nameZval_type_strZexpected_type_strrS   rS   rT   r-  V  s"    ÿ
ÿz*_TorchCompileInductorWrapper.apply_optionsc                 C   s   ddl m} |||| jdS )Nr   )Ú
compile_fx)Zconfig_patches)Ztorch._inductor.compile_fxr7  r*  )r€   Zmodel_Zinputs_r7  rS   rS   rT   Ú__call__k  s    z%_TorchCompileInductorWrapper.__call__N)r™   rš   r›   Zcompiler_namer   rŽ   r   r—   r,  r   r   r-  r8  rS   rS   rS   rT   r&  /  s   r&  r'  ©Ú	fullgraphr+  Úbackendro   r.  Údisable)Úmodelr:  r+  r;  ro   r.  r<  r‰   c          	         s’   t  d¡ | du r2tdœ‡ ‡‡‡‡‡fdd„}|S ddl}ˆdurRˆdurRtdƒ‚ˆdu rfˆdu rfd‰ˆ d	krztˆˆˆƒ‰ |jjˆ ˆˆˆd
| ƒS )aÀ  
    Optimizes given model/function using TorchDynamo and specified backend.

    Args:
       model (Callable): Module/function to optimize
       fullgraph (bool): Whether it is ok to break model into several subgraphs
       dynamic (bool): Use dynamic shape tracing
       backend (str or Callable): backend to be used
       mode (str): Can be either "default", "reduce-overhead" or "max-autotune"
       options (dict): A dictionary of options to pass to the backend.
       disable (bool): Turn torch.compile() into a no-op for testing

    Example::

        @torch.compile(options={"matmul-padding": True}, fullgraph=True)
        def foo(x):
            return torch.sin(x) + torch.cos(x)

    ztorch.compileN©r=  c              	      s&   | d u rt dƒ‚t| ˆˆˆ ˆˆˆdS )NzModel can't be Noner9  )rÙ   rE   r>  ©r;  r<  r+  r:  ro   r.  rS   rT   ÚfnŽ  s    úzcompile.<locals>.fnr   zVEither mode or options can be specified, but both can't be specified at the same time.rÓ   r'  )r;  Znopythonr+  r<  )rÉ   Z_log_api_usage_oncer   Ztorch._dynamorÙ   r&  Z_dynamoÚoptimize)	r=  r:  r+  r;  ro   r.  r<  r@  r¹   rS   r?  rT   rE   q  s    

rE   c                 C   s^   t  | ¡j} tjt }t|| ƒr6td | t	|| ƒ¡ƒ‚t
|| |ƒ d t| g¡}|tj|< dS )zùRegister an external runtime module of the specific :attr:`device_type`
    supported by torch.

    After the :attr:`module` is registered correctly, the user can refer
    the external runtime module as part of torch with attribute torch.xxx.
    z@The runtime module of '{}' has already been registered with '{}'rZ   N)r¹   rÈ   r¼   rd   Úmodulesr™   r«   rÙ   ÚformatÚgetattrÚsetattrrO   )Zdevice_typer¿   ÚmZtorch_module_namerS   rS   rT   Ú_register_device_module¤  s    


ÿrG  )Úreturn_types)Úlibrary)Ú_meta_registrationsZTORCH_CUDA_SANITIZER)Úfunc)rF   c                  O   s*   dd l }| d¡ d|d< tj| i |¤ŽS )Nr   zptorch._sparse_coo_tensor_unsafe is deprecated, use torch.sparse_coo_tensor(..., check_invariants=False) instead.FZcheck_invariants)ÚwarningsrÔ   r¹   Zsparse_coo_tensor)rp   ÚkwargsrL  rS   rS   rT   Ú_sparse_coo_tensor_unsafeË  s    
rN  )N("  rœ   r¯   rL   rd   rb   Útextwraprf   ÚinspectÚversion_infoÚ	ExceptionÚ_utilsr   r   Z_utils_internalr   r   r   r	   rs   r   Ztorch_versionÚtypingr   r   r   r   r   r   r   r   rž   Ú__all__ÚgetenvZpfiles_pathrM   rO   Úexec_prefixZpy_dll_pathrv   ru   Zth_dll_pathÚbase_exec_prefixZbase_py_dll_pathr2  ÚfilterrN   Z	dll_pathsÚallZnvtoolsext_dll_pathÚversionrX   Zcuda_versionrY   r1  Zcuda_version_1Zcuda_path_varZdefault_pathZ	cuda_pathÚextendZWinDLLÚkernel32r«   Zwith_load_library_flagsZSetErrorModeZprev_error_modeÚc_void_pZLoadLibraryWÚrestypeZLoadLibraryExWZdll_pathZadd_dll_directoryrg   rx   ÚprintZdllsZpath_patchedÚdllZ	is_loadedÚresZget_last_errorZ
last_errorZWinErrorrr   ÚstrerrorÚenvironrk   r|   rc   ÚgetdlopenflagsZ	old_flagsÚsetdlopenflagsrw   Ú	RTLD_LAZYZtorch._CrÉ   r=   r>   r?   r@   rB   rA   rC   rD   r¸   ÚImportErrorZ_C_for_compiled_checkÚdedentÚstripÚdirÚnameÚendswithÚappendrD  rÂ   r¤   Úisclassrš   ÚattrÚ	candidater¼   rB  r   r   r   rÅ   r   r   rÌ   r4   r5   r6   r×   r—   r7   r8   r:   r9   r;   r<   rÚ   rÛ   rÜ   rÝ   Z_tensorr2   ZstoragerÞ   r0   rß   r1   rà   r.   r(   r)   rç   r*   r+   r,   r-   r/   rê   rë   rì   rí   rî   rï   rð   rñ   rÃ   Úsetrò   Ú__annotations__r  r   r   r   r   r   Zserializationr   r   Z_tensor_strr    rô   Z	torch.amprõ   ræ   r®   r²   Ztorch._C._VariableFunctionsr÷   Z_segment_reduceZPRIVATE_OPSZ_VariableFunctionsÚ
startswithÚglobalsZ
functionalrú   r¹   rý   rþ   Ztorch.autogradr%   r&   rÿ   r'   r   r  r  r  r  Ztorch.signalr  r  Ztorch.optim._multi_tensorr  r  r	  Ztorch.utils.backcompatr
  r  r  r  r  r  Ztorch.backends.cudaZtorch.backends.mpsZtorch.backends.cudnnZtorch.backends.mklZtorch.backends.mkldnnZtorch.backends.openmpZtorch.backends.quantizedZtorch.utils.datar  r  r  r  Ztorch.nn.quantizableZtorch.nn.quantizedZtorch.nn.qatZtorch.nn.intrinsicZ_init_namesrK   r  r  r  r  Z
torch._opsr  Ztorch._classesr  r  r  Zcontiguous_formatZlegacy_contiguous_formatZtorch.multiprocessing._atforkr  Zget_num_threadsZ_lobpcgr3   ZatenZquantized_lstmZquantized_gruZtorch.utils.dlpackr  r  r   Z_linalg_utilsr!  r"  r#  r$  r%  Zsymeigr&  rŸ   rE   rG  rH  rI  rJ  Ztorch.cuda._sanitizerZ
_sanitizerZcsanZenable_cuda_sanitizerr£   rK  Z
torch.funcrF   rN  rS   rS   rS   rT   Ú<module>   s6  


(ÿ










"ÿ
ÿ
/.2

õ




	0.*-

















û		


*Bú


ú3

