JSP's Deep learning

[Setting] 0. TensorFlow 메모리 관리 코드 본문

Deap learning/Setting

[Setting] 0. TensorFlow 메모리 관리 코드

_JSP_ 2022. 7. 24. 22:44

* TensorFlow 메모리 관리 코드

import tensorflow as tf


gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
    try:
        tf.config.experimental.set_memory_growth(gpus[0], True)
    except RuntimeError as e:
        # 프로그램 시작시에 메모리 증가가 설정되어야만 합니다
        print(e)
  • TensorFlow-gpu 라이브러리는 코드 실행 시 잔여 GPU memory을 사용가능한 최대치로 할당해버린다.
  • 따라서 위의 코드를 설정하지 않으면, GPU memory을 효율적으로 사용하지 못하기 때문에, 해당 코드로 GPU memory을 필요한만큼 할당할 수 있도록 한다.
    (* Stack 형식으로 메모리를 할당한다)
Comments