ó
    EñiŠ  ã                   ó,  • % S r SSKrSSKrSSKJrJr  SSKJr  SSKJ	r	J
r
JrJr  SSKrSSKJr  \R                  " \5      r " S S\5      r\\R&                  \\R*                     /\4   r0 r\\\
\   4   \S	'   0 r\\\4   \S
'      SS\
\   S\
\   S\\   S\S\	4   4S jjr\R:                  " \SS9r\R:                  " \SS9rS\\\4   S\4S jr SS\\   4S jjr!\RD                  SS j5       r#\RD                  SS j5       r$S\S\%4S jr&g)aÚ  
This module implements TorchDynamo's backend registry system for managing compiler backends.

The registry provides a centralized way to register, discover and manage different compiler
backends that can be used with torch.compile(). It handles:

- Backend registration and discovery through decorators and entry points
- Lazy loading of backend implementations
- Lookup and validation of backend names
- Categorization of backends using tags (debug, experimental, etc.)

Key components:
- CompilerFn: Type for backend compiler functions that transform FX graphs
- _BACKENDS: Registry mapping backend names to entry points
- _COMPILER_FNS: Registry mapping backend names to loaded compiler functions

Example usage:
    @register_backend
    def my_compiler(fx_graph, example_inputs):
        # Transform FX graph into optimized implementation
        return compiled_fn

    # Use registered backend
    torch.compile(model, backend="my_compiler")

The registry also supports discovering backends through setuptools entry points
in the "torch_dynamo_backends" group. Example:
```
setup.py
---
from setuptools import setup

setup(
    name='my_torch_backend',
    version='0.1',
    packages=['my_torch_backend'],
    entry_points={
        'torch_dynamo_backends': [
            # name = path to entry point of backend implementation
            'my_compiler = my_torch_backend.compiler:my_compiler_function',
        ],
    },
)
```
```
my_torch_backend/compiler.py
---
def my_compiler_function(fx_graph, example_inputs):
    # Transform FX graph into optimized implementation
    return compiled_fn
```
Using `my_compiler` backend:
```
import torch

model = ...  # Your PyTorch model
optimized_model = torch.compile(model, backend="my_compiler")
```
é    N)ÚCallableÚSequence)Ú
EntryPoint)ÚAnyÚOptionalÚProtocolÚUnion)Úfxc                   óX   • \ rS rSrS\R
                  S\\R
                  S4   4S jrSrg)Ú
