Transformers documentation
Kernels
Kernels
This page documents the kernels configuration utilities.
KernelConfig
Kernel configuration class. This class is used to configure the kernel mapping for a model.
Transforms a simple kernel_mapping of the form: { “RMSNorm”: “kernels-community/layer_norm:LlamaRMSNorm”, … },
or
{ “RMSNorm”: { “cuda”: “kernels-community/layer_norm:LlamaRMSNorm”, “rocm”: “kernels-community/layer_norm:LlamaRMSNorm”, … }, … }
into a nested mapping:
{ “RMSNorm”: { “cuda”: { Mode.INFERENCE: LayerRepository( repo_id=“kernels-community/layer_norm”, layer_name=“LlamaRMSNorm”, ) } } }
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.
sanitize_kernel_mapping
< source >( model )
Validates the kernel_mapping to ensure that:
- Each layer_name in the mapping is registered in the model (i.e., the model contains a module with a matching kernel_layer_name).
- Each kernel value is either a string of the form ‘org/repo:layer_name’ or a dict mapping device types (“cuda”, “rocm”, “xpu”) to such strings.
- Each device key in a dict is one of “cuda”, “rocm”, or “xpu”.
- 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).