+
    ~j(                     :    ^RI Ht R tR tR t ! R R]4      tR# )   )PushToHubMixinc                   Rp \        V P                  4       4      pTP                  P
                  pTR8X  d2   ^RIHp T! 4       '       d   ^ RIp\        TR4      P                  e   R# T#   \         d    \        RT 24      hi ; i)zw
Infers the device type from the model parameters.
Args:
    model: The model instance.

Returns:
    The device type.
z
    {
        "RMSNorm": {
            "cuda":
                "kernels-community/layer_norm:LlamaRMSNorm",
            ...
        },
        ...
    }
    zPCannot determine model device, please provide a device to the mapping. Example: cuda)is_torch_availableNversionrocm)next
parametersStopIteration
ValueErrordevicetypeutilsr   torchgetattrhip)modelEXAMPLE_MAPPINGparamdev_typer   r   s   &     u/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/transformers/utils/kernel_config.pyinfer_devicer      s    	O
U%%'( ||  H6.ui(,,8O!  
^_n^op
 	

s   A- -Bc                     ^ RI Hp VR9  d   \        RV 24      hVP                  R4      ^,          pVP                  R4      ^ ,          pVW5! VVR7      //W@&   R# )    LayerRepositoryBOnly cuda, rocm, xpu, npu, neuron and tpu devices supported, got: :)repo_id
layer_nameNr   r   xpunpuneurontpu)kernelsr   r   split)r    r   	repo_namemodecompatible_mappingr   repo_layer_namer   s   &&&&&   r   add_to_mappingr,   :   sl    'DD]^d]efggooc*1-Oooc"1%G/*
&"    c                    ^ RI Hp ^ RIHp VR9  d   \	        RV 24      hVP                  R4      ^,          pVP                  R4      ^ ,          pVP                  R4      R	,          p	VW6! V! V4      V	VR7      //W@&   R# )
r   )Path)LocalLayerRepositoryr   r   /)	repo_pathpackage_namer    Nr!   )pathlibr/   r&   r0   r   r'   )
r    r   r(   r)   r*   r/   r0   r+   r2   repo_package_names
   &&&&&     r   add_to_mapping_localr7   K   s    ,DD]^d]efggooc*1-O$Q'I!,R0&y/.*
&"r-   c                   N   a  ] tR t^`t o RtR	R ltR
R ltR tR tRR lt	Rt
V tR# )KernelConfigz]
Kernel configuration class. This class is used to configure the kernel mapping for a model.
Nc                :    Ve   TM/ V n         / V n        W n        R # Nkernel_mappingregistered_layer_namesuse_local_kernel)selfr=   r?   s   &&&r   __init__KernelConfig.__init__e   s     0>0JnPR&(# 0r-   c                H    ^ RI Hp VWW! VVVR7      //V P                  V&   R# )r   r   )r   r    revisionN)r&   r   r=   )r@   r   registered_namer    r   r)   rD   r   s   &&&&&&& r   update_kernelKernelConfig.update_kernelj   s4    + o#)%0
O,r-   c                    VP                  4        F2  w  r#\        VR 4      '       g   K  VP                  V P                  V&   K4  	  R# )kernel_layer_nameN)named_moduleshasattrrI   r>   )r@   r   namemodules   &&  r   store_registered_layer_names)KernelConfig.store_registered_layer_namesw   s;    !//1LDv2334:4L4L++D1 2r-   c                   RpV P                  V4       \        V P                  \        4      '       g%   \	        RV R\        V P                  4       24      hV P                  P                  4        F  w  r4W0P                  P                  4       9  d   \	        RV R24      h\        V\        4      '       d"   RV9  g   RV9  d   \	        RV R	V 24      hKi  \        V\        4      '       df   VP                  4        FO  w  rVVR9  d   \	        R
V 24      h\        V\        4      '       d   RV9  g
   RV9  g   K@  \	        RV R	V 24      h	  K  \	        RV RV 24      h	  R# )a  
Validates the kernel_mapping to ensure that:
1. Each layer_name in the mapping is registered in the model (i.e., the model contains a module with a matching kernel_layer_name).
2. Each kernel value is either a string of the form 'org/repo:layer_name' or a dict mapping device types ("cuda", "rocm", "xpu", "npu") to such strings.
3. Each device key in a dict is one of "cuda", "rocm", "xpu", or "npu".
4. Each repo_name is a valid repository and layer name in the format 'org/repo:layer_name' (i.e., a string containing both a slash and a colon).
5. If a local path is detected, it should be in the format '/abs/path:layer_name'. The absolute path must include the `package_name`, like "/home/user/layer_norm".

