# \`CUDA error: out of memory\` with Flux

**URL:** <https://discourse.julialang.org/t/cuda-error-out-of-memory-with-flux/45269>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [August 20, 2020, 1:06pm UTC](https://discourse.julialang.org/t/cuda-error-out-of-memory-with-flux/45269 "2020-08-20T13:06:13Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![natema](https://avatars.discourse-cdn.com/v4/letter/n/ba9def/32.png) [@natema](https://discourse.julialang.org/u/natema)\
**Post date:** [August 21, 2020, 6:13pm UTC](https://discourse.julialang.org/t/cuda-error-out-of-memory-with-flux/45269/2 "2020-08-21T18:13:39Z")

</div>

Well… the code is now running with batches of size 10 rather than 1000.  
I vaguely remember to have tried even with a batch size of 1 and to be getting the same error, but I didn’t save the example so I will remain wondering…  
Btw, I was checking the GPU memory usage with `nvidia-smi` and, independently of the batch size, the code leaves only few MB of ram available when running the main loop, which I copy here for easy reference:

```julia
for epoch = 1:epochs
        @info "epoch" epoch
        for i in 1:batchnum
                batch = trainset[i] |> gpu
                gs = gradient(params(m)) do
                        l = loss(batch...)
                end
                @info "batch fraction" i/batchnum
                update!(opt, params(m), gs)
        end
        @show accuracy(valX, valY)
end

```

The error is being raised then trying to run `accuracy`.  
I’m now doing a binary search to find out the critical batch size, for what is worth.

---

_[View the full topic](https://discourse.julialang.org/t/cuda-error-out-of-memory-with-flux/45269)._
