Skip to content

Commit 3452a2a

Browse files
author
Han Wang
committed
fix to_numpy_array device
1 parent d3b01da commit 3452a2a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

deepmd/dpmodel/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ def to_numpy_array(x: Optional["Array"]) -> np.ndarray | None:
121121
try:
122122
# asarray is not within Array API standard, so may fail
123123
return np.asarray(x)
124-
except (ValueError, AttributeError):
124+
except (ValueError, AttributeError, TypeError):
125125
xp = array_api_compat.array_namespace(x)
126126
# to fix BufferError: Cannot export readonly array since signalling readonly is unsupported by DLPack.
127-
x = xp.asarray(x, copy=True)
127+
# Move to CPU device to ensure numpy compatibility
128+
x = xp.asarray(x, device="cpu", copy=True)
128129
return np.from_dlpack(x)
129130

130131

0 commit comments

Comments
 (0)