[Bugfix][Spec-Decode] Populate draft seq_lens_cpu_upper_bound for spec-decode attention metadata (#44492)

Signed-off-by: Oxana Korzh <okorzh@amd.com>
Signed-off-by: okorzh-amd <okorzh-amd@users.noreply.github.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: okorzh-amd <okorzh-amd@users.noreply.github.com>
Co-authored-by: Matthew Bonanni <mbonanni@redhat.com>
This commit is contained in:
Oxana Korzh
2026-07-20 20:50:58 +00:00
committed by GitHub
co-authored by Cursor okorzh-amd Matthew Bonanni
parent 7ca017778f
commit 4ec199b66a
4 changed files with 150 additions and 0 deletions
@@ -268,6 +268,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
dummy_run and skip_attn_for_dummy_run,
decode_batch_desc,
num_tokens_across_dp,
input_batch.seq_lens_cpu_upper_bound,
)
return self.draft_tokens[:num_reqs]
@@ -376,6 +377,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
skip_attn: bool,
batch_desc: BatchExecutionDescriptor,
num_tokens_across_dp: torch.Tensor | None,
seq_lens_cpu_upper_bound: torch.Tensor,
) -> None:
positions = self.input_buffers.positions[:num_reqs]
query_start_loc = self.input_buffers.query_start_loc[: num_reqs + 1]
@@ -400,6 +402,8 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
num_reqs=num_reqs,
num_reqs_padded=batch_desc.num_reqs or num_reqs,
num_tokens_padded=batch_desc.num_tokens,
seq_lens_cpu_upper_bound=seq_lens_cpu_upper_bound,
step=step,
)
# Update the current draft step.
@@ -269,6 +269,8 @@ class DFlashSpeculator(DraftModelSpeculator):
num_reqs: int,
num_reqs_padded: int,
num_tokens_padded: int,
seq_lens_cpu_upper_bound: torch.Tensor,
step: int,
num_query_per_req: int | None = None,
causal: bool | Mapping[int, bool] = False,
) -> dict[str, Any] | None:
@@ -279,6 +281,8 @@ class DFlashSpeculator(DraftModelSpeculator):
num_reqs,
num_reqs_padded,
num_tokens_padded,
seq_lens_cpu_upper_bound=seq_lens_cpu_upper_bound,
step=step,
num_query_per_req=self.num_query_per_req,
causal=causal,
)
@@ -427,6 +431,8 @@ class DFlashSpeculator(DraftModelSpeculator):
num_reqs=num_reqs,
num_reqs_padded=num_reqs_padded,
num_tokens_padded=num_tokens_padded,
seq_lens_cpu_upper_bound=input_batch.seq_lens_cpu_upper_bound,
step=self.num_query_per_req,
causal=self._group_causal,
)
draft_slot_mappings_by_layer = build_slot_mappings_by_layer(
@@ -210,6 +210,8 @@ class DraftModelSpeculator(BaseSpeculator):
num_reqs: int,
num_reqs_padded: int,
num_tokens_padded: int,
seq_lens_cpu_upper_bound: torch.Tensor,
step: int,
num_query_per_req: int = 1,
causal: bool | Mapping[int, bool] = True,
) -> dict[str, Any] | None:
@@ -224,6 +226,15 @@ class DraftModelSpeculator(BaseSpeculator):
x[:num_reqs_padded] for x in self.block_tables.input_block_tables
]
slot_mappings = self.block_tables.slot_mappings[:, :num_tokens_padded]
draft_seq_lens_cpu_upper_bound = torch.zeros(
num_reqs_padded, dtype=torch.int32, device="cpu"
)
torch.add(
seq_lens_cpu_upper_bound[:num_reqs],
step,
out=draft_seq_lens_cpu_upper_bound[:num_reqs],
)
draft_seq_lens_cpu_upper_bound[:num_reqs].clamp_(max=self.max_model_len)
attn_metadata = build_attn_metadata(
attn_groups=self.attn_groups,
num_reqs=num_reqs_padded,
@@ -239,6 +250,7 @@ class DraftModelSpeculator(BaseSpeculator):
slot_mappings=slot_mappings,
kv_cache_config=self.kv_cache_config,
causal=causal,
seq_lens_cpu_upper_bound=draft_seq_lens_cpu_upper_bound,
)
return attn_metadata