U
    9%e                     @   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ddddddd	d
gZdddg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 )!PythonDispatcherZ__test__fooZCPUZAutogradCPUZFPGAZAutogradOtherZXLAZAutogradXLAZLazyZAutogradLazyCompositeExplicitAutogradZAutogradCompositeImplicitAutogradc                 C   s.   t | j t d| jd| _| jd d S )NZFRAGMENT zfoo(Tensor x) -> Tensor)CZ_dispatch_check_invariantsnameZ_dispatch_library	namespacerefZdef_self r   W/var/www/html/Darija-Ai-API/env/lib/python3.8/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|kr<d|kr<td|D ]:}|| jkrdt| 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   Zfn_)dispatchdebug)lensetRuntimeErrorr   r
   Zimpl_t_t)r   Z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   s   t | j d| j S N::)r   Z_dispatch_dumpr	   r   r   r   r   r   rawRegistrations   s    z!PythonDispatcher.rawRegistrationsc                 C   s   t | j d| j S r"   )r   Z_dispatch_dump_tabler	   r   r   r   r   r   rawDispatchTable   s    z!PythonDispatcher.rawDispatchTablec                    sx   |  d}|  }|d}|D ]R}|dd  t fdd| jD r |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>r#   r      )r!   r$   splitanyr   r   )r   outputstateZstate_entriesliner   r   r*   r   registrations   s    

zPythonDispatcher.registrationsc                 C   sr   |  d}|  }|d}td}|D ]B}|dd }|| jkr*|d|}|| ||dd 7 }q*|S )	NzComputed Dispatch Tabler   z)registered at .*FallbackKernel\.cpp.*(\[)r&   r   [z: r-   )r!   r%   r.   recompileruntime_keyssubr   )r   r0   tableZtable_entriesregexr2   r)   entryr   r   r   dispatchTable   s    



zPythonDispatcher.dispatchTableN)__name__
__module____qualname__r	   r   r7   Z
alias_keysr   r   r   r   r   r!   r$   r%   r3   r<   r   r   r   r   r   6   s2       
r   )r5   Ztorch._CZ_Cr   r   r   r   r   r   <module>   s   3