TransWikia.com

Is it possible to make use of the CPU RAM, if i'm running of of VRAM, in tensorflow?

Data Science Asked by bjernie on April 19, 2021

I want to train a model running on tensorflow. I have a GPU but it only has 6gb of VRAM. So i was wondering if it is possible to use some of the CPU’s RAM to offload the GPU? I know it will be much slower, and i can reduce the batch size and number of layers etc. Can it be done?

One Answer

If I understand correctly you are essentially looking for a way to use the CPU's RAM as a swap for the GPU's RAM. Unfortunately this isn't as easy to accomplish and might require some low level work. So if you're looking for a simple argument to add to your keras model, as far as I know there is none. Some options:

  • Some older tensorflow APIs supported this functionality (e.g. dynamic_rnn - see swap_memory parameter). However these are now deprecated in favor of the equivalent keras layer, that to my knowledge does not support this functionality. Theoretically you could use compatibility mode to utilize this.
  • You can specify what device each tensor will be loaded on beforehand. This isn't equivalent to swapping, but you could offload some computation to be regularly performed on the CPU. You can do this with tf.device.
  • The same idea as above is often applied to loading and preprocessing the data, which is done on the CPU, while everything concerning the training ops is handled by the GPU. This is convenient because you can have a batch being loaded by the CPU at the same time that the model is being trained by the GPU. I know this is far off from what you're asking, because it requires your model to fit in the GPU entirely, however it fits in the general theme of offloading work to the CPU. This is fully supported by tf.data.Dataset.
  • Use some trickery like gradient checkpoints to reduce the memory footprint of your models (with the expense of computational speed). This does not have anything to do with offloading work to the CPU, but it could help you fit your model into memory.

Answered by Djib2011 on April 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP