1 parent 9370fc2 commit 53ef258Copy full SHA for 53ef258
1 file changed
deepmd/pt/utils/region.py
@@ -21,7 +21,14 @@ def phys2inter(
21
the internal coordinates
22
23
"""
24
- rec_cell, _ = torch.linalg.inv_ex(cell)
+ 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)
32
return torch.matmul(coord, rec_cell)
33
34
0 commit comments