[DSv4 Perf] Skip empty c128 kernel launch, around 2x kernel performance improvement. (#48957)
Signed-off-by: yewentao256 <zhyanwentao@126.com>
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import Any, ClassVar, cast
|
||||
import torch
|
||||
from torch import nn
|
||||
|
||||
from vllm.config import VllmConfig, get_current_vllm_config
|
||||
from vllm.config import CUDAGraphMode, VllmConfig, get_current_vllm_config
|
||||
from vllm.forward_context import get_forward_context
|
||||
from vllm.model_executor.layers.attention_layer_base import AttentionLayerBase
|
||||
from vllm.model_executor.layers.layernorm import RMSNorm
|
||||
@@ -42,6 +42,19 @@ def _prefer_two_stage_compressor() -> bool:
|
||||
return current_platform.is_rocm()
|
||||
|
||||
|
||||
def _get_c128_boundary(metadata: CommonAttentionMetadata) -> bool | None:
|
||||
starts = metadata._num_computed_tokens_cpu
|
||||
if starts is None:
|
||||
return None
|
||||
|
||||
starts_list = starts.tolist()
|
||||
query_start_loc = metadata.query_start_loc_cpu.tolist()
|
||||
return any(
|
||||
start % 128 + query_start_loc[i + 1] - query_start_loc[i] >= 128
|
||||
for i, start in enumerate(starts_list)
|
||||
)
|
||||
|
||||
|
||||
class CompressorBackend(AttentionBackend):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -90,6 +103,7 @@ class CompressorMetadata:
|
||||
|
||||
token_to_req_indices: torch.Tensor | None = None # [num_tokens]
|
||||
num_decode_tokens: int | None = None
|
||||
c128_boundary: bool | None = None
|
||||
|
||||
|
||||
class CompressorMetadataBuilder(AttentionMetadataBuilder):
|
||||
@@ -127,6 +141,11 @@ class CompressorMetadataBuilder(AttentionMetadataBuilder):
|
||||
block_size=self.block_size,
|
||||
token_to_req_indices=token_to_req_indices,
|
||||
num_decode_tokens=num_decode_tokens,
|
||||
c128_boundary=(
|
||||
_get_c128_boundary(common_attn_metadata)
|
||||
if self.block_size == 8
|
||||
else None
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -317,7 +336,8 @@ class DeepseekCompressor(nn.Module):
|
||||
)
|
||||
|
||||
# Get the metadata and handle dummy profiling run.
|
||||
attn_metadata = get_forward_context().attn_metadata
|
||||
forward_context = get_forward_context()
|
||||
attn_metadata = forward_context.attn_metadata
|
||||
if not isinstance(attn_metadata, dict):
|
||||
return
|
||||
|
||||
@@ -359,6 +379,16 @@ class DeepseekCompressor(nn.Module):
|
||||
pdl_kwargs=pdl_kwargs,
|
||||
)
|
||||
|
||||
# full graph cannot branch on per-step CPU metadata after capture
|
||||
if (
|
||||
current_platform.is_cuda()
|
||||
and self.head_dim == 512
|
||||
and self.compress_ratio == 128
|
||||
and forward_context.cudagraph_runtime_mode != CUDAGraphMode.FULL
|
||||
and state_metadata.c128_boundary is False
|
||||
):
|
||||
return
|
||||
|
||||
# Fused: compress → RMSNorm → RoPE → FP8 quant → KV cache write.
|
||||
# RoPE requirements (kernel applies forward GPT-J style rotation):
|
||||
# - is_neox_style=False (interleaved pairs, NOT split-half)
|
||||
|
||||
Reference in New Issue
Block a user