Skip to content

vllm.v1.worker.gpu.spec_decode.dflash.utils

Functions:

draft_attention_supports_dcp(draft_vllm_config, model_tag)

Whether the MLA draft layers can select an attention backend with DCP.

Runs the same selection as the draft layers, so a draft with no DCP-capable backend can fall back to DCP=1 and a replicated KV cache. Sliding-window drafts always do: their cache cannot shard by DCP, and NIXL pulls such a draft group from a single DCP prefill rank.

Source code in vllm/v1/worker/gpu/spec_decode/dflash/utils.py
def draft_attention_supports_dcp(draft_vllm_config: VllmConfig, model_tag: str) -> bool:
    """Whether the MLA draft layers can select an attention backend with DCP.

    Runs the same selection as the draft layers, so a draft with no DCP-capable
    backend can fall back to DCP=1 and a replicated KV cache. Sliding-window
    drafts always do: their cache cannot shard by DCP, and NIXL pulls such a
    draft group from a single DCP prefill rank.
    """
    from vllm.compilation.backends import set_model_tag
    from vllm.config import set_current_vllm_config
    from vllm.v1.attention.selector import get_attn_backend

    speculative_config = draft_vllm_config.speculative_config
    assert speculative_config is not None
    draft_model_config = speculative_config.draft_model_config
    if (
        not draft_model_config.use_mla
        or getattr(draft_model_config.hf_text_config, "sliding_window", None)
        is not None
    ):
        return False
    try:
        with set_current_vllm_config(draft_vllm_config), set_model_tag(model_tag):
            get_attn_backend(
                draft_model_config.get_head_size(),
                draft_model_config.dtype,
                draft_vllm_config.cache_config.cache_dtype,
                use_mla=True,
                num_heads=draft_model_config.get_num_attention_heads(
                    draft_vllm_config.parallel_config
                ),
            )
    except ValueError:
        return False
    return True