Kernel native causal_conv1d functions#47294
Conversation
|
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. |
vasqu
left a comment
There was a problem hiding this comment.
Ok I remember why this is a bit more complicated, see especially my last comment. The first is about functionality
We might need a wrapper around use_kernel_func_from_hub along use_kernel_func_from_hub_with_fallback that allows to use the original package as another fallback. But we would need
- Mandatory kernels install - which we will do
- This new wrapper that forces the exchange when the og is installed
- ^ unsure where to support because the registration path for kernels is a bit weird for functions so it probably needs to invoke a forced kernelize only for these kind of functions
| return core_attn_out, last_recurrent_state | ||
|
|
||
|
|
||
| class Qwen3NextGatedDeltaNet(nn.Module): |
There was a problem hiding this comment.
We need
| @use_kernelized_func([causal_conv1d_update, causal_conv1d_fn]) | |
| class Qwen3NextGatedDeltaNet(nn.Module): |
here as it otherwise won't use them / kernelize it properly. It's always a bit weird with functions and kernels
| self.causal_conv1d_fn = causal_conv1d_fn | ||
| self.causal_conv1d_update = causal_conv1d_update or torch_causal_conv1d_update |
There was a problem hiding this comment.
Ok I think I remember why this is a bit more complicated: With this, we will only support torch only and using kernels but not the original package anymore. So users that installed causal-conv1d would no longer use the fast path - imo it's a mistake from the past that we not directly switched to kernels
For this we have (see mamba2)
transformers/src/transformers/models/mamba2/modeling_mamba2.py
Lines 187 to 202 in 35bb43e
So lazy-loaded kernels would use fallbacks to their original package (
resolve_internal_import gives the past in the original package / full path if not exposed on top init)
| return decorator | ||
|
|
||
|
|
||
| def replace_with_function_from_package(function_name: str, package: str): |
There was a problem hiding this comment.
Ah ok I see the approach now, yea definitely will be working regardless of the next decorator then 🤔
My only worry is that some functions are not exposed on top init, e.g. see the mamba resolve internal path. Which means it won't properly work in those cases then. It's super annoying but we have to pass it imo
There was a problem hiding this comment.
Other question: if we exchange here, wouldnt it also change the signature and kernelize wouldn't work anymore. Would be interested to see what happens on the interaction of having both kernels installed and the og package
|
It's getting complicated, we may revisit later but the interaction between og, kernels, and torch is akward |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: qwen3_5, qwen3_5_moe, qwen3_next |
| self.conv1d.bias, | ||
| activation=self.activation, | ||
| seq_idx=kwargs.get("seq_idx"), | ||
| ) |
There was a problem hiding this comment.
Would only change this to use more kwargs but otherwise should stay the same
CI recapDashboard: View test results in Grafana |
What does this PR do?
As per the title. This makes
causal_conv1d_fnandcausal_conv1d_updatekernels native! Needs to be extended to all models using them, but just for qwen to unblock me for nowcc @vasqu