[Perf] [AMD] monokernels: Let a plugin skip per-step attention metadata (#44601)

Co-authored-by: Kevin Mi <kevin.mi@radixark.ai>
Co-authored-by: kkHuang-amd <43161300+kkHuang-amd@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Mi
2026-10-18 14:04:57 +00:00
committed by GitHub
co-authored by Kevin Mi kkHuang-amd Claude Opus 5.5
parent 57db5089c2
commit e9b22a0818
6 changed files with 55 additions and 6 deletions
@@ -107,6 +107,8 @@ from sglang.srt.layers.cp.utils import is_cp_active
from sglang.srt.mem_cache.deepseek_v4_memory_pool import DeepSeekV4TokenToKVPool
from sglang.srt.mem_cache.dsv41_request_window import window_layout
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMode
from sglang.srt.monokernels.runtime import is_metadata_unread
from sglang.srt.monokernels.spec import StepMetadata
from sglang.srt.runtime_context import (
get_exec,
get_parallel,
@@ -907,6 +909,7 @@ class DeepseekV4HipRadixBackend(
speculative_num_steps=0,
):
super().__init__()
self.model_runner = model_runner
self.device = torch.device(model_runner.device)
self.max_context_len = model_runner.model_config.context_len
head_dim = model_runner.model_config.head_dim
@@ -1768,6 +1771,11 @@ class DeepseekV4HipRadixBackend(
if not low_ratio_decode_rows_are_identity(
self, forward_batch, ratio
)
and not is_metadata_unread(
self.model_runner.model,
forward_batch,
StepMetadata.LOW_RATIO_DECODE_SCHEDULE,
)
},
max_context_len=self.max_context_len,
num_requests=forward_batch.batch_size,
+11
View File
@@ -21,6 +21,7 @@ from sglang.srt.monokernels.spec import (
MonoSpec,
Plan,
ShapeKey,
StepMetadata,
find_spec,
spec_registered,
)
@@ -100,6 +101,14 @@ def shape_key(forward_batch: ForwardBatch) -> Optional[ShapeKey]:
return ShapeKey(forward_mode=name, batch_size=bs, tokens_per_request=rows // bs)
def is_metadata_unread(
model: torch.nn.Module, forward_batch: ForwardBatch, metadata: StepMetadata
) -> bool:
"""Whether the monokernel forward that runs this step never reads the metadata."""
served, unread = model.__dict__.get("_monokernel_unread_metadata", ((), ()))
return metadata in unread and shape_key(forward_batch) in served
def install_monokernel_forward(
*,
model: torch.nn.Module,
@@ -340,6 +349,8 @@ def _install_forward(
return built.forward(Plan(key=key), *args, **kwargs)
model.forward = forward
# attention backends ask is_metadata_unread before building per-step metadata
model._monokernel_unread_metadata = (served, spec.unread_metadata)
def _format_steps(keys: Iterable[ShapeKey]) -> str:
+8
View File
@@ -40,6 +40,12 @@ class Feature(enum.Enum):
PARTITIONED_GPU = "partitioned GPUs"
class StepMetadata(enum.Enum):
"""Per-step attention metadata a backend can skip building."""
LOW_RATIO_DECODE_SCHEDULE = "the aiter decode schedule of each low-ratio indexer"
class DeviceLimits(msgspec.Struct, frozen=True):
"""What a spec's kernels support on one ISA, e.g. gfx950."""
@@ -153,6 +159,8 @@ class MonoSpec(msgspec.Struct, frozen=True):
] = None
# (model) -> tokens per request when different from the target, e.g. draft blocks
tokens_per_request: Optional[Callable[[torch.nn.Module], int]] = None
# per-step metadata the forward never reads; backends skip it on routed steps
unread_metadata: frozenset[StepMetadata] = frozenset()
def widths(self, isa: str) -> tuple[int, ...]:
return self.devices[isa].widths