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 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CompositeImplicitAutogradc                 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   N/var/www/html/ai/venv/lib/python3.10/site-packages/torch/_python_dispatcher.py__init__H   s   zPythonDispatcher.__init__c                 C   s   | j S N)supported_keysr   r   r   r   keysR   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_linev   s   zPythonDispatcher._format_linec                 C   s(   d| d}||  dd7 }|d7 }|S )Nr-   r*   r.   z---------------------------
)r/   )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   r3   r4   )r   _dispatch_dump_tabler   r   r   r   r   r   rawDispatchTable   r8   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>r5   r,      )r2   r7   splitanyr   r/   )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: rB   )r2   r:   rC   recompileruntime_keyssubr/   )r   rE   tabletable_entriesregexrH   r>   entryr   r   r   dispatchTable   s   



zPythonDispatcher.dispatchTableN)__name__
__module____qualname__r   r   rM   
alias_keysr   r   r    r+   r/   r2   r7   r:   rI   rS   r   r   r   r   r   6   s.    r   )rK   torch._C_Cr   r   r   r   r   r   <module>   s    0