Skip to content

vllm.models.qwen4_exp.common.qsa

Main-attention metadata shared by the QSA platform implementations.

Classes:

Qwen4ExpQSAMetadataBuilder

Bases: AttentionMetadataBuilder[Qwen4ExpQSAMetadata]

Methods:

  • build –

    Keep cache addresses shared with the current runner batch.

  • update_block_table –

    Reuse batch bounds while replacing cache-group-specific addresses.

  • update_draft_decode_metadata –

    Decode batch bounds stay fixed and addresses reference runner buffers.

Source code in vllm/models/qwen4_exp/common/qsa.py
class Qwen4ExpQSAMetadataBuilder(AttentionMetadataBuilder[Qwen4ExpQSAMetadata]):
    _cudagraph_support: ClassVar[AttentionCGSupport] = AttentionCGSupport.UNIFORM_BATCH
    supports_update_block_table = True
    supports_draft_decode_metadata_update = True

    def __init__(
        self,
        kv_cache_spec: AttentionSpec,
        layer_names: list[str],
        vllm_config: VllmConfig,
        device: torch.device,
    ) -> None:
        super().__init__(kv_cache_spec, layer_names, vllm_config, device)

    def build(
        self,
        common_prefix_len: int,
        common_attn_metadata: CommonAttentionMetadata,
        fast_build: bool = False,
    ) -> Qwen4ExpQSAMetadata:
        """Keep cache addresses shared with the current runner batch."""
        return Qwen4ExpQSAMetadata(
            num_actual_tokens=common_attn_metadata.num_actual_tokens,
            max_query_len=common_attn_metadata.max_query_len,
            block_table=common_attn_metadata.block_table_tensor,
            slot_mapping=common_attn_metadata.slot_mapping,
        )

    def update_block_table(
        self,
        metadata: Qwen4ExpQSAMetadata,
        blk_table: torch.Tensor,
        slot_mapping: torch.Tensor,
    ) -> Qwen4ExpQSAMetadata:
        """Reuse batch bounds while replacing cache-group-specific addresses."""
        return replace(metadata, block_table=blk_table, slot_mapping=slot_mapping)

    def update_draft_decode_metadata(self, metadata: Qwen4ExpQSAMetadata) -> None:
        """Decode batch bounds stay fixed and addresses reference runner buffers."""
        pass

build(common_prefix_len, common_attn_metadata, fast_build=False)

Keep cache addresses shared with the current runner batch.

Source code in vllm/models/qwen4_exp/common/qsa.py
def build(
    self,
    common_prefix_len: int,
    common_attn_metadata: CommonAttentionMetadata,
    fast_build: bool = False,
) -> Qwen4ExpQSAMetadata:
    """Keep cache addresses shared with the current runner batch."""
    return Qwen4ExpQSAMetadata(
        num_actual_tokens=common_attn_metadata.num_actual_tokens,
        max_query_len=common_attn_metadata.max_query_len,
        block_table=common_attn_metadata.block_table_tensor,
        slot_mapping=common_attn_metadata.slot_mapping,
    )

update_block_table(metadata, blk_table, slot_mapping)

Reuse batch bounds while replacing cache-group-specific addresses.

Source code in vllm/models/qwen4_exp/common/qsa.py
def update_block_table(
    self,
    metadata: Qwen4ExpQSAMetadata,
    blk_table: torch.Tensor,
    slot_mapping: torch.Tensor,
) -> Qwen4ExpQSAMetadata:
    """Reuse batch bounds while replacing cache-group-specific addresses."""
    return replace(metadata, block_table=blk_table, slot_mapping=slot_mapping)

update_draft_decode_metadata(metadata)

Decode batch bounds stay fixed and addresses reference runner buffers.

Source code in vllm/models/qwen4_exp/common/qsa.py
def update_draft_decode_metadata(self, metadata: Qwen4ExpQSAMetadata) -> None:
    """Decode batch bounds stay fixed and addresses reference runner buffers."""
    pass