I have a tensorflow model saved as a protocol buffer format as model.pb which is 184 MB. When I load it using a session, I see that the process hogs 11 GB of GPU RAM. Why is that?
0
votes
For one thing, by default TF allocates (almost) the whole GPU memory when you create a session, regardless of how much you actually need for the model (This makes memory management more efficient). Look up "enable GPU memory growth". For another, protobuf file doesn't represent the in-RAM weight of the model, but only the parameters saved. You still need, for example, input, output & intermediate buffers (& a whole bunch of other stuff, this is just an example to make the point), so yeah, expect your in-RAM size to be bigger. It's normal.
- GPhilo
1 Answers
2
votes
Tensorflow uses all the GPU memory by default to minimize memory fragmentation (see the documentation). You can prevent this behavior by using the allow_growth config option:
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config, ...)