From 87db74302151956e354a05c01ecda47fd24cb882 Mon Sep 17 00:00:00 2001 From: iridiumine <42236072+iridiumine@users.noreply.github.com> Date: Mon, 14 Sep 2026 19:36:33 +0800 Subject: [PATCH] [NPU] Fix device mismatch in SWA mask for DSpark verify graph capture (#39353) --- .../srt/hardware_backend/npu/attention/ascend_backend.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py b/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py index 6626f89aa..d4049b5db 100644 --- a/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py +++ b/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py @@ -802,7 +802,8 @@ class AscendAttnBackend(AttentionBackend): and _is_dflash_verify(spec_info) and seq_lens_cpu is not None ): - seq_lens_int = seq_lens_cpu[:bs].int() + # seq_lens_cpu may be a CPU tensor; swa_indices is on-device. + seq_lens_int = seq_lens_cpu[:bs].int().to(self.device) else: seq_lens_int = seq_lens[:bs].int() starts = torch.clamp(seq_lens_int - self.sliding_window_size, min=0)