TensorFlow를 공용 GPU에서 사용 할 때 메모리 절약 방법
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, ...)
출처: https://goodtogreate.tistory.com/entry/TensorFlow를-공용-GPU에서-사용-할-때-메모리-절약-방법 [GOOD to GREAT]
시스템 환경 설정으로 적용하는 방법
export TF_FORCE_GPU_ALLOW_GROWTH=true
해도 동일한 효과를 가질 수 있음.
Tensorflow 2.x 적용하는 방법
import tensorflow as tf
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.compat.v1.Session(config=config)
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Hello, my family member. I just wanted to express how great this piece is—it’s well written and has almost all the important information. I want to see more posts like this one.
Thanks I have just been looking for information about this subject for a long time and yours is the best Ive discovered till now However what in regards to the bottom line Are you certain in regards to the supply
Hello, I would want to keep in contact with you regarding your writings on AOL because I genuinely appreciate your writing. I’m excited to see you soon. I need a specialist in this area to address my issue. Perhaps you are that somebody.
hiI like your writing so much share we be in contact more approximately your article on AOL I need a specialist in this area to resolve my problem Maybe that is you Looking ahead to see you
I would claim that a true assistance is involved in producing excellent posts. It’s my first time visiting your website, and I’m amazed at how much research you did to produce such a fantastic article. Fantastic work!
Hi, member of my family. I just wanted to say how fantastic this article is—it’s nicely written and has nearly all of the important details. I hope to see more content similar to this one.