Ë
    L²j»`  ã                   ó†  — U d dl Z d dlmZmZ d dlmZmZ d dlmZm	Z	m
Z
 d dlZg d¢Z e j                  e«      Z e	d«      Z e
d«      Zeeej&                  ef   ef   Zeeef   Zeez  Ze G d„ d	«      «       Zeeeee   gee   f   Ze G d
„ d«      «       Z e«       Zeed<   i aee eef   ejB                  jD                  f   ed<   ee eef   ee   f   Z#i a$e#ed<   eeee eef      f   Z%i a&e%ed<   i a'e%ed<   i a(e%ed<   deee   z  dz  deee   z  dz  deee   z  dz  de)e eef      fd„Z*ddœde+ddfd„Z,dededejB                  jD                  fd„Z-dejB                  jD                  dededdfd „Z.d!eee   z  dz  dee   fd"„Z/dddd#œd$eee   z  dz  d%eee   z  dz  d&eee   z  dz  ddfd'„Z0dddd(œd)eee   z  dz  d*eee   z  dz  d+eee   z  dz  ddfd,„Z1d-edee   fd.„Z2d-ededed/e eef   ddf
d0„Z3ddd1œd2ed3ededed4eez  d5e+d6e+ddfd7„Z4dd8œd9ee   d:ee   d;e+de+fd<„Z5dd=œdeded>ee   d?edz  ddf
d@„Z6ddddAœdBedCe)e eef      dz  dDe+d?edz  ddf
dE„Z7dd=œdeded>ee   d?edz  ddf
dF„Z8dPdG„Z9ddHœdIedDe+ddfdJ„Z:ddHœdKeeeege+f   dDe+ddfdL„Z;ddHœdMeeege+f   dNedDe+ddfdO„Z<y)Qé    N)ÚCallableÚIterable)Ú	dataclassÚfield)ÚConcatenateÚ	ParamSpecÚTypeVar)ÚUserOrderingFnÚregister_op_overrideÚ!reorder_graphs_from_user_functionÚreenable_op_overridesÚderegister_op_overridesÚget_dsl_operationsÚPÚRc                   óV   — e Zd ZU dZeed<   eed<   eed<   eed<   dZeed<   dZ	eed	<   y
)Ú_OverrideNodezTrack function override data.Údsl_nameÚ	op_symbolÚdispatch_keyÚoverride_fnFÚunconditional_overrideTÚactiveN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__Ú_OpFnr   Úboolr   © ó    úU/var/www/html/ia-enhanced/venv/lib/python3.12/site-packages/torch/_native/registry.pyr   r      s0   … á'àƒMØƒNØÓØÓØ#(Ð˜DÓ(Ø€FˆDÔr#   r   c                   ó  — e Zd ZU dZ ee¬«      Zee   ed<    ee¬«      Z	ee   ed<    ee¬«      Z
ee   ed<   dedefd„Z	 dd	eee   z  d
z  deee   z  d
z  deee   z  d
z  dedd
f
d„Zdeeeef      fd„Zdefd„Zy
)Ú_FilterStatez+Manages filtering state for override nodes.)Údefault_factoryÚ
_dsl_namesÚ_op_symbolsÚ_dispatch_keysÚnodeÚreturnc                 óš   — |j                   | j                  v ry|j                  | j                  v ry|j                  | j
                  v ryy)zå
        Check if a node is enabled based on current filter state.

        Args:
            node: The override node to check

        Returns:
            bool: True if the node should be enabled, False if filtered out
        FT)r   r(   r   r)   r   r*   )Úselfr+   s     r$   Úcheck_enabledz_FilterState.check_enabled4   sF   € ð �=‰=˜DŸO™OÑ+Øà�>‰>˜T×-Ñ-Ñ-Øà×Ñ × 3Ñ 3Ñ3Øàr#   Ú	dsl_namesNÚ
op_symbolsÚdispatch_keysÚremove_keysc                 óÞ  — |rv| xj                   t        t        |«      «      z  c_         | xj                  t        t        |«      «      z  c_        | xj                  t        t        |«      «      z  c_        y| xj                   t        t        |«      «      z  c_         | xj                  t        t        |«      «      z  c_        | xj                  t        t        |«      «      z  c_        y)aó  
        Update filter sets as (current | new) or (current ~ new).

        Args:
            dsl_names: DSL names to add/remove from filter
            op_symbols: Operation symbols to add/remove from filter
            dispatch_keys: Dispatch keys to add/remove from filter
            remove_keys: If True, remove keys from filter; if False, add them

        Note:
            Uses set.discard as it doesn't raise an exception if the element
            wasn't in the set to begin with.
        N)r(   ÚsetÚ_resolve_iterabler)   r*   )r.   r0   r1   r2   r3   s        r$   Úupdatez_FilterState.updateI   s©   € ñ( Ø�OŠOœsÔ#4°YÓ#?Ó@Ñ@�OØ×Ò¤Ô$5°jÓ$AÓ BÑBÕØ×Ò¤3Ô'8¸Ó'GÓ#HÑHÖà�OŠOœsÔ#4°YÓ#?Ó@Ñ@�OØ×Ò¤Ô$5°jÓ$AÓ BÑBÕØ×Ò¤3Ô'8¸Ó'GÓ#HÑHÖr#   c                 óX   — t        | j                  | j                  | j                  «      S )z¯
        Build a set of dictionary keys based on the current filter state.

        Returns:
            set[tuple[str, str]]: Set of (op_symbol, dispatch_key) tuples
        )Ú_build_key_setr(   r)   r*   )r.   s    r$   Úbuild_disable_key_setz"_FilterState.build_disable_key_setf   s*   € ô Ø�O‰OØ×ÑØ×Ñó
ð 	
r#   c                 ó(  — d}|dz  }|dz  }t        | j                  «      D ]  \  }}|d|› d|› d�z  }Œ |dz  }t        | j                  «      D ]  \  }}|d|› d|› d�z  }Œ |dz  }t        | j                  «      D ]  \  }}|d|› d|› d�z  }Œ |S )	z-Return string representation of filter state.Ú zFilter State:
z  === DSL: ===
ú    z: ú
z  === OP SYMBOL: ===
z  === DISPATCH KEYS: ===
)Ú	enumerater(   r)   r*   )r.   ÚsÚiÚdslÚopÚkeys         r$   Ú__str__z_FilterState.__str__s   sÝ   € àˆØ	ÐÑˆØ	ÐÑˆÜ §¡Ó0ò 	%‰FˆAˆsØ�4˜�s˜"˜S˜E Ð$Ñ$‰Að	%à	Ð%Ñ%ˆÜ˜t×/Ñ/Ó0ò 	$‰EˆAˆrØ�4˜�s˜"˜R˜D Ð#Ñ#‰Að	$à	Ð)Ñ)ˆÜ × 3Ñ 3Ó4ò 	%‰FˆAˆsØ�4˜�s˜"˜S˜E Ð$Ñ$‰Að	%ð ˆr#   )F)r   r   r   r   r   r5   r(   r   r   r)   r*   r   r!   r/   r   r7   Útupler:   rE   r"   r#   r$   r&   r&   ,   sà   … á5á °Ô5€J��C‘Ó5Ù!°#Ô6€K��S‘Ó6Ù$°SÔ9€N�C˜‘HÓ9ð -ð °Dó ð4 "ñIà˜ #™Ñ&¨Ñ-ðIð ˜( 3™-Ñ'¨$Ñ.ðIð ˜X c™]Ñ*¨TÑ1ð	Ið
 ðIð 
óIð:
 s¨5°°c°©?Ñ';ó 
ð˜ô r#   r&   Ú_filter_stateÚ_libsÚ_graphsÚ_dsl_name_to_lib_graphÚ_dispatch_key_to_lib_graphÚ_op_symbol_to_lib_graphr0   r1   r2   r,   c                 ó´   ‡— t        «       Šdt        t        t           z  dz  dt        ddfˆfd„} || t        «        ||t
        «        ||t        «       ‰S )aK  
    Build a set of dictionary keys based on filter criteria.

    Args:
        dsl_names: DSL names to include in key set
        op_symbols: Operation symbols to include in key set
        dispatch_keys: Dispatch keys to include in key set

    Returns:
        set[tuple[str, str]]: Set of (op_symbol, dispatch_key) tuples
    ÚentriesNÚgraph_lib_dictr,   c                 ój   •— t        | «      }|D ]"  }||v sŒ||   D ]  }‰j                  |«       Œ Œ$ y)z;Helper to add matching keys from graph_lib_dict to key_set.N)r6   Úadd)rN   rO   Úresolved_entriesÚentryrD   Úkey_sets        €r$   Ú_append_to_setz&_build_key_set.<locals>._append_to_set¨   sG   ø€ ô -¨WÓ5Ðà%ò 	%ˆEØ˜Ò&Ø)¨%Ñ0ò %�CØ—K‘K Õ$ñ%ñ	%r#   )r5   r   r   Ú_MappingTyperJ   rL   rK   )r0   r1   r2   rU   rT   s       @r$   r9   r9   –   s_   ø€ ô  %(£E€Gð	%Ü”x¤‘}Ñ$ tÑ+ð	%Ü=Ið	%à	õ	%ñ �9Ô4Ô5Ù�:Ô6Ô7Ù�=Ô"<Ô=à€Nr#   F)Úprint_inactiverW   c                 ó$  — t         j                  «       D ]y  \  \  }}}t        d|›d|›�«       t        |«      D ]R  \  }}|j                  s| sŒd|› d|j
                  ›d|j                  ›�}| r|d|j                  ›�z  }t        |«       ŒT Œ{ y)z~
    Print all override graphs for debugging purposes.

    Args:
        print_inactive: Whether to print inactive nodes
    zop=z, key=r=   z: node.dsl_name=z, node.unconditional_override=z node.active=N)rI   ÚitemsÚprintr?   r   r   r   )rW   rC   rD   Ú	node_listrA   r+   r@   s          r$   Ú_print_override_graphsr\   º   s�   € ô !(§¡£ò 	Ñ‰	ˆˆS�9Ü����W˜�vÐÔä  Ó+ò 	‰GˆAˆtØ�{Š{šnØ ˜sÐ"3 T§]¡]Ð$4Ð4S°t×7RÑ7RÐ6TÐU�Ù!Ø˜>˜TŸ[™[˜NÐ+Ñ+�Aä�a•ñ	ñ	r#   r   r   c                 ó|   — | |f}|t         vr(t        j                  j                  dd|«      t         |<   t         |   S )zç
    Get or create a torch.library.Library instance for the given key.

    Args:
        op_symbol: The operation symbol
        dispatch_key: The dispatch key

    Returns:
        torch.library.Library: The library instance
    ÚatenÚIMPL)rH   ÚtorchÚlibraryÚLibrary)r   r   rD   s      r$   Ú_get_or_create_libraryrc   Í   s<   € ð �lÐ
#€CØ
”%ÑÜ—]‘]×*Ñ*¨6°6¸<ÓHŒˆc‰
ä�‰:Ðr#   Úlibr+   c                 ón   — | j                  |j                  |j                  ||j                   d¬«       y)zà
    Register a single node implementation with the library.

    Args:
        lib: The torch.library.Library instance
        node: The override node to register
        dispatch_key: The dispatch key for registration
    T)Úwith_keysetÚallow_overrideN)Úimplr   r   r   )rd   r+   r   s      r$   Ú_register_node_implri   á   s7   € ð ‡H�HØ�‰Ø×ÑØØ×3Ñ3Ð3Øð õ r#   Úiterablec                 óT   — | €g S t        | t        «      rt        | t        «      r| fS | S )zÌ
    Resolve various input types to a consistent iterable of strings.

    Args:
        iterable: String, iterable of strings, or None

    Returns:
        Iterable[str]: Consistent iterable output
    )Ú
isinstancer   r   )rj   s    r$   r6   r6   õ   s/   € ð ÐØˆ	ä�h¤Ô)¬Z¸Ä#Ô-FØˆ{Ðà€Or#   )Úenable_dsl_namesÚenable_op_symbolsÚenable_dispatch_keysrm   rn   ro   c                 óÞ   — t         j                  d| ||«       t        j                  | ||d¬«       t	        | ||«      }|D ]*  }|\  }}|t
        v sŒt        ||t
        |   t        ¬«       Œ, y)as  
    Re-enable overrides by removing them from filter state and reregistering.

    Args:
        enable_dsl_names: DSL names to re-enable
        enable_op_symbols: Operation symbols to re-enable
        enable_dispatch_keys: Dispatch keys to re-enable

    Note:
        This function uses reverse filter state management (removing from
        filters to enable).
    z>Re-registering ops by dsl: %s, op_symbol: %s, dispatch_key: %sT)r3   ©Úfilter_stateN)ÚlogÚinforG   r7   r9   rI   Ú_register_overrides_from_graph)rm   rn   ro   rT   rD   r   r   s          r$   r   r     s‹   € ô$ ‡H�HØHØØØô	ô ×ÑØØØØð	 ô ô %3ØØØó%€Gð ò ˆØ"%Ñˆ	�<à”'Š>ô +Ø˜<¬°©ÄMöñr#   )Údisable_dsl_namesÚdisable_op_symbolsÚdisable_dispatch_keysrv   rw   rx   c                 óè   — t         j                  d| ||«       t        j                  | ||«       t        j	                  «       }|D ]*  }|\  }}|t
        v sŒt        ||t
        |   t        ¬«       Œ, y)ag  
    De-register overrides by updating filter state and reregistering graphs.

    Args:
        disable_dsl_names: DSL names to disable
        disable_op_symbols: Operation symbols to disable
        disable_dispatch_keys: Dispatch keys to disable

    Note:
        This function uses filter state management to selectively disable
        operations.
    z>De-registering ops by dsl: %s, op_symbol: %s, dispatch_key: %srq   N)rs   rt   rG   r7   r:   rI   Ú_cleanup_and_reregister_graph)rv   rw   rx   rT   rD   r   r   s          r$   r   r   =  s}   € ô$ ‡H�HØHØØØô	ô ×ÑÐ*Ð,>Ð@UÔVô %2×$GÑ$GÓ$I€Gð ò 	ˆØ"%Ñˆ	�<à”'Š>Ü)ØØÜ˜‘Ü*ö	ñ		r#   r   c                 ó¼   — t        «       }t        j                  «       D ]1  \  \  }}}|D ]$  }|j                  | k(  sŒ|j	                  |«        Œ1 Œ3 t        |«      S )z¼Get list of operations registered by a specific DSL.

    Args:
        dsl_name: Name of the DSL to query.

    Returns:
        Sorted list of operation names registered by the DSL.
    )r5   rI   rY   r   rQ   Úsorted)r   Ú
operationsr   Ú_Únodesr+   s         r$   r   r   i  s`   € ô “€JÜ!(§¡£ò Ñ‰ˆ�A˜Øò 	ˆDØ�}‰} Ó(Ø—‘˜yÔ)Ùñ	ðô
 �*ÓÐr#   rD   c                 óä   — dt         t        t        t        t        t        f      f   dt        dt        t        t        f   ddfd„} |t        | |«        |t
        ||«        |t        ||«       y)zÖ
    Update the registration mapping dictionaries.

    Args:
        dsl_name: The DSL name
        op_symbol: The operation symbol
        dispatch_key: The dispatch key
        key: The dictionary key tuple
    ÚregistrationÚsymbolrD   r,   Nc                 ó^   — | j                  |«      }|€	|g}|| |<   y|j                  |«       y)z;Helper to add key to registration list or create new entry.N)ÚgetÚappend)r�   r‚   rD   Ú
