Skip to content

Commit 17a353f

Browse files
committed
update
1 parent 5c63acc commit 17a353f

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

deepmd/tf/train/run_options.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ def get_device_name(self) -> str | None:
8181
str or None
8282
The device name if available, otherwise None.
8383
"""
84-
gpus = tf.config.list_physical_devices("GPU")
85-
if gpus:
86-
# Use the first physical GPU device identifier as the device name
87-
details = tf.config.experimental.get_device_details(gpus[0])
88-
return details.get("device_name") or gpus[0].name
84+
try:
85+
gpus = tf.config.get_visible_devices("GPU")
86+
if gpus:
87+
# Use the first visible GPU device identifier as the device name
88+
details = tf.config.experimental.get_device_details(gpus[0])
89+
return details.get("device_name") or gpus[0].name
90+
except (AttributeError, RuntimeError):
91+
# Experimental API may not exist or fail in some TF versions
92+
pass
8993
return None
9094

9195

0 commit comments

Comments
 (0)