@@ -116,30 +116,6 @@ def causal_conv1d_fn(
116116 return out .to (hidden_states .dtype )
117117
118118
119- @use_kernel_func_from_hub_with_fallback ("mamba_inner_fn" , "mamba_ssm" )
120- def mamba_inner_fn (
121- xz : torch .Tensor ,
122- conv1d_weight : torch .Tensor ,
123- conv1d_bias : torch .Tensor | None ,
124- x_proj_weight : torch .Tensor ,
125- delta_proj_weight : torch .Tensor ,
126- out_proj_weight : torch .Tensor ,
127- out_proj_bias : torch .Tensor | None ,
128- A : torch .Tensor ,
129- B : torch .Tensor | None = None ,
130- C : torch .Tensor | None = None ,
131- D : torch .Tensor | None = None ,
132- delta_bias : torch .Tensor | None = None ,
133- delta_softplus : bool = True ,
134- b_rms_weight : torch .Tensor | None = None ,
135- c_rms_weight : torch .Tensor | None = None ,
136- dt_rms_weight : torch .Tensor | None = None ,
137- b_c_dt_rms_eps : float = 1e-6 ,
138- ** kwargs ,
139- ):
140- return None
141-
142-
143119@use_kernel_func_from_hub_with_fallback ("selective_state_update" , "mamba_ssm" )
144120def mamba_selective_state_update (
145121 state : torch .Tensor ,
@@ -294,15 +270,16 @@ def combine_fn(left, right):
294270 return scan_output
295271
296272
297- @use_kernelized_func (
298- [mamba_inner_fn , mamba_selective_scan , mamba_selective_state_update , causal_conv1d_fn , causal_conv1d_update ]
299- )
273+ @use_kernelized_func ([mamba_selective_scan , mamba_selective_state_update , causal_conv1d_fn , causal_conv1d_update ])
300274class FalconMambaMixer (nn .Module ):
301275 """
302276 Compute ∆, A, B, C, and D the state space parameters and compute the `contextualized_states`.
303- A, D are input independent (see FalconMamba paper [1] Section 3.5.2 "Interpretation of A" for why A isn't selective)
304- ∆, B, C are input-dependent (this is a key difference between FalconMamba and the linear time invariant S4,
305- and is why FalconMamba is called **selective** state spaces)
277+ A, D are input independent (see Mamba paper [1] Section 3.5.2 "Interpretation of A" for why A isn't selective)
278+ ∆, B, C are input-dependent (this is a key difference between Mamba and the linear time invariant S4,
279+ and is why Mamba is called **selective** state spaces)
280+
281+ NOTE: unlike Mamba, there is no fused `mamba_inner_fn` path: it can only normalize dt after `dt_proj`, while
282+ FalconMamba normalizes it before, see https://github.com/huggingface/transformers/pull/51184
306283 """
307284
308285 def __init__ (self , config : FalconMambaConfig , layer_idx : int , initialize_mixer_weights : bool = True ):
@@ -401,32 +378,6 @@ def forward(
401378 projected_states = self .in_proj (hidden_states ).transpose (1 , 2 )
402379
403380 A = - torch .exp (self .A_log .float ())
404- if self .training and cache is None :
405- fused_output = mamba_inner_fn (
406- projected_states ,
407- self .conv1d .weight ,
408- self .conv1d .bias if self .use_conv_bias else None ,
409- self .x_proj .weight ,
410- self .dt_proj .weight ,
411- self .out_proj .weight ,
412- self .out_proj .bias .float () if self .use_bias else None ,
413- A ,
414- None , # input-dependent B
415- None , # input-dependent C
416- self .D .float (),
417- delta_bias = self .dt_proj .bias .float (),
418- delta_softplus = True ,
419- # Key difference: norms on B, C, and dt
420- b_rms_weight = self .b_layernorm .weight ,
421- c_rms_weight = self .c_layernorm .weight ,
422- dt_rms_weight = self .dt_layernorm .weight ,
423- b_c_dt_rms_eps = self .rms_eps ,
424- )
425-
426- # Only kernels can use this shortcircuit, fallback to normal torch otherwise
427- if fused_output is not None :
428- return fused_output
429-
430381 hidden_states_B_C , gate = projected_states .chunk (2 , dim = 1 )
431382
432383 # 2. Convolution sequence transformation
0 commit comments