연구실 서버 한 대에서의 gpu를 나눠써야하는 상황이 발생하여, 각각 사용가능한 gpu의 최대 메모리를 제한하여 사용하는 방식을 사용하였다.

 

gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:  # gpu가 존재한다면 MB단위로 제한 (5GB로 제한)
  tf.config.experimental.set_virtual_device_configuration(gpus[0], 
        [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=5*1024)])

위의 코드를 추가하면 메모리가 제한되는 것을 볼 수 있다.

지정해둔 메모리보다 조금 더 사용한다.

 

+ Recent posts