Skip to content

vllm.v1.attention.backends.mamba_attn

Classes:

BaseMambaAttentionMetadataBuilder

Bases: AttentionMetadataBuilder[M], ABC

Methods:

_build_chunk_metadata_tensors(chunk_size, common, common_attn_metadata, checkpoint_offsets_p=None)

Compute chunk metadata and return as device tensors. Returns (cu_chunk_seqlen_p, seq_idx_p, last_chunk_indices_p, checkpoint_chunk_idx_p). The last is None unless a row checkpoints; it has one entry per prefill row, holding the logical chunk that ends on the checkpoint, and 0 for rows that decline.

_compute_chunk_metadata(chunk_size, num_prefills, num_computed_tokens_p_cpu, query_start_loc_p_cpu, checkpoint_offsets_p=None) staticmethod

Compute chunk-specific metadata for Mamba models.

The code below carefully constructs the chunks such that: 1. Chunks contain tokens from a single sequence only. 2. Chunk boundaries fall on multiples of chunk_size in each sequence's absolute token positions, so the chunking does not depend on how chunked prefill split the sequence. Constraint (1) dramatically simplifies the mamba kernels.

checkpoint_offsets_p[i] forces an extra chunk end that many tokens into row i's query (0 = none), because the SSD scan only materializes states at chunk ends. Returns its chunk index per row, or -1.

_compute_common_metadata(common_attn_metadata, *, num_accepted_tokens=None, num_decode_draft_tokens_cpu=None)

Compute metadata common to all Mamba-like backends.

_prefill_cpu_metadata(common_attn_metadata, num_reqs, num_prefills, num_decode_tokens)

Prefill context lengths and query offsets, from CPU data only.

seq_lens_cpu_upper_bound is precise for prefill rows in all modes (including async spec decode), so this avoids the D2H sync that compute_num_computed_tokens().cpu() would force.

Returns (num_computed_tokens_p_cpu, query_start_loc_p_cpu).

_update_metadata_for_cudagraph_capture(metadata)

Update the metadata for cudagraph capture. Currently, only decode is supported for full cudagraphs with Mamba.

bind_mrv2_graph_inputs(state_indices, num_accepted_tokens)

Bind compatible MRV2 persistent buffers as full-graph inputs.

build(common_prefix_len, common_attn_metadata, fast_build=False, *, num_accepted_tokens=None, num_decode_draft_tokens_cpu=None, **kwargs)

Default build implementation for Mamba-like attention backends. Subclasses (e.g., Mamba2) can override to add additional metadata.

build_for_cudagraph_capture(common_attn_metadata)

This method builds the metadata for full cudagraph capture. Currently, only decode is supported for full cudagraphs with Mamba.