entry_lists       r$   Ú_get_new_entry_or_appendz;_update_registration_maps.<locals>._get_new_entry_or_appendŽ  s9   € ð "×%Ñ% fÓ-ˆ
àÐØ˜ˆJØ#-ˆL˜Ò à×Ñ˜cÕ"r#   )Údictr   ÚlistrF   rJ   rL   rK   )r   r   r   rD   r‡   s        r$   Ú_update_registration_mapsrŠ   {  ss   € ð&#Üœ3¤¤U¬3´¨8¡_Ñ 5Ð5Ñ6ð#äð#ô ”3œ�8‰_ð#ð 
ó	#ñ Ô3°X¸sÔCÙÔ4°iÀÔEÙÔ7¸ÀsÕKr#   )Úallow_multiple_overrider   ÚbackendÚ
lib_symbolrh   r‹   r   c          	      óÎ   — |dk7  rt        d|› d�«      ‚||f}t        j                  |g «      }|j                  t	        | ||||¬«      «       |t        |<   t        | |||¬«       y)aÄ  
    Register a passed override function to the dispatcher.

    Actually a graph-building operation; real registration happens later.

    Args:
        backend: The backend name (DSL name)
        lib_symbol: Library you're overriding symbols in (must be "aten")
        op_symbol: Name of the operation you're overriding
        dispatch_key: Dispatch key to override
        impl: Implementation function for the override
        allow_multiple_override: Allow overriding an existing override
        unconditional_override: Implementation doesn't have a fallback and
            doesn't require torch.DispatchKeySet as the first argument

    Raises:
        ValueError: If lib_symbol is not "aten"
    r^   z.Unsupported lib_symbol (must be "aten", got: "ú")r   r   r   r   r   )rD   N)Ú
