A implementation of ResNet-18 uses lot of GPU memory

Hello and welcome!
You can customize the memory allocator for CuArrays. Please check:
https://juliagpu.gitlab.io/CUDA.jl/usage/memory/

Example (add these lines before ‘using’ anything, at the start of your session):

ENV["JULIA_CUDA_VERBOSE"] = true
ENV["CUARRAYS_MEMORY_POOL"] = "split"
ENV["CUARRAYS_MEMORY_LIMIT"] = 8000_000_000

using CuArrays

You can also try to use larger batch sizes during training.

I also had similar issues with some custom networks and playing with the ENVs above helped a lot.
I never did a comparison with Tensorflow or other frameworks, though…

I see you do some float. conversions. This by default converts to Float64. It’s better to use Float32 data all over your code.

As a side note, please format your code example using backticks, it’s much easier for others to read and understand.

1 Like