Skip to content

vllm.model_executor.models.extract_hidden_states

Hidden States Extractor Model.

This model extracts and caches hidden states from the target model without performing actual token generation. It's used with the extract_hidden_states speculative decoding method.

Classes:

Functions:

CacheOnlyAttentionBackend

Bases: AttentionBackend

Attention backend that only caches KV without computing attention.

CacheOnlyAttentionImpl

Bases: AttentionImpl

Attention implementation that only caches KV states.

CacheOnlyAttentionLayer

Bases: Module, AttentionLayerBase

Attention layer that only caches key/value states without computing attention.

Methods:

  • forward –

    Cache hidden states as KV pairs without computing attention.

forward(to_cache)

Cache hidden states as KV pairs without computing attention.

Parameters:

  • to_cache

    (Tensor) –

    The tensor to insert into the kv cache. shape [num_tokens, num_heads, head_size]

Returns:

  • Tensor –

    Dummy output tensor (not used)

ExtractHiddenStatesModel

Bases: Module

Methods:

  • forward –

    Process and cache hidden states.

  • load_weights –

    No weights to load for this dummy model.

forward(hidden_states)

Process and cache hidden states.

Parameters:

  • hidden_states

    (Tensor) –

    Hidden states from target model shape: [num_tokens, num_hidden_states, hidden_size]

Returns:

  • None –

    Tuple of (dummy_output, dummy_output) - both unused

load_weights(weights)

No weights to load for this dummy model.

unified_kv_cache_update(to_cache, layer_name)

Returns a dummy that is passed to unified_attention to signal a side effect and the data dependency between them to ensure torch.compile preserves ordering.