ValueErrorrI   r„   r…   r   rŠ   )	rŒ   r�   r   r   rh   r‹   r   rD   Úop_graphs	            r$   r   r   ¡  sz   € ð8 �VÒÜÐIÈ*ÈÐUVÐWÓXÐXà�lÐ
#€Cô �{‰{˜3 Ó#€Hà‡O�OÜØØØ%ØØ#9ô	
ôð „GˆC�Lä˜g y°,ÀCÖHr#   ©Úforce_reregisterÚoriginal_graphÚ	new_graphr“   c                ó   — |ry| |k7  S )aG  
    Determine if a graph needs reregistration based on changes.

    Args:
        original_graph: The original graph before modification
        new_graph: The graph after modification
        force_reregister: If True, always reregister regardless of changes

    Returns:
        bool: True if reregistration is needed
    Tr"   )r”   r•   r“   s      r$   Ú_should_reregister_graphr—   Ó  s   € ñ" Øð ˜YÑ&Ð&r#   rq   Úgraphrr   c                óN   — | |f}|t         v rt         |= |rt        | |||¬«       yy)a]  
    Clean up existing library and reregister a graph.

    This is the common pattern used across reorder, deregister, and reenable operations.

    Args:
        op_symbol: The operation symbol
        dispatch_key: The dispatch key
        graph: The graph to register
        filter_state: Optional filter state for conditional registration
    rq   N)rH   ru   )r   r   r˜   rr   rD   s        r$   rz   rz   ë  s<   € ð$ �lÐ