Args:
    model: The model instance whose modules are checked for registered kernel_layer_name attributes.

Raises:
    ValueError: If a layer_name is not registered in the model, if a device is not supported,
                or if a repo_name is not a valid 'org/repo:layer_name' string.
a  
        For single device form remote
        {
            "RMSNorm":
                "kernels-community/layer_norm:LlamaRMSNorm",
            ...
        },
        For multiple devices form remote
        {
            "RMSNorm": {
                "cuda":
                    "kernels-community/layer_norm:LlamaRMSNorm",
                "rocm":
                    "kernels-community/layer_norm:LlamaRMSNorm",
                ...
            },
            ...
        }
        For single device form local
        {
            "RMSNorm":
                "/abs/path:LlamaRMSNorm",
            ...
        },
        For multiple devices form local
        {
            "RMSNorm": {
                "cuda":
                    "/abs/path:LlamaRMSNorm",
                "rocm":
                    "/abs/path:LlamaRMSNorm",
                ...
            },
            ...
        }
        z7Kernel mapping must be a dict of the following format: z, got: zLayer z[ is not registered in the model, please register it first using use_kernel_forward_from_hubr1   r   zKernel mapping for 'zl' must be a valid repo name with a layer name (e.g., 'org/repo:layer_name' or '/abs/path:layer_name'), got: r   z'Kernel mapping must follow the format: Nr!   )
rN   
isinstancer=   dictr   r   itemsr>   valuesstr)r@   r   MAPPING_FORMATr    kernelr   r(   s   &&     r   sanitize_kernel_mapping$KernelConfig.sanitize_kernel_mapping|   s    #H 	))%0$--t44I.IYY`aefjfyfyaz`{|  #'"5"5";";"=J!<!<!C!C!EE ZL  )D  E  &#&&f$6(9$.zl  ;g  hn  go  p  ):
 FD)))/%F%TT(+mntmu)vww%i55I9MQT\eQe(2:,  ?k  lu  kv  w  *8 !#J>JZZabhai!jkk- #>r-   c           	     d   ^ RI Hp / p\        V4      pV P                  P	                  4        F  w  rgVP
                  '       d   VP                  MVP                  pV'       d   WP                  ,          p\        V\        4      '       d3   Tp	V P                  '       g   \        WeWV4       K  \        WeWV4       K  \        V\        4      '       g   K  VP	                  4        F;  w  rW8w  d   K  V P                  '       g   \        WjWV4       K.  \        WjWV4       K=  	  K  	  W@n        R# )a  
Transforms a simple kernel_mapping of the form:
    {
        "RMSNorm":
            "kernels-community/layer_norm:LlamaRMSNorm",
        ...
    },

    or for local path:

    {
        "RMSNorm":
            "/home/user/liger_kernels:LigerRMSNorm",
        ...
    },

into a nested mapping:

    {
        "RMSNorm": {
            "cuda": {
                Mode.INFERENCE: LayerRepository(
                    repo_id="kernels-community/layer_norm",
                    layer_name="LlamaRMSNorm",
                )
            }
        }
    }

    or for local path:

    {
        "RMSNorm": {
            "cuda": {
                Mode.INFERENCE: LocalLayerRepository(
                    repo_path=Path("/home/user/liger_kernels"),
                    package_name="liger_kernels",
                    layer_name="LigerRMSNorm",
                )
            }
        }
    }

that's compatible with the kernels library.

The device is inferred from the model's parameters if not provided.
The Mode is inferred from the model's training state.
)ModeN)r&   r[   r   r=   rS   trainingTRAINING	INFERENCETORCH_COMPILErQ   rU   r?   r,   r7   rR   )r@   r   compiler[   r*   current_devicer    rW   r)   r(   r   s   &&&        r   create_compatible_mapping&KernelConfig.create_compatible_mapping   s    b 	!%e,"&"5"5";";"=J$)NNN4==D000&#&&"	,,,":yPbc(YVhiFD)))/%F/ 000&z9L^_,ZRde *8 #>* 1r-   r<   )NFr;   )F)__name__
__module____qualname____firstlineno____doc__rA   rF   rN   rX   rb   __static_attributes____classdictcell__)__classdict__s   @r   r9   r9   `   s.     1

M
QlfJ1 J1r-   r9   N)r   r   r   r,   r7   r9    r-   r   <module>rm      s(    #%P"*y1> y1r-   