Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,10 @@ def _fn(fb, _ctx):
def _pp_source(key):
def _fn(_fb, ctx):
ppx = ctx.pp_proxy_tensors
return None if ppx is None else ppx.tensors[key]
# .get(): a proxy entry can be absent (e.g. topk_indices
# when a DSA model runs a dense attention backend);
# returning None skips the copy for that slot.
return None if ppx is None else ppx.tensors.get(key)

return _fn

Expand Down
9 changes: 7 additions & 2 deletions python/sglang/srt/model_executor/runner/base_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ def _allocate_decode_buffers(
# mHC (e.g. DSV4) flattens residual into hidden_states (size = hc_hidden_size).
is_mhc = hc_hidden_size is not None
hs = hc_hidden_size if is_mhc else hidden_size
# Sized in tokens, not requests: under speculative decoding the
# verify forward carries num_tokens_per_bs tokens per request and
# _dummy_run slices these buffers to num_tokens (same as
# topk_indices below). Identical for plain decode where
# num_tokens_per_bs == 1.
pp_proxy_tensors = {
"hidden_states": torch.zeros((max_bs, hs), dtype=dtype),
"hidden_states": torch.zeros((max_num_token, hs), dtype=dtype),
}
if not is_mhc:
pp_proxy_tensors["residual"] = torch.zeros(
(max_bs, hidden_size), dtype=dtype
(max_num_token, hidden_size), dtype=dtype
)
if pp_proxy_topk_size is not None:
pp_proxy_tensors["topk_indices"] = torch.zeros(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,19 @@ def load_batch(
# In speculative decoding, these two fields are still needed.
self.buffers.input_ids[: self.raw_num_token].copy_(forward_batch.input_ids)
self.buffers.positions[: self.raw_num_token].copy_(forward_batch.positions)
if (
pp_proxy_tensors is not None
and self.buffers.pp_proxy_tensors is not None
):
# PP + spec verify: the pre-planned load ran without the proxy
# (eagle_prepare_for_verify has no access to it), so the
# graph's proxy input buffers must be refreshed here -- the
# captured graph reads these rows (mirrors fill_from's
# side-slot copy).
for k, v in pp_proxy_tensors.tensors.items():
buf = self.buffers.pp_proxy_tensors.get(k)
if buf is not None: # skip markers like __msg_type__
buf[: v.shape[0]].copy_(v)
if (
self.model_runner.spec_algorithm.is_dflash()
and self.model_runner.is_draft_worker
Expand Down Expand Up @@ -1056,7 +1069,15 @@ def execute(
)
else:
assert isinstance(output, PPProxyTensors)
return PPProxyTensors({k: v[: self.bs] for k, v in output.tensors.items()})
# Slice in token rows, not request rows: under speculative verify
# each request carries num_tokens_per_bs tokens (identical for
# plain decode, where num_tokens_per_bs == 1).
return PPProxyTensors(
{
k: v[: self.bs * self.num_tokens_per_bs]
for k, v in output.tensors.items()
}
)

def get_spec_info(self, num_tokens: int):
spec_info = None
Expand Down
7 changes: 5 additions & 2 deletions python/sglang/srt/model_executor/runner_utils/buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ def create(
if pp_size > 1:
is_mhc = hc_hidden_size is not None
hs = hc_hidden_size if is_mhc else hidden_size
# Sized in tokens, not requests: under speculative decoding
# the verify forward carries num_tokens_per_bs tokens per
# request (same as topk_indices below).
pp_proxy_tensors = {
"hidden_states": torch.zeros((max_bs, hs), dtype=dtype),
"hidden_states": torch.zeros((max_num_token, hs), dtype=dtype),
}
if not is_mhc:
pp_proxy_tensors["residual"] = torch.zeros(
(max_bs, hidden_size), dtype=dtype
(max_num_token, hidden_size), dtype=dtype
)
if pp_proxy_topk_size is not None:
pp_proxy_tensors["topk_indices"] = torch.zeros(
Expand Down
Loading