From 5534f2fa4116b087db00b2846d2c96bd924a9bb4 Mon Sep 17 00:00:00 2001 From: handsomezhuzhu <2658601135@qq.com> Date: Wed, 11 Feb 2026 00:17:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9C++=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E4=B8=8D=E5=8F=AF=E7=94=A8=E6=97=B6=E7=9A=84=E5=BC=B1?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E5=BC=A0=E9=87=8F=E5=9B=9E=E9=80=80=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vllm_npu/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vllm_npu/utils.py b/vllm_npu/utils.py index a2d7909..3f3d2e1 100644 --- a/vllm_npu/utils.py +++ b/vllm_npu/utils.py @@ -728,9 +728,14 @@ def weak_ref_tensor(tensor: Any) -> Any: Create a weak reference to a tensor. The new tensor will share the same data as the original tensor, but will not keep the original tensor alive. + Falls back to returning the tensor as-is if the C++ op is unavailable. """ if isinstance(tensor, torch.Tensor): - return torch.ops._C_ascend.weak_ref_tensor(tensor) + if hasattr(torch.ops, '_C_ascend') and hasattr( + torch.ops._C_ascend, 'weak_ref_tensor'): + return torch.ops._C_ascend.weak_ref_tensor(tensor) + # Fallback: return tensor directly (no weak ref, minor memory overhead) + return tensor else: return tensor