My server configuration is as follows:
By using the Django framework and apache server, we call the Keras deep learning model. And after the successful calling of the model, the model has been always running in the GPU memory, which causes the GPU memory can not be released except by shutting down the apache server.
So, is there any way to control the release of GPU memory when calling a Keras model by Apache+Mod_wsgi+Django?
Thanks!
Runtime memory footprint screenshots
If your system has an NVIDIA® GPU and you have the GPU version of TensorFlow installed then your Keras code will automatically run on the GPU.
For people who fail to make K.clear_session()
work, there is an alternative solution:
from numba import cuda
cuda.select_device(0)
cuda.close()
Tensorflow
is just allocating memory to the GPU, while CUDA is responsible for managing the GPU memory.
If CUDA somehow refuses to release the GPU memory after you have cleared all the graph with K.clear_session()
, then you can use the cuda
library to have a direct control on CUDA to clear GPU memory.
from keras import backend as K
K.clear_session()
This will clear the current session (Graph) and so the stale model should be removed from GPU. If it didn't work, you might need to 'del model' and reload it again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With