CompiledFnéJ   ÚargsÚreturn.c                 ó   • g )N© )Úselfr   s     Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/_dynamo/backends/registry.pyÚ__call__ÚCompiledFn.__call__K   s   € Èó    r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚtorchÚTensorÚtupler   Ú__static_attributes__r   r   r   r   r   J   s!   † ØL˜eŸl™lÐL¨u°U·\±\À3Ð5FÑ/G×Lr   r   Ú	_BACKENDSÚ_COMPILER_FNSÚcompiler_fnÚnameÚtagsr   .c                 ó  • U c  [         R                  " [        XS9$ [        U 5      (       d   eU=(       d    U R                  nU[
        ;  d
   SU 35       eU [        ;  a	  S[        U'   U [
        U'   [        U5      U l        U $ )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Úcallabler   r    r   r   Ú_tags)r!   r"   r#   s      r   r'   r'   T   s‡   € ð  Ñä× Ò Ô!1¸ÑHÐHÜ�K× Ñ Ð Ð Ø×'�;×'Ñ'€DØ”}Ó$Ð?Ð(8¸¸Ð&?Ó?Ð$Øœ)Ó#ØŒ	�$‰Ø%„M�$ÑÜ˜d›€KÔØÐr   )Údebug)r#   )Úexperimentalc                 óò   • [        U [        5      (       aa  U [        ;  a
  [        5         U [        ;  a  SSKJn  U" U S9eU [        ;  a$  [        U    nUb  [        UR                  5       U S9  [        U    n U $ )z#Expand backend strings to functionsé   )ÚInvalidBackend)r"   )r!   r"   )	Ú
isinstanceÚstrr   Ú_lazy_importÚexcr.   r    r'   Úload)r!   r.   Úentry_points      r   Úlookup_backendr5   w   sm   € ä�+œs×#Ñ#ØœiÓ'ÜŒNØœiÓ'Ý,á  kÑ2Ð2àœmÓ+Ü# KÑ0ˆKØÑ&Ü ¨[×-=Ñ-=Ó-?ÀkÒRÜ# KÑ0ˆØÐr   c                 óð   • [        5         [        U =(       d    S5      n[         Vs/ s H8  nU[        ;  d)  UR	                  [        U   R
                  5      (       a  M6  UPM:     nn[        U5      $ s  snf )zU
Return valid strings that can be passed to:

    torch.compile(..., backend="name")
r   )r1   Úsetr   r    Úintersectionr)   Úsorted)Úexclude_tagsÚexclude_tags_setr"   Úbackendss       r   Úlist_backendsr=   Š   sn   € ô „NÜ˜<×-¨2Ó.Ðõ óâˆDØ”}Ó$Ø×,Ñ,¬]¸4Ñ-@×-FÑ-F×G÷ 	Ùð ð ô �(ÓÐùòs   §5A3Á A3c                  óV   • SSK Jn   SSKJn  U" U 5        SSKJn  Uc   e[        5         g )Nr-   )r<   )Úimport_submodule)Údynamo_minifier_backend)Ú r<   Úutilsr?   Úrepro.after_dynamor@   Ú_discover_entrypoint_backends)r<   r?   r@   s      r   r1   r1   œ   s%   € åÝ(á�XÔå<à"Ñ.Ð.Ð.ä!Õ#r   c                  óŽ   • SSK Jn   SnU " US9nUR                   Vs0 s H  o3X#   _M	     nnU H  nXE   [        U'   M     g s  snf )Nr   )Úentry_pointsÚtorch_dynamo_backends)Úgroup)Úimportlib.metadatarF   Únamesr   )rF   Ú
group_nameÚepsr"   Úeps_dictÚbackend_names         r   rD   rD   ª   sN   € õ 0à(€JÙ
˜ZÑ
(€Cà,/¯IªIÓ6ªI D�c‘i’©I€HÐ6Û ˆØ"*Ñ"8Œ	�,Óò !ùò 7s   �Ac                 ó  • [        5         U [        R                  5       ;   a  g[        U S5      (       a!  U R                  nU[
        ;   d
  U[        ;   a  g[        U S5      (       a!  U R                  [        R                  5       ;   $ g)z‹
Check if the given compiler function is a registered backend.
Custom backends (user-provided callables not in the registry) return False.
TÚcompiler_namer!   F)r1   r    ÚvaluesÚhasattrrP   r   r!   )r!   rP   s     r   Ú_is_registered_backendrS   ·   sw   € ô „Nð ”m×*Ñ*Ó,Ó,Øô ˆ{˜O×,Ñ,Ø#×1Ñ1ˆØœIÓ%¨¼-Ó)GØô ˆ{˜M×*Ñ*Ø×&Ñ&¬-×*>Ñ*>Ó*@Ñ@Ð@àr   )NNr   ))r*   r+   )r   N)'Ú__doc__r%   ÚloggingÚcollections.abcr   r   rI   r   Útypingr   r   r   r	   r   r
   Ú	getLoggerr   Úlogr   ÚGraphModuleÚlistr   Ú
CompilerFnr   Údictr0   Ú__annotations__r    r'   r&   Úregister_debug_backendÚregister_experimental_backendr5   r=   Úcacher1   rD   ÚboolrS   r   r   r   Ú<module>rc      sz  ðò:óx Û ß .Ý )ß 1Ó 1ã Ý ð ×Ò˜Ó!€ôM�ô Mð �r—~‘~ t¨E¯L©LÑ'9Ð:¸JÐFÑG€
à-/€	ˆ4��X˜jÑ)Ð)Ñ*Ó /Ø')€ˆt�C˜�OÑ$Ó )ð )-ØØñØ˜*Ñ%ðà
�3‰-ðð �3‰-ðð ˆc�3ˆhÑõ	ð: #×*Ò*Ð+;À*ÑMÐ Ø )× 1Ò 1ØÐ,ñ!Ð ð
  c¨: oÑ 6ð ¸:ô ñ&¸TÀ#¹Yõ ð$ ‡�ó
$ó ð
$ð ‡�ó	9ó ð	9ð¨
ð °tõ r   