Commit 61bdff40 authored by Yuxin Wu's avatar Yuxin Wu

do not load devices by TF

parent 53c4db69
...@@ -35,9 +35,9 @@ class GPUUtilizationTracker(Callback): ...@@ -35,9 +35,9 @@ class GPUUtilizationTracker(Callback):
if devices is None: if devices is None:
env = os.environ.get('CUDA_VISIBLE_DEVICES') env = os.environ.get('CUDA_VISIBLE_DEVICES')
if env is None: if env is None:
logger.warn("[GPUUtilizationTracker] Both devices and CUDA_VISIBLE_DEVICES are None! "
"Will monitor all visible GPUs!")
self._devices = list(map(str, range(get_nr_gpu()))) self._devices = list(map(str, range(get_nr_gpu())))
logger.warn("[GPUUtilizationTracker] Both devices and CUDA_VISIBLE_DEVICES are None! "
"Will monitor all {} visible GPUs!".format(len(self._devices)))
else: else:
if len(env): if len(env):
self._devices = env.split(',') self._devices = env.split(',')
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import os import os
from .utils import change_env from .utils import change_env
from . import logger from .concurrency import subproc_call
__all__ = ['change_gpu', 'get_nr_gpu'] __all__ = ['change_gpu', 'get_nr_gpu']
...@@ -29,8 +29,8 @@ def get_nr_gpu(): ...@@ -29,8 +29,8 @@ def get_nr_gpu():
env = os.environ.get('CUDA_VISIBLE_DEVICES', None) env = os.environ.get('CUDA_VISIBLE_DEVICES', None)
if env is not None: if env is not None:
return len(env.split(',')) return len(env.split(','))
logger.info("Loading devices by TensorFlow ...") output, code = subproc_call("nvidia-smi -L", timeout=5)
from tensorflow.python.client import device_lib if code != 0:
device_protos = device_lib.list_local_devices() return 0
gpus = [x.name for x in device_protos if x.device_type == 'GPU'] output = output.decode('utf-8')
return len(gpus) return len(output.strip().split('\n'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment