Skip to content

Commit 53ef258

Browse files
committed
fix: handle CUDA solver errors in phys2inter by falling back to CPU inversion
1 parent 9370fc2 commit 53ef258

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

deepmd/pt/utils/region.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ def phys2inter(
2121
the internal coordinates
2222
2323
"""
24-
rec_cell, _ = torch.linalg.inv_ex(cell)
24+
try:
25+
rec_cell, _ = torch.linalg.inv_ex(cell)
26+
except RuntimeError as err:
27+
# Some CUDA/cuSOLVER combinations can fail to create a solver handle.
28+
# Fall back to CPU inversion for 3x3 cell matrices and move back.
29+
if "cusolver" not in str(err).lower():
30+
raise
31+
rec_cell = torch.linalg.inv(cell.cpu()).to(device=cell.device, dtype=cell.dtype)
2532
return torch.matmul(coord, rec_cell)
2633

2734

0 commit comments

Comments
 (0)