mirror of
https://github.com/handsomezhuzhu/vllm-npu-plugin.git
synced 2026-02-20 11:42:30 +00:00
fix: 添加对C++操作不可用时的弱引用张量回退处理
This commit is contained in:
@@ -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):
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user