vllm.v1.attention.backends.mamba2_attn ¶
Mamba2AttentionBackend ¶
Bases: AttentionBackend
Source code in vllm/v1/attention/backends/mamba2_attn.py
Mamba2AttentionMetadata dataclass ¶
Source code in vllm/v1/attention/backends/mamba2_attn.py
token_chunk_offset_ptr class-attribute instance-attribute ¶
__init__ ¶
__init__(
num_prefills: int,
num_prefill_tokens: int,
num_decodes: int,
num_decode_tokens: int,
query_start_loc_p: Tensor,
seq_lens: Tensor,
prep_initial_states: bool,
chunk_size: int,
has_initial_states_p: Optional[Tensor],
seq_idx_p: Optional[Tensor],
cu_chunk_seqlen_p: Optional[Tensor],
last_chunk_indices_p: Optional[Tensor],
state_indices_tensor: Tensor,
nums_dict: Optional[dict] = None,
batch_ptr: Optional[Tensor] = None,
token_chunk_offset_ptr: Optional[Tensor] = None,
) -> None
Mamba2AttentionMetadataBuilder ¶
Bases: BaseMambaAttentionMetadataBuilder[Mamba2AttentionMetadata]
Source code in vllm/v1/attention/backends/mamba2_attn.py
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 271 272 273 | |
__init__ ¶
__init__(
kv_cache_spec: AttentionSpec,
layer_names: list[str],
vllm_config: VllmConfig,
device: device,
)
Source code in vllm/v1/attention/backends/mamba2_attn.py
build ¶
build(
common_prefix_len: int,
common_attn_metadata: CommonAttentionMetadata,
fast_build: bool = False,
) -> Mamba2AttentionMetadata
Source code in vllm/v1/attention/backends/mamba2_attn.py
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 271 272 273 | |
compute_varlen_chunk_metadata ¶
compute_varlen_chunk_metadata(
query_start_loc: Tensor, chunk_size: int
) -> tuple[Tensor, Tensor, Tensor]
Build chunk-aligned, variable-length metadata used by Mamba2 SSD kernels.
Given per-sequence cumulative token starts query_start_loc of shape [B+1] and a physical chunk_size, returns three tensors on the same device: - cu_chunk_seqlens: (nchunks+1,) int32 exclusive prefix-sum of logical-chunk lengths (each logical chunk never crosses a sequence or physical-chunk boundary). - last_chunk_indices: (B,) int32 index of the last logical chunk for each sequence (=-1 for empty sequences). - seq_idx_chunks: (nchunks,) int32 sequence index for each logical chunk in order.
This is intentionally lightweight and CPU-side; it mirrors the metadata produced by the V1 Mamba2 meta-data builder and is exported so tests (and other callers) can avoid duplicating the logic.