o
    h                     @   s(   d dl Z d dlmZ 	 G dd dZdS )    Nc                   @   s   e Zd ZdZdZg dZg dZee ZdddZ	 d	d
 Z		 dd Z
	 dd Z	 dd Z	 dd Z	 dd Z	 dd Z	 dd ZdS )PythonDispatcher__test__foo)CPUAutogradCPUFPGAAutogradOtherXLAAutogradXLALazyAutogradLazy)CompositeExplicitAutogradAutogradCompositeImplicitAutogradreturnNc                 C   s.   t | j t d| jd| _| jd d S )NFRAGMENT zfoo(Tensor x) -> Tensor)C_dispatch_check_invariantsname_dispatch_library	namespacerefdef_self r   l/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/_python_dispatcher.py__init__I   s   zPythonDispatcher.__init__c                 C   s   | j S N)supported_keysr   r   r   r   keysS   s   zPythonDispatcher.keysc                 C   s   t t|t |krtd| dd|v rd|v rtd|D ]}|| jvr2t| d| j d| jjd|d| d	 q d S )
Nz1Overriden is not allowed but found duplicates in .r   r   z\Registration to both CompositeImplicitAutograd and CompositeExplicitAutograd is not allowed.z3 is not supported, please select a dispatch key in r   fn_)dispatchdebug)lensetRuntimeErrorr    r   impl_t_t)r   dispatchKeyskeyr   r   r   register^   s    

zPythonDispatcher.registerc                 C   s   |dd| dS )Nz<15 
r   )r   r+   kernelr   r   r   _format_linew   s   zPythonDispatcher._format_linec                 C   s(   d| d}||  dd7 }|d7 }|S )Nr.   r+   r/   z---------------------------
)r0   )r   headersr   r   r   _format_header~   s   zPythonDispatcher._format_headerc                 C      t | j d| j S N::)r   _dispatch_dumpr   r   r   r   r   r   rawRegistrations      z!PythonDispatcher.rawRegistrationsc                 C   r4   r5   )r   _dispatch_dump_tabler   r   r   r   r   r   rawDispatchTable   r9   z!PythonDispatcher.rawDispatchTablec                    sx   |  d}|  }|d}|D ])}|dd  t fdd| jD r9|dd dd	 }||  |7 }q|S )
NzRegistered Kernelsr.   :r   c                 3   s    | ]}  |V  qd S r   )
startswith).0kfirstr   r   	<genexpr>   s    z1PythonDispatcher.registrations.<locals>.<genexpr>r6   r-      )r3   r8   splitanyr    r0   )r   outputstatestate_entriesliner/   r   r@   r   registrations   s   

zPythonDispatcher.registrationsc                 C   sr   |  d}|  }|d}td}|D ]!}|dd }|| jv r6|d|}|| ||dd 7 }q|S )	NzComputed Dispatch Tabler.   z)registered at .*FallbackKernel\.cpp.*(\[)r<   r   [z: rC   )r3   r;   rD   recompileruntime_keyssubr0   )r   rF   tabletable_entriesregexrI   r?   entryr   r   r   dispatchTable   s   



zPythonDispatcher.dispatchTable)r   N)__name__
__module____qualname__r   r   rN   
alias_keysr    r   r!   r,   r0   r3   r8   r;   rJ   rT   r   r   r   r   r   7   s.    
r   )rL   torch._C_Cr   r   r   r   r   r   <module>   s   0