-
-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cuda gpu memory usage increasing in time #2523
Comments
The issue is likely with GC not being GPU-aware and not finalizing gpu arrays in time, so the memory just keeps growing, even though only a fraction of it is actually used. Maybe with EscapeAnalysis and things like JuliaLang/julia#55990 situation can be improved, but I'm not sure if it can work effectively with things like Zygote (maybe @aviatesk can clarify). The situation is worse if you render your desktop and run computations on the same GPU, so when you run out of memory in Julia you also crash your DE. I recently experimented with allowing users to define a region of code where all gpu allocations are recorded and then bulk-freeing them once the program is out of that region in AMDGPU. Example: θ = <parameters>
AMDGPU.record_memory!(true)
∇ = gradient(θ) do θ
...
end
apply!(θ, ∇) # in-place parameter update
AMDGPU.record_memory!(false) # bulk-free all allocations that happened during recording. It significantly improved memory usage with GaussianSplatting.jl:
Maybe there are better approaches to this, but as an idea I think it can also easily be extended to Flux (e.g. with training API). |
I've experimented with yet another approach (JuliaGPU/AMDGPU.jl#708) that further significantly improves performance. The pattern in the code should be similar to previous approach: Benchmarking on GaussianSplatting.jl 1k training steps we get a stable GPU memory consumption:
And here's the example of how to use it in the code. |
This issue has emerged multiple times on discord
https://discourse.julialang.org/t/memory-usage-increasing-with-each-epoch/121798
https://discourse.julialang.org/t/flux-memory-usage-high-in-srcnn/115174
https://discourse.julialang.org/t/out-of-memory-using-flux-cnn-during-back-propagation-phase/24492
https://discourse.julialang.org/t/flux-gpu-memory-problems/79783
and it could be related to #828 #302 #736 and JuliaGPU/CUDA.jl#137
This is a minimal example, involving only the forward pass, on Flux's master:
with output
Running multiple times
train_mlp()
the memory usage keeps ever increasing and more and more memory is reserved.Mitigation strategies are to set memory limit like
or to manually run the garbage collector
which slows done a lot if done every iteration.
This behavior is highly problematic because training runs quickly fill the gpu and one cannot run other gpu processes.
cc @maleadt
The text was updated successfully, but these errors were encountered: