File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments