[Fix] dsv4: Skip DP-attention pad rows in the engram hasher and low-ratio sources (#40424)

Co-authored-by: jiashuai <jiashuai@baidu.com>
Co-authored-by: hnyls2002 <lsyincs@gmail.com>
This commit is contained in:
ssJ
2026-10-21 14:37:55 -07:00
committed by GitHub
co-authored by jiashuai hnyls2002
parent 68623cae92
commit 29e78045fb
2 changed files with 11 additions and 4 deletions
@@ -3273,6 +3273,12 @@ class DeepseekV4AttnBackend(
return
hoisted_req = getattr(meta, "low_ratio_req_indices", None)
hoisted_pos = getattr(meta, "low_ratio_pos_i64", None)
if hoisted_pos is not None and hoisted_pos.shape[0] < positions.shape[0]:
# DP attention pads an eager extend past the rows extend_seq_lens cover.
num_real = hoisted_pos.shape[0]
x, positions = x[:num_real], positions[:num_real]
if q_lora is not None:
q_lora = q_lora[:num_real]
if (
hoisted_req is not None
and hoisted_pos is not None
+5 -4
View File
@@ -308,13 +308,14 @@ class EngramHasher(nn.Module):
assert self.history is not None, "EngramHasher.init_history was not called"
n = self.max_ngram_size
num_tokens = input_ids.shape[0]
if num_tokens == 0:
return torch.empty(
(0, self.primes.shape[0], self.offsets.shape[1]),
mode = forward_batch.forward_mode
if num_tokens == 0 or mode.is_idle():
# A DP-attention idle batch carries pad rows; nothing reads its hashes.
return torch.zeros(
(num_tokens, self.primes.shape[0], self.offsets.shape[1]),
dtype=torch.int64,
device=input_ids.device,
)
mode = forward_batch.forward_mode
if (
mode.is_extend()
and not mode.is_target_verify()