[Attention] Add CuTe DSL backend selection for MLA context prefill (#62069)
Signed-off-by: Wei Zhao <51183510+wzhao18@users.noreply.github.com> Signed-off-by: wzhao18 <wzhao18.sz@gmail.com>
This commit is contained in:
@@ -22,6 +22,17 @@ if TYPE_CHECKING:
|
||||
from vllm.platforms.interface import DeviceCapability
|
||||
|
||||
|
||||
def is_cute_dsl_mla_prefill_supported(
|
||||
qk_head_dim: int, v_head_dim: int, query_dtype: torch.dtype
|
||||
) -> bool:
|
||||
# FlashInfer has no public compatibility API; replace these checks when available.
|
||||
return (
|
||||
query_dtype in (torch.float16, torch.bfloat16, torch.float8_e4m3fn)
|
||||
and (qk_head_dim, v_head_dim) in ((128, 128), (192, 128))
|
||||
and (qk_head_dim != 192 or query_dtype == torch.float8_e4m3fn)
|
||||
)
|
||||
|
||||
|
||||
class TrtllmRaggedPrefillBackend(MLAPrefillBackend):
|
||||
"""TRT-LLM Ragged backend for MLA prefill."""
|
||||
|
||||
@@ -79,6 +90,7 @@ class TrtllmRaggedPrefillBackend(MLAPrefillBackend):
|
||||
v_head_dim=v_head_dim,
|
||||
vllm_config=vllm_config,
|
||||
)
|
||||
self._context_backend = vllm_config.attention_config.trtllm_ragged_backend
|
||||
self._workspace_spec = (
|
||||
(envs.VLLM_FLASHINFER_WORKSPACE_BUFFER_SIZE,),
|
||||
torch.uint8,
|
||||
@@ -198,6 +210,16 @@ class TrtllmRaggedPrefillBackend(MLAPrefillBackend):
|
||||
"TRTLLM ragged context prefill contains an empty query or KV row"
|
||||
)
|
||||
|
||||
if self._context_backend == "cute-dsl":
|
||||
if not is_cute_dsl_mla_prefill_supported(q.shape[-1], v.shape[-1], q.dtype):
|
||||
raise ValueError(
|
||||
"CuTe DSL context prefill does not support "
|
||||
f"Q/K head dimension {q.shape[-1]}, "
|
||||
f"V head dimension {v.shape[-1]}, and query dtype {q.dtype}."
|
||||
)
|
||||
# Generic MLA supplies V as a projection slice; CuTe requires packed V.
|
||||
v = v.contiguous()
|
||||
|
||||
if out is None:
|
||||
out = torch.empty(
|
||||
q.shape[0],
|
||||
@@ -225,6 +247,7 @@ class TrtllmRaggedPrefillBackend(MLAPrefillBackend):
|
||||
cum_seq_lens_kv=chunk.cu_seq_lens,
|
||||
enable_pdl=False,
|
||||
is_causal=False,
|
||||
backend=self._context_backend,
|
||||
return_lse=True,
|
||||
out=out,
|
||||
skip_all_rows_active_check=True,
|
||||
|
||||
Reference in New Issue
Block a user