Skip to content

Commit 0357f4e

Browse files
author
Han Wang
committed
fix device
1 parent d29cee8 commit 0357f4e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

deepmd/dpmodel/utils/network.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,8 @@ def get_graph_index( # noqa: ANN201
13321332

13331333
# 1. atom graph
13341334
# node(i) to edge(ij) index_select; edge(ij) to node aggregate
1335-
nlist_loc_index = xp.arange(nf * nloc, dtype=nlist.dtype)
1335+
dev = array_api_compat.device(nlist)
1336+
nlist_loc_index = xp.arange(nf * nloc, dtype=nlist.dtype, device=dev)
13361337
# nf x nloc x nnei
13371338
n2e_index = xp.broadcast_to(
13381339
xp.reshape(nlist_loc_index, (nf, nloc, 1)), (nf, nloc, nnei)
@@ -1341,7 +1342,7 @@ def get_graph_index( # noqa: ANN201
13411342
n2e_index = n2e_index[xp.astype(nlist_mask, xp.bool)]
13421343

13431344
# node_ext(j) to edge(ij) index_select
1344-
frame_shift = xp.arange(nf, dtype=nlist.dtype) * (
1345+
frame_shift = xp.arange(nf, dtype=nlist.dtype, device=dev) * (
13451346
nall if not use_loc_mapping else nloc
13461347
)
13471348
shifted_nlist = nlist + frame_shift[:, xp.newaxis, xp.newaxis]
@@ -1357,8 +1358,8 @@ def get_graph_index( # noqa: ANN201
13571358
n2a_index = n2a_index[a_nlist_mask_3d]
13581359

13591360
# edge(ij) to angle(ijk) index_select; angle(ijk) to edge(ij) aggregate
1360-
edge_id = xp.arange(n_edge, dtype=nlist.dtype)
1361-
edge_index = xp.zeros((nf, nloc, nnei), dtype=nlist.dtype)
1361+
edge_id = xp.arange(n_edge, dtype=nlist.dtype, device=dev)
1362+
edge_index = xp.zeros((nf, nloc, nnei), dtype=nlist.dtype, device=dev)
13621363
edge_index = xp_setitem_at(edge_index, xp.astype(nlist_mask, xp.bool), edge_id)
13631364
# only cut a_nnei neighbors, to avoid nnei x nnei
13641365
edge_index = edge_index[:, :, :a_nnei]

0 commit comments

Comments
 (0)