[DLLM] Add initial cuda graph support (#14203)
This commit is contained in:
@@ -40,6 +40,7 @@ from sglang.srt.distributed.parallel_state import (
|
||||
graph_capture,
|
||||
set_pdmux_status,
|
||||
)
|
||||
from sglang.srt.dllm.config import DllmConfig
|
||||
from sglang.srt.layers.attention.nsa.utils import is_nsa_enable_prefill_cp
|
||||
from sglang.srt.layers.dp_attention import (
|
||||
DpPaddingMode,
|
||||
@@ -263,6 +264,9 @@ class CudaGraphRunner:
|
||||
|
||||
self.deepep_adapter = DeepEPCudaGraphRunnerAdapter()
|
||||
|
||||
self.dllm_config = DllmConfig.from_server_args(model_runner.server_args)
|
||||
self.is_dllm = self.dllm_config is not None
|
||||
|
||||
# Batch sizes to capture
|
||||
self.capture_bs, self.compile_bs = get_batch_sizes_to_capture(model_runner)
|
||||
log_info_on_rank0(logger, f"Capture cuda graph bs {self.capture_bs}")
|
||||
@@ -283,6 +287,9 @@ class CudaGraphRunner:
|
||||
self.num_tokens_per_bs = (
|
||||
self.model_runner.server_args.speculative_num_draft_tokens
|
||||
)
|
||||
elif self.is_dllm:
|
||||
self.capture_forward_mode = ForwardMode.DLLM_EXTEND
|
||||
self.num_tokens_per_bs = self.dllm_config.block_size
|
||||
|
||||
# If returning hidden states is enabled, set initial capture hidden mode to full to avoid double-capture on startup
|
||||
if model_runner.server_args.enable_return_hidden_states:
|
||||
@@ -299,6 +306,8 @@ class CudaGraphRunner:
|
||||
self.maybe_init_pdmux()
|
||||
self.seq_len_fill_value = (
|
||||
self.model_runner.attn_backend.get_cuda_graph_seq_len_fill_value()
|
||||
if self.dllm_config is None
|
||||
else self.dllm_config.block_size
|
||||
)
|
||||
|
||||
self.encoder_len_fill_value = 0
|
||||
@@ -825,7 +834,14 @@ class CudaGraphRunner:
|
||||
output = self.output_buffers[graph_key]
|
||||
if isinstance(output, LogitsProcessorOutput):
|
||||
return LogitsProcessorOutput(
|
||||
next_token_logits=output.next_token_logits[: self.raw_num_token],
|
||||
next_token_logits=(
|
||||
output.next_token_logits[: self.raw_num_token]
|
||||
if not self.is_dllm
|
||||
else None
|
||||
),
|
||||
full_logits=(
|
||||
output.full_logits[: self.raw_num_token] if self.is_dllm else None
|
||||
),
|
||||
hidden_states=(
|
||||
output.hidden_states[: self.raw_num_token]
|
||||
if output.hidden_states is not None
|
||||
|
||||
@@ -91,6 +91,9 @@ class ForwardMode(IntEnum):
|
||||
# Split Prefill for PD multiplexing
|
||||
SPLIT_PREFILL = auto()
|
||||
|
||||
# Used in diffusion LLM inference
|
||||
DLLM_EXTEND = auto()
|
||||
|
||||
def is_prefill(self):
|
||||
return self.is_extend()
|
||||
|
||||
@@ -102,6 +105,7 @@ class ForwardMode(IntEnum):
|
||||
or (include_draft_extend_v2 and self == ForwardMode.DRAFT_EXTEND_V2)
|
||||
or self == ForwardMode.TARGET_VERIFY
|
||||
or self == ForwardMode.SPLIT_PREFILL
|
||||
or self == ForwardMode.DLLM_EXTEND
|
||||
)
|
||||
|
||||
def is_context_parallel_extend(self, include_draft_extend_v2: bool = False):
|
||||
@@ -153,6 +157,7 @@ class ForwardMode(IntEnum):
|
||||
self == ForwardMode.DECODE
|
||||
or self == ForwardMode.TARGET_VERIFY
|
||||
or self == ForwardMode.IDLE
|
||||
or self == ForwardMode.DLLM_EXTEND
|
||||
)
|
||||
|
||||
def is_cpu_graph(self):
|
||||
@@ -171,6 +176,9 @@ class ForwardMode(IntEnum):
|
||||
def is_prebuilt(self):
|
||||
return self == ForwardMode.PREBUILT
|
||||
|
||||
def is_dllm_extend(self):
|
||||
return self == ForwardMode.DLLM_EXTEND
|
||||
|
||||
|
||||
@total_ordering
|
||||
class CaptureHiddenMode(IntEnum):
|
||||
@@ -442,8 +450,9 @@ class ForwardBatch:
|
||||
block_size = batch.dllm_config.block_size
|
||||
ret.positions = torch.tensor(
|
||||
[
|
||||
[i for i in range(block_offset, block_offset + block_size)]
|
||||
i
|
||||
for block_offset in batch.dllm_block_offsets
|
||||
for i in range(block_offset, block_offset + block_size)
|
||||
],
|
||||
dtype=torch.int32,
|
||||
).to(device, non_blocking=True)
|
||||
|
||||
Reference in New Issue
Block a user