U
    ,-ee                     @   s  U d dl Z d dlZd dlmZmZmZmZmZmZm	Z	 d dl
Z
d dl
mZ G dd deZeejee
j gef Ze Zeeef ed< dee ee ee dd	d
Ze jeddZe jeddZdd Zdee dddZe ddd Ze dedddZdS )    N)CallableDictListOptionalProtocolSequenceTuple)fxc                   @   s(   e Zd Zejeejdf dddZdS )
CompiledFn.)argsreturnc                 G   s   d S )N )selfr   r   r   `/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/torch/_dynamo/backends/registry.py__call__
   s    zCompiledFn.__call__N)__name__
__module____qualname__torchTensorr   r   r   r   r   r   r
   	   s   r
   	_BACKENDSr   compiler_fnnametagsc                 C   sZ   | dkrt jt||dS t| s$t|p,| j}|tksDtd| | t|< t|| _| S )a  
    Decorator to add a given compiler to the registry to allow calling
    `torch.compile` with string shorthand.  Note: for projects not
    imported by default, it might be easier to pass a function directly
    as a backend and not use a string.

    Args:
        compiler_fn: Callable taking a FX graph and fake tensor inputs
        name: Optional name, defaults to `compiler_fn.__name__`
        tags: Optional set of string tags to categorize backend with
    N)r   r   zduplicate name: )		functoolspartialregister_backendcallableAssertionErrorr   r   tuple_tagsr   r   r   r   r      s    

r   )debug)r   )experimentalc                 C   sR   t | trN| tkrt  | tkr(t|  | tkrFddlm} || dt|  } | S )z#Expand backend strings to functions   )InvalidBackendr   )
isinstancestrr   _lazy_import_lazy_import_entry_pointexcr%   )r   r%   r   r   r   lookup_backend4   s    

r,   r"   r#   )r   c                    s,   t   t pd t fddt D S )za
    Return valid strings that can be passed to:

        torch.compile(..., backend="name")
    r   c                    s    g | ]\}}  |js|qS r   )intersectionr!   ).0r   backendZexclude_tagsr   r   
<listcomp>L   s   z!list_backends.<locals>.<listcomp>)r)   setsortedr   itemsr1   r   r1   r   list_backendsC   s    
r6   c                  C   s<   ddl m}  ddlm} ||  ddlm} |d k	s8td S )Nr$   )backends)import_submodule)dynamo_minifier_backend) r7   utilsr8   Zrepro.after_dynamor9   r   )r7   r8   r9   r   r   r   r)   T   s
    r)   backend_namec                    s   ddl m} d }d}tjdk rX| } fdd||dD }t|dkrx|d  }n ||d} |jkrx|   }|d k	r tt	 krt
| d	 d S )
Nr   )entry_pointsZtorch_dynamo_backends)   
   c                    s   g | ]}|j  kr|qS r   r&   )r/   epr<   r   r   r2   h   s     
 z,_lazy_import_entry_point.<locals>.<listcomp>r   )group)r   r   )importlib.metadatar>   sysversion_infogetlenloadnamesr6   r    r   )r=   r>   r   
group_nameZbackend_epsZepsr   r<   r   r*   `   s    


r*   )NNr   )r-   )r   rD   typingr   r   r   r   r   r   r   r   r	   r
   ZGraphModuler   Z
CompilerFndictr   r(   __annotations__r   r   Zregister_debug_backendZregister_experimental_backendr,   r6   	lru_cacher)   r*   r   r   r   r   <module>   s6    $    
