AI/TensorFlow, PyTorch, Keras, Scikit
TensorFlow를 공용 GPU에서 사용 할 때 메모리 절약 방법
JAYNUX
2018. 8. 2. 14:39
위와 같이 아래와 같이 TensorFlow를 공용 GPU에서 사용 할 때 메모리 절약 방법
절대적 메모리 uppeor bound 설정
tf.Session
생성 할 때 GPU memory allocation을 지정할 수 있다. 이것을 위해서 tf.GPUOptions
에 config
부분을 아래와 같이 활용 한다.# Assume that you have 12GB of GPU memory and want to allocate ~4GB:
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
per_process_gpu_memory_fraction=0.333
으로 설정된 것은 strict하게 upper bound on the amount of GPU memory를 설정한 것이다.탄력적으로 GPU memory 사용 방법
allow_growth
를 True
로 설정하면 필요에 따라 탄력적으로 memory
를 사용하게 된다.config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config, ...)