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