#€Cð Œe�|Ü�#ˆJñ Ü&ØØØØ%ö		
ð r#   )Úkeys_to_processÚreregister_overridesrr   Útransformation_fnrš   r›   c                óB  — |�|nt        t        j                  «       «      }t        |«      D ]—  \  }}||ft        vrŒt        t        ||f   «      }	  | |||«      }t        |t        «      s,t        j                  dt        |«      j                  ||«       Œl|t        ||f<   |sŒzt        ||d¬«      sŒ‰t!        ||||¬	«       Œ™ y# t        t
        t        t        f$ r t        j                  d||d¬«       Y ŒÏt        $ r t        j                  d||«       Y Œðw xY w)
a”  
    Apply a transformation function to graphs and optionally reregister.

    This is the core pattern used by reorder_graphs_from_user_function and
    can be reused for other graph transformation operations.

    Args:
        transformation_fn: Function to transform each graph
        keys_to_process: Keys to process, or None for all graphs
        reregister_overrides: Whether to reregister changed graphs
        filter_state: Optional filter state for conditional registration

    Note:
        If transformation_fn raises an exception for a specific graph, that graph
        will be skipped and processing will continue with remaining graphs.
    NúAGraph transformation failed for %s/%s. Preserving original graph.T©Úexc_infoúNUnexpected error in graph transformation for %s/%s. Preserving original graph.zbGraph transformation returned invalid type %s for %s/%s. Expected list. Preserving original graph.Fr’   rq   )r5   rI   Úkeysr‰   Ú	TypeErrorr�   ÚAttributeErrorÚRuntimeErrorrs   ÚwarningÚ	ExceptionÚ	exceptionrl   Útyper   r—   rz   )	rœ   rš   r›   rr   Útarget_keysr   r   r”   r•   s	            r$   Ú_apply_graph_transformationr«     s=  € ð6 +Ð6‰¼CÄÇÁÃÓ<Oð ô
 $(¨Ó#4ò /Ñˆ	�<Ø�|Ð$¬GÑ3Øäœg y°,Ð&?Ñ@ÓAˆð	Ù)¨)°\À>ÓRˆIô$ ˜)¤TÔ*Ü�K‰KØtÜ�Y“×(Ñ(ØØô	ð ð .7Œ�˜LÐ)Ñ*ò  Ô$<Ø˜I¸ö%
ô *ØØØØ)ö	ñU/øô œ:¤~´|ÐDò 	Ü�K‰KØSØØØð	 ô ñ Üò 	Ü�M‰MØ`ØØôñ
 ð	ús   Á
CÃ2DÃ<DÄDc                ó�   — | |f}t        |Ž }|D ]5  }d}|r|j                  |«      }|rt        |||«       d|_        Œ/d|_        Œ7 y)a  
    Register all overrides in a single graph.

    Args:
        op_symbol: The operation symbol
        dispatch_key: The dispatch key
        graph: List of override nodes to register
        filter_state: Optional filter state for conditional registration
    TFN)rc   r/   ri   r   )r   r   r˜   rr   rD   rd   r+   Úenables           r$   ru   ru   _  s\   € ð  �lÐ
#€CÜ
  #Ð
&€Càò 	 ˆØˆÙØ!×/Ñ/°Ó5ˆFáÜ  T¨<Ô8ØˆD�KàˆD�Kñ	 r#   c                  ó`   — t         j                  «       D ]  \  } }| \  }}t        |||«       Œ y)zO
    Perform all registration calls from previously-built override graphs.
    N)rI   rY   ru   )rD   r˜   r   r   s       r$   Ú_register_all_overridesr¯   ~  s8   € ô —m‘m“oò 
