[kernels] refactor function kernel calling#41577
Merged
Conversation
MekkCyber
commented
Oct 14, 2025
Comment on lines
+235
to
+236
| def lazy_load_kernel(kernel_name: str, mapping: dict[str, Optional[ModuleType]]): | ||
| if kernel_name in mapping and isinstance(mapping[kernel_name], ModuleType): |
Contributor
Author
There was a problem hiding this comment.
the main utility function applied to the case of causal-conv1d
Contributor
Author
|
run-slow: falcon_mamba, mamba |
Contributor
|
This comment contains run-slow, running the specified jobs: models: ['models/falcon_mamba', 'models/mamba'] |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
5 tasks
| raise RuntimeError("register_kernel_mapping requires `kernels` to be installed. Run `pip install kernels`.") | ||
|
|
||
|
|
||
| _KERNEL_SIMPLE_MAPPING: dict[str, str] = { |
Comment on lines
+259
to
+264
| causal_conv1d = lazy_load_kernel("causal-conv1d", _KERNEL_MAPPING_ACROSS_MODELS) | ||
| causal_conv1d_update, causal_conv1d_fn = ( | ||
| (causal_conv1d.causal_conv1d_update, causal_conv1d.causal_conv1d_fn) | ||
| if causal_conv1d is not None | ||
| else (None, None) | ||
| ) |
Collaborator
There was a problem hiding this comment.
we should not need to pass the kernel mapping, lazy load kernel can handle it!
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: falcon_mamba, mamba |
ArthurZucker
approved these changes
Oct 16, 2025
| ALL_MASK_ATTENTION_FUNCTIONS.register(attn_implementation, ALL_MASK_ATTENTION_FUNCTIONS["flash_attention_2"]) | ||
|
|
||
|
|
||
| def lazy_load_kernel(kernel_name: str, mapping: dict[str, Optional[ModuleType]] = _KERNEL_MODULE_MAPPING): |
Collaborator
There was a problem hiding this comment.
should be None, if none default to kernel mapping python will cry otherwise!
Comment on lines
+243
to
+248
| causal_conv1d = lazy_load_kernel("causal-conv1d") | ||
| causal_conv1d_update, causal_conv1d_fn = ( | ||
| (causal_conv1d.causal_conv1d_update, causal_conv1d.causal_conv1d_fn) | ||
| if causal_conv1d is not None | ||
| else (None, None) | ||
| ) |
ngazagna-qc
pushed a commit
to ngazagna-qc/transformers
that referenced
this pull request
Oct 23, 2025
* refactor function kernel callling * nit * don't pass the mapping * use _kernels_available * rm import
SangbumChoi
pushed a commit
to SangbumChoi/transformers
that referenced
this pull request
Jan 23, 2026
* refactor function kernel callling * nit * don't pass the mapping * use _kernels_available * rm import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This should simplify lazy kernel loading in Transformers.
We simply define a mapping between each kernel name and the repository it should be pulled from, then load it using the
lazy_load_kernelfunction. This function adds the kernel to a global cache shared across all models.If the kernel isn’t available, we check whether it’s installed as a module for backward compatibility; otherwise, we return
None.