From c98f1ccedb45d34a69fdfd31046edb1ced962f72 Mon Sep 17 00:00:00 2001 From: Estrella-xx <820167017@qq.com> Date: Thu, 20 Aug 2026 20:40:57 +0800 Subject: [PATCH] [NPU]Ensure tensors allocated by empty_like are contiguous (#34935) --- .../srt/hardware_backend/npu/attention/ascend_backend.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 356281ab7..7bd540888 100644 --- a/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py +++ b/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py @@ -1587,7 +1587,9 @@ class AscendAttnBackend(AttentionBackend): (q.shape[0], layer.tp_q_head_num * layer.v_head_dim) ) else: - attn_output = torch.empty_like(q) + attn_output = torch.empty_like( + q, memory_format=torch.contiguous_format + ) use_gqa = layer.tp_q_head_num != layer.tp_k_head_num @@ -2746,7 +2748,9 @@ class AscendAttnBackend(AttentionBackend): (q.shape[0], layer.tp_q_head_num * layer.v_head_dim) ) else: - attn_output = torch.empty_like(q) + attn_output = torch.empty_like( + q, memory_format=torch.contiguous_format + ) use_gqa = layer.tp_q_head_num != layer.tp_k_head_num