vllm.model_executor.layers.mamba.mamba_utils ¶
MambaStateCopyFunc 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 ¶
Data class specifying the memory-copy parameters for Mamba states used for prefix caching in align mode.
Attributes:
| Name | Type | Description |
|---|---|---|
start_addr | int | Starting address for the memory copy operation. |
num_elements | int | Number of elements to copy from the starting address. |
Source code in vllm/model_executor/layers/mamba/mamba_utils.py
MambaStateShapeCalculator ¶
Source code in vllm/model_executor/layers/mamba/mamba_utils.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
_orient_conv_shape staticmethod ¶
Return (dim, state_len) for DS layout, (state_len, dim) for SD.
Source code in vllm/model_executor/layers/mamba/mamba_utils.py
extra_groups_for_head_shards classmethod ¶
Compute the increase in group numbers to account for replication in order to accompany the head shards.
Source code in vllm/model_executor/layers/mamba/mamba_utils.py
get_conv_copy_spec ¶
get_conv_copy_spec(
state: Tensor,
block_ids: list[int],
cur_block_idx: int,
num_accepted_tokens: int,
) -> MambaCopySpec
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).
Source code in vllm/model_executor/layers/mamba/mamba_utils.py
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.
Source code in vllm/model_executor/layers/mamba/mamba_utils.py
get_temporal_copy_spec ¶
get_temporal_copy_spec(
state: Tensor,
block_ids: list[int],
cur_block_idx: int,
num_accepted_tokens: int,
) -> MambaCopySpec
Return a MambaCopySpec for copying a temporal state slice.