vllm.model_executor.layers.mamba.mamba_utils
¶
Classes:
-
MambaCopySpec–Data class specifying the memory-copy parameters for Mamba states used for
-
MambaStateDtypeCalculator– -
MambaStateShapeCalculator–
Functions:
-
get_conv_copy_spec–Return a MambaCopySpec for copying a convolutional state slice.
-
get_conv_state_layout–Return the SSM conv state layout.
-
get_temporal_copy_spec–Return a MambaCopySpec for copying a temporal state slice.
-
is_conv_state_dim_first–True when the conv state is stored as (dim, state_len) per block.
Attributes:
-
MambaStateCopyFunc(TypeAlias) –Type alias for a function that computes a MambaCopySpec for copying state slices.
MambaStateCopyFunc = Callable[[torch.Tensor, list[int], int, int], MambaCopySpec]
module-attribute
¶
Type alias for a function that computes a MambaCopySpec for copying state slices.
Parameters:
state: torch.Tensor - the Mamba state tensor (e.g., conv or temporal states).
block_ids: list[int] - the list of block indices for the state to copy.
cur_block_idx: int - current block index within block_ids to copy from.
num_accepted_tokens: int - number of accepted tokens used to compute the copy offset.
Range: 1 .. 1 + num_speculative_tokens (inclusive).
MambaCopySpec
dataclass
¶
MambaStateDtypeCalculator
¶
Methods:
-
append_replayssm_ring–Append the ReplaySSM ring dtypes to a base
(conv, ssm)tuple: -
gated_delta_net_state_dtype–(conv, ssm), plus the ReplaySSM(d, k, g)rings when enabled.
append_replayssm_ring(base_dtypes, model_dtype)
classmethod
¶
Append the ReplaySSM ring dtypes to a base (conv, ssm) tuple:
(x_cache, dt_cache, B_cache) = (activation, fp32, activation).
gated_delta_net_state_dtype(model_dtype, mamba_cache_dtype, mamba_ssm_cache_dtype='auto', use_replayssm=False)
classmethod
¶
(conv, ssm), plus the ReplaySSM (d, k, g) rings when enabled.
The d/k rings use fp16 for bf16 activations; g is float32.
MambaStateShapeCalculator
¶
Methods:
-
append_replayssm_ring–Append the physical ReplaySSM ring shapes.
-
extra_groups_for_head_shards–Compute the increase in group numbers to account for
-
gated_delta_net_state_shape–Append the ReplaySSM rings of length
replayssm_buffer_lenwhen
_orient_conv_shape(dim, state_len)
staticmethod
¶
Return (dim, state_len) for DS layout, (state_len, dim) for SD.
append_replayssm_ring(base_shapes, n_groups, tp_world_size, logical_window, backend, num_speculative_tokens=0)
classmethod
¶
Append the physical ReplaySSM ring shapes.
base_shapes[1] is (nheads // tp, head_dim, state_size);
B_cache extends n_groups for head shards as in mamba2_state_shape.
extra_groups_for_head_shards(ngroups, tp_size)
classmethod
¶
Compute the increase in group numbers to account for replication in order to accompany the head shards.
gated_delta_net_state_shape(tp_world_size, num_k_heads, num_v_heads, head_k_dim, head_v_dim, conv_kernel_size, num_spec=0, replayssm_buffer_len=None)
classmethod
¶
Append the ReplaySSM rings of length replayssm_buffer_len when
it is set.
get_conv_copy_spec(state, block_ids, cur_block_idx, num_accepted_tokens)
¶
Return a MambaCopySpec for copying a convolutional state slice.
Works for both SD layout (num_blocks, state_len, dim) and
DS layout (num_blocks, dim, state_len).
get_conv_state_layout()
cached
¶
Return the SSM conv state layout.
SD = (state_len, dim) — dim is the innermost contiguous dimension. DS = (dim, state_len) — TP-sharded dim is on dim-1 (like HND for KV cache), consistent with SSM temporal state layout.
get_temporal_copy_spec(state, block_ids, cur_block_idx, num_accepted_tokens)
¶
Return a MambaCopySpec for copying a temporal state slice.
is_conv_state_dim_first()
¶
True when the conv state is stored as (dim, state_len) per block.