‰
ˆˆUØ"%Ñˆ	�<ä&ØØØõ	
ñ
r#   )r›   Úfnc                ó   — t        | |¬«       y)a¶  
    Reorder override graphs using a user-provided ordering function.

    Args:
        fn: User-provided function that takes (op_symbol, dispatch_key, graph)
            and returns a reordered graph
        reregister_overrides: Whether to reregister graphs that have changed

    Note:
        This function uses the common graph transformation pattern and can serve
        as an example for other graph manipulation operations.
    ©rœ   r›   N)r«   )r°   r›   s     r$   r   r   Œ  s   € ô"  ØØ1ör#   Ú	filter_fnc          	      óx   ‡ — dt         dt         dt        t           dt        t           fˆ fd„}t        ||¬«       y)aø  
    Apply a filter function to remove nodes from graphs.

    This is a convenience function that uses the graph transformation pattern
    to filter out unwanted nodes.

    Args:
        filter_fn: Function that takes (op_symbol, dispatch_key, node) and
            returns True to keep the node, False to remove it
        reregister_overrides: Whether to reregister modified graphs

    Example:
        # Remove all nodes with "deprecated" in the DSL name
        _apply_graph_filter(
            lambda op, dk, node: "deprecated" not in node.dsl_name,
            reregister_overrides=True
        )

    Note:
        If filter_fn raises an exception for a specific graph, the original
        graph will be preserved and processing will continue.
    r   r   r˜   r,   c                 ó   •— 	 |D �cg c]  } ‰| ||«      sŒ|‘Œ c}S c c}w # t         t        t        t        f$ r t        j                  d| |d¬«       |cY S t        $ r t        j                  d| |«       |cY S w xY w)z-Apply filter_fn to graph with error handling.rž   TrŸ   r¡   ©r£   r�   r¤   r¥   rs   r¦   r§   r¨   )r   r   r˜   r+   r³   s       €r$   Úfiltering_transformationz5_apply_graph_filter.<locals>.filtering_transformation¿  sˆ   ø€ ð	Ø%*ÖW˜T©i¸	À<ÐQUÕ.V’DÒWÐWùÒWøÜœ:¤~´|ÐDò 	Ü�K‰KØSØØØð	 ô ð ŠLÜò 	Ü�M‰MØ`ØØôð
 ŠLð	ús%   ƒ# ‡—›# ž# £4A=Á!A=Á<A=r²   N©r   r‰   r   r«   )r³   r›   r·   s   `  r$   Ú_apply_graph_filterr¹   £  sB   ø€ ð8ÜðÜ&)ðÜ26´}Ñ2Eðä	ŒmÑ	õô,  Ø2Ø1ör#   Úcondition_fnÚordering_fnc          	      ó|   ‡ ‡— dt         dt         dt        t           dt        t           fˆ ˆfd„}t        ||¬«       y)aE  
    Apply reordering only to graphs that match a condition.

    This allows for more targeted reordering operations.

    Args:
        condition_fn: Function that takes (op_symbol, dispatch_key) and
            returns True if the graph should be reordered
        ordering_fn: Ordering function to apply to matching graphs
        reregister_overrides: Whether to reregister modified graphs

    Example:
        # Only reorder CUDA operations
        _apply_selective_reordering(
            condition_fn=lambda op, dk: dk == "CUDA",
            ordering_fn=lambda op, dk, g: sorted(g, key=lambda n: n.dsl_name),
            reregister_overrides=True
        )

    Note:
        If condition_fn or ordering_fn raises an exception for a specific graph,
        the original graph will be preserved and processing will continue.
    r   r   r˜   r,   c                 óª  •— 	  ‰| |«      }|r	  ‰| ||«      S |S # t         t        t        t        f$ r t        j                  d| |d¬«       |cY S t        $ r t        j                  d| |«       |cY S w xY w# t         t        t        t        f$ r t        j                  d| |d¬«       |cY S t        $ r t        j                  d| |«       |cY S w xY w)z=Apply ordering_fn conditionally based on condition_fn result.rž   TrŸ   r¡   r¶   )r   r   r˜   Úshould_reorderrº   r»   s       €€r$   Úconditional_transformationz?_apply_selective_reordering.<locals>.conditional_transformationù  sø   ø€ ð	Ù)¨)°\ÓBˆNñ" ðÙ" 9¨l¸EÓBÐBð" ˆøôG œ:¤~´|ÐDò 	Ü�K‰KØSØØØð	 ô ð ŠLÜò 	Ü�M‰MØ`ØØôð
 ŠLð	ûô œz¬>¼<ÐHò Ü—‘ØWØØ Ø!ð	 ô ð ’Üò Ü—‘ØdØØ ôð
 ’ðús,   ƒ	 �	A8 ›4A5Á!A5Á4A5Á84CÂ.!CÃCr²   Nr¸   )rº   r»   r›   r¿   s   ``  r$   Ú_apply_selective_reorderingrÀ   Û  sC   ù€ ð<)Üð)Ü&)ð)Ü26´}Ñ2Eð)ä	ŒmÑ	ö)ôV  Ø4Ø1ör#   )r,   N)=ÚloggingÚcollections.abcr   r   Údataclassesr   r   Útypingr   r   r	   Útorch.libraryr`   Ú__all__Ú	getLoggerr   rs   r   r   ÚDispatchKeySetÚ_OpOverrideFnÚ_OpReplaceFnr    r   r   r‰   r
   r&   rG   r   rH   rˆ   rF   ra   rb   Ú_GraphsTyperI   rV   rJ   rK   rL   r5   r9   r!   r\   rc   ri   r6   r   r   r   rŠ   r   r—   rz   r«   ru   r¯   r   r¹   rÀ   r"   r#   r$   ú<module>rÌ      sœ  ðÜ ß .ß (ß 2Ñ 2ã ò€ð €g×Ñ˜Ó!€áˆcƒN€ÙˆCƒL€à˜ U×%9Ñ%9¸1Ð%<Ñ=¸qÐ@ÑA€Ø˜˜1˜‰~€à˜Ñ$€ð ÷ð ó ðð ˜3  T¨-Ñ%8Ð9¸4ÀÑ;NÐNÑO€ð ÷Tð Tó ðTñp +›n€ˆ|Ó ,ð 79€€tˆE�#�s�(‰O˜UŸ]™]×2Ñ2Ð2Ñ3Ó 8ð �5˜˜c˜‘? D¨Ñ$7Ð7Ñ8€Ø€ˆÓ à�C˜˜e C¨ H™oÑ.Ð.Ñ/€ð (*Ð ˜Ó )Ø+-Ð ˜LÓ -Ø(*Ð ˜Ó *ð!Ø�X˜c‘]Ñ" TÑ)ð!à�h˜s‘mÑ# dÑ*ð!ð ˜ #™Ñ&¨Ñ-ð!ð 	ˆˆs�Cˆx‰Ñó	!ðH 6;ò ¨dð ¸tó ð& cð ¸ð ÀÇÁ×AVÑAVó ð(Ø	�‰×	Ñ	ðØ&3ðØCFðà	óð(  h¨s¡mÑ 3°dÑ :ð ¸xÈ¹}ó ð* 04Ø04Ø37ò	2à˜D ™I‘o¨Ñ,ð2ð ˜T #™Y‘¨Ñ-ð2ð   S¡	™/¨DÑ0ð	2ð
 
