-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathgpu_env.py
46 lines (36 loc) · 1.11 KB
/
gpu_env.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
from datetime import datetime
from enum import Enum
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
IGNORE_PATTERNS = ('data', '*.pyc', 'CVS', '.git', 'tmp', '.svn', '__pycache__', '.gitignore', '.*.yaml')
MODEL_ID = datetime.now().strftime("%m%d-%H%M%S") + (
os.environ['suffix_model_id'] if 'suffix_model_id' in os.environ else '')
APP_NAME = 'mrc'
class SummaryType(Enum):
SCALAR = 1
HISTOGRAM = 2
SAMPLED = 3
class ModeKeys(Enum):
TRAIN = 1
EVAL = 2
INFER = 3
INTERACT = 4
DECODE = 5
TEST = 6
try:
import GPUtil
# GPUtil.showUtilization()
DEVICE_ID_LIST = GPUtil.getFirstAvailable(order='random', maxMemory=0.1, maxLoad=0.1)
DEVICE_ID = DEVICE_ID_LIST[0] # grab first element from list
os.environ["CUDA_VISIBLE_DEVICES"] = str(DEVICE_ID)
CONFIG_SET = 'default_gpu'
except FileNotFoundError:
print('no gpu found!')
DEVICE_ID = 'x'
CONFIG_SET = 'default'
except RuntimeError:
print('all gpus are occupied!')
DEVICE_ID = '?'
CONFIG_SET = 'default_gpu'
print('use config: %s' % CONFIG_SET)