diff --git a/python/sglang/srt/models/lfm2.py b/python/sglang/srt/models/lfm2.py index 3694e32fa..2750a0f81 100644 --- a/python/sglang/srt/models/lfm2.py +++ b/python/sglang/srt/models/lfm2.py @@ -302,11 +302,13 @@ class Lfm2ShortConv(nn.Module): ] ) cache_indices = mamba_indices.to(torch.int32) + has_initial_state = forward_batch.extend_prefix_lens > 0 else: query_start_loc = torch.tensor( [0, T], dtype=torch.int32, device=hidden_states.device ) cache_indices = mamba_indices[:1].to(torch.int32) + has_initial_state = forward_batch.extend_prefix_lens[:1] > 0 conv_out = causal_conv1d_fn( Bx_t, @@ -314,7 +316,7 @@ class Lfm2ShortConv(nn.Module): self.conv_bias, query_start_loc=query_start_loc, cache_indices=cache_indices, - has_initial_state=None, + has_initial_state=has_initial_state, conv_states=conv_state, activation=None, ).transpose(0, 1) diff --git a/python/sglang/srt/models/lfm2_moe.py b/python/sglang/srt/models/lfm2_moe.py index 4c7d5d06d..fcc396357 100644 --- a/python/sglang/srt/models/lfm2_moe.py +++ b/python/sglang/srt/models/lfm2_moe.py @@ -360,10 +360,12 @@ class Lfm2MoeShortConv(nn.Module): query_start_loc[:-1] = extend_start_loc query_start_loc[-1] = T cache_indices = mamba_indices.to(torch.int32) + has_initial_state = forward_batch.extend_prefix_lens > 0 else: # Single sequence: [0, T] query_start_loc = hidden_states.new_tensor([0, T], dtype=torch.int32) cache_indices = mamba_indices[:1].to(torch.int32) + has_initial_state = forward_batch.extend_prefix_lens[:1] > 0 conv_out = causal_conv1d_fn( Bx_t, @@ -371,7 +373,7 @@ class Lfm2MoeShortConv(nn.Module): self.conv_bias, query_start_loc=query_start_loc, cache_indices=cache_indices, - has_initial_state=None, + has_initial_state=has_initial_state, conv_states=conv_state, activation=None, ).transpose(0, 1)