ó2ðn 15Ø15Ø48ò	)à˜T #™Y‘¨Ñ-ð)ð ˜d 3™i™¨$Ñ.ð)ð   c¡™?¨TÑ1ð	)ð
 
ó)ðX ð ¨¨c©ó ð$#LØð#Làð#Lð ð#Lð 
ˆs�Cˆx‰ð	#Lð
 
ó#LðZ %*Ø#(ò/IØð/Iàð/Ið ð/Ið ð	/Ið
 ˜,Ñ
&ð/Ið "ð/Ið !ð/Ið 
ó/Iðl #ò	'Ø˜Ñ'ð'à�MÑ"ð'ð ð	'ð
 
ó'ð: )-ò 
Øð 
àð 
ð �Ñð 
ð
  Ñ%ð 
ð 
ó 
ðL 48Ø!&Ø(,òNØ%ðNð ˜˜s C˜x™Ñ)¨DÑ0ðNð ð	Nð
  Ñ%ðNð 
óNðl )-ò Øð àð ð �Ñð ð
  Ñ%ð ð 
ó ó>
ð" "'òØðð ðð 
ó	ð4 "'ò5Ø˜˜c =Ð1°4Ð7Ñ8ð5ð ð5ð 
ó	5ðx "'ò	LØ˜C ˜: tÐ+Ñ,ðLàðLð ð	Lð
 
ôLr#   