Solved by glaringlee in post #2 
              
              
                @dfalbel 
I never did it before. But I think it is doable. 
The FreeCudaMemoryCallbacksRegistry is defined here and used to register FreeMemoryCallbacks 
‘https://github.com/pytorch/pytorch/blob/master/c10/cuda/CUDACachingAllocator.cpp#L23’ 
FreeCudaMemoryCallbacksRegistry is actually a c10::registr…