diff --git a/python/sglang/srt/layers/attention/deepseek_v4_backend.py b/python/sglang/srt/layers/attention/deepseek_v4_backend.py index af6fe36d6f..6220301e9b 100644 --- a/python/sglang/srt/layers/attention/deepseek_v4_backend.py +++ b/python/sglang/srt/layers/attention/deepseek_v4_backend.py @@ -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 diff --git a/python/sglang/srt/layers/engram.py b/python/sglang/srt/layers/engram.py index f8f28ab0d1..768df04699 100644 --- a/python/sglang/srt/layers/engram.py +++ b/python/sglang/srt/layers/engram.py @@ -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()