When I train a neural network with NetTrain[..., TargetDevice->"GPU"]
, wolfram's neural network code automatically allocates memory on my GPU for my model's computation graph, copied depending on the batch size.
My problem is that if I change my model and re-run NetTrain, memory allocated for the old model is not reliably de-allocated from my gpu, resulting in an error:
NetTrain: An unknown internal error occurred. Consult internal`$LastInternalFailure for potential information.
and internal`$LastInternalFailure
of:
MXNetError <...> ./pooled_storage_manager.h:161: cudaMalloc retry failed: out of memory
How can I explicitly tell the wolfram neural network library to clear out allocated GPU memory?
(I have found a workaround without restarting my computer involving repeating restarting the Wolfram Kernel and waiting dozens of seconds until my gpu memory is freed. But this is extremely inconvenient, and it requires me to re-run my notebook to continue from where I left off.)