🚨 [Kernels] Refactor all linear attn models & native kernels fallback - #47630
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. |
Cyrilvallez
left a comment
There was a problem hiding this comment.
Very very nice, cannot wait for this PR! Just checked bamba for now to give a few early thoughts!
| # Only kernels can use this shortcircuit, fallback to normal torch otherwise | ||
| if fused_output is not None: | ||
| return fused_output |
There was a problem hiding this comment.
This makes it a bit awkward IMO... Any way to check if the function was found in kernels instead?
There was a problem hiding this comment.
Hard to do because kernels can be swapped at runtime at any time
|
run-slow: mamba, mamba2, falcon_mamba, jamba |
|
This comment contains models: ["models/falcon_mamba", "models/jamba", "models/mamba", "models/mamba2"] |
CI ResultsCommit Info
Model CI Report❌ 1 new failed tests from this PR 😭
|
|
run-slow: falcon_mamba |
|
This comment contains models: ["models/falcon_mamba"] |
|
run-slow: falcon_mamba |
| ' I will be talking about the importance of the internet in our lives.\nThe internet is a global' | ||
| ], | ||
| ("cuda", 9): [ | ||
| ' I am going to talk about the “Theory of Relativity” by Albert Einstein.\n', |
There was a problem hiding this comment.
Not sure what caused the change on A10 but the output is the same across all devices now so I wouldn't see it as a regression as the outputs are aligned. I assumed some small matmul diff causing slightly different gens previously
|
This comment contains models: ["models/falcon_mamba"] |
|
run-slow: bamba, falcon_h1, falcon_mamba, granitemoehybrid, inkling, jamba, lfm2, lfm2_moe, mamba, mamba2, minimax, nemotron_h, olmo_hybrid, qwen3_5, qwen3_5_moe, qwen3_next |
|
This comment contains models: ["models/bamba", "models/falcon_h1", "models/falcon_mamba", "models/granitemoehybrid", "models/inkling", "models/jamba", "models/lfm2", "models/lfm2_moe", "models/mamba", "models/mamba2", "models/minimax", "models/nemotron_h", "models/olmo_hybrid", "models/qwen3_5", "models/qwen3_5_moe", "models/qwen3_next"] |
Cyrilvallez
left a comment
There was a problem hiding this comment.
All right, very nice work! Still a few important details to fix, but should not be much efforts. Most notably:
- Make sure we align the name of the torch functions and kernels function everywhere, as most are not the same. This makes it much harder to understand what we do. Having the same name makes it clear for anyone that it's supposed to do the same thing in pure torch
- Correctly guard all conv parts with
and not record_pastfor speculative decoding/mtp etc, and be coherent between all our implems
| @use_kernel_func_from_hub_with_fallback( | ||
| "mamba_split_conv1d_scan_combined", | ||
| "mamba_ssm", | ||
| ) | ||
| def mamba2_split_conv1d_scan_combined( | ||
| zxbcdt: torch.Tensor, | ||
| conv1d_weight: torch.Tensor, | ||
| conv1d_bias: torch.Tensor | None, | ||
| dt_bias: torch.Tensor, | ||
| A: torch.Tensor, | ||
| D: torch.Tensor, | ||
| chunk_size: int, | ||
| initial_states: torch.Tensor | None = None, | ||
| dt_limit: tuple[float, float] = (0.0, float("inf")), | ||
| return_final_states: bool = False, | ||
| activation: str = "silu", | ||
| rmsnorm_weight: torch.Tensor | None = None, | ||
| rmsnorm_eps: float = 1e-6, | ||
| outproj_weight: torch.Tensor | None = None, | ||
| outproj_bias: torch.Tensor | None = None, | ||
| headdim: int | None = None, | ||
| ngroups: int = 1, | ||
| norm_before_gate: bool = True, | ||
| **kwargs, | ||
| ): | ||
| return None |
There was a problem hiding this comment.
This is still a bit awkward IMO 🥲 We do need to have all the args and kwargs so that kernels can match the signature right? We cannot simply use mamba2_split_conv1d_scan_combined(*args, **kwargs)?
There was a problem hiding this comment.
Yea not possible because we need to match the kernels signature
| class JambaMambaMixer(MambaMixer): | ||
| class JambaMambaMixer(FalconMambaMixer): |
There was a problem hiding this comment.
Is it really better to switch inheritance? Why do we want to add use_mambapy etc?
There was a problem hiding this comment.
The main goal here is to show that it's nearly 1:1 in the forward minus mamba inner fn not being usable
| q, k, v = torch.split( | ||
| mixed_qkv.transpose(1, 2), | ||
| [self.key_dim, self.key_dim, self.value_dim], | ||
| dim=-1, | ||
| ) |
There was a problem hiding this comment.
Humm actually, is it really better to merge them given that we need to cat and split?
There was a problem hiding this comment.
Pretty sure it's worth it, the conv is a bigger limiting factor than the cat and split
(also just easier for our cache in general)
Kernels] Native fallbackKernels] Refactor all mamba's recurrent part & Native kernels fallback
Kernels] Refactor all mamba's recurrent part & Native kernels fallbackKernels] Refactor all mamba models recurrent part & Native kernels fallback
|
[For maintainers] Suggested jobs to run (before merge) run-slow: bamba, falcon_h1, falcon_mamba, granitemoehybrid, inkling, jamba, lfm2, lfm2_moe, mamba, mamba2, minimax, nemotron_h, olmo_hybrid, qwen3_5, qwen3_5_moe, qwen3_next |
Kernels] Refactor all mamba models recurrent part & Native kernels fallbackKernels] Refactor all linear attn models & native kernels fallback
CI recapDashboard: View test results in Grafana |
Cyrilvallez
left a comment
There was a problem hiding this comment.
Alright, let's go now if you're done with all the changes after offline discussion!! Thanks again, super happy to land it and finally have fully clean mambas! 🤗
Tl;dr: Allow kernels, og, and torch only to natively coexist along each other. This is also makes kernels as opt in, not as mandatory which caused very weird behavior where it suddenly took precedence even over the og kernels
Model types
Dependent on
Note:
activation=Noneand manually applying the activation...; act(hidden_states)