- TensorFlow Machine Learning Projects
- Ankit Jain Armando Fandango Amita Kapoor
- 231字
- 2021-06-10 19:15:30
GPU memory handling
At the start of the TensorFlow session, by default, a session grabs all of the GPU memory, even if the operations and variables are placed only on one GPU in a multi-GPU system. If another session starts execution at the same time, it will receive an out-of-memory error. This can be solved in multiple ways:
- For multi-GPU systems, set the environment variable CUDA_VISIBLE_DEVICES=<list of device idx>:
os.environ['CUDA_VISIBLE_DEVICES']='0'
The code that's executed after this setting will be able to grab all of the memory of the visible GPU.
- For letting the session grab a part of the memory of the GPU, use the config option per_process_gpu_memory_fraction to allocate a percentage of the memory:
config.gpu_options.per_process_gpu_memory_fraction = 0.5
This will allocate 50% of the memory in all of the GPU devices.
- By combining both of the preceding strategies, you can make only a certain percentage, alongside just some of the GPU, visible to the process.
- Limit the TensorFlow process to grab only the minimum required memory at the start of the process. As the process executes further, set a config option to allow for the growth of this memory:
config.gpu_options.allow_growth = True
This option only allows for the allocated memory to grow, so the memory is never released back.
To find out more about learning techniques for distributing computation across multiple compute devices, refer to our book, Mastering TensorFlow.
推薦閱讀
- Hands-On Intelligent Agents with OpenAI Gym
- 后稀缺:自動化與未來工作
- Hands-On Internet of Things with MQTT
- PostgreSQL 11 Server Side Programming Quick Start Guide
- 計算機(jī)應(yīng)用復(fù)習(xí)與練習(xí)
- 數(shù)據(jù)中心建設(shè)與管理指南
- Windows 8應(yīng)用開發(fā)實戰(zhàn)
- 大數(shù)據(jù)挑戰(zhàn)與NoSQL數(shù)據(jù)庫技術(shù)
- WordPress Theme Development Beginner's Guide(Third Edition)
- 數(shù)據(jù)庫系統(tǒng)原理及應(yīng)用教程(第5版)
- 新編計算機(jī)圖形學(xué)
- 統(tǒng)計挖掘與機(jī)器學(xué)習(xí):大數(shù)據(jù)預(yù)測建模和分析技術(shù)(原書第3版)
- 奇點將至
- Learning ServiceNow
- Mastering Ansible(Second Edition)