# Flux: ERROR: OutOfMemoryError()

**URL:** <https://discourse.julialang.org/t/flux-error-outofmemoryerror/29481>\
**Category:** New to Julia\
**Tags:** flux\
**Created:** [October 4, 2019, 10:53am UTC](https://discourse.julialang.org/t/flux-error-outofmemoryerror/29481 "2019-10-04T10:53:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnbb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnbb/32/34233_2.png) [@johnbb](https://discourse.julialang.org/u/johnbb)\
**Post date:** [October 4, 2019, 10:53am UTC](https://discourse.julialang.org/t/flux-error-outofmemoryerror/29481/1 "2019-10-04T10:53:03Z")

</div>

Hi,

I am new to Julia (3-4 days experience only) and trying to fit a simple least square neural network model in Julia 1.2.0 using Flux. The code at the end results in ERROR: OutOfMemoryError() even though I have 64 GB of memory. However, if I let n = 10000 it works, but I do not understand the memory usage

```julia
julia> @time Flux.train!(loss, params(model), data_iterator, ADAM())
 13.316979 seconds (15.39 M allocations: 26.925 GiB, 9.88% gc time)

```

Any hints?

```julia
using Flux

n = 100000
p = 10
x = rand(p, n)  
y = rand(n)

model = Chain(Dense(p, 32, relu),
              Dense(32, 16, relu),
              Dense(16, 1))
loss(x, y) = Flux.mse(model(x), y)
data_iterator = Iterators.repeated((x, y), 5)
@time Flux.train!(loss, params(model), data_iterator, ADAM())

```

---

<div class="post-metadata">

**Author:** ![johnbb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnbb/32/34233_2.png) [@johnbb](https://discourse.julialang.org/u/johnbb)\
**Post date:** [October 4, 2019, 2:52pm UTC](https://discourse.julialang.org/t/flux-error-outofmemoryerror/29481/2 "2019-10-04T14:52:06Z")

</div>

I have realized that my example is not a very realistic one. Normally, one would use a batch size of, say, 100 and in that case it works well.

```julia
trdata = [(rand(p,100), rand(100)) for i in 1:1000]
@time Flux.@epochs 5 Flux.train!(loss, params(model), trdata, ADAM())

```
