# Flux model on CPU runs slowly

**URL:** https://discourse.julialang.org/t/flux-model-on-cpu-runs-slowly/47723
**Category:** Performance
**Tags:** question, flux
**Created:** [October 4, 2020, 2:22am UTC](https://discourse.julialang.org/t/flux-model-on-cpu-runs-slowly/47723 "2020-10-04T02:22:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AquaIndigo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaindigo/32/15820_2.png) [@AquaIndigo](https://discourse.julialang.org/u/AquaIndigo)
#### Post date: [October 4, 2020, 2:22am UTC](https://discourse.julialang.org/t/flux-model-on-cpu-runs-slowly/47723/1 "2020-10-04T02:22:41Z")

</div>

I find the `Flux` model on CPU runs more slowly than that on GPU:

```julia
julia> m = Chain(
           Dense(2250, 500, σ),
           Dense(500, 50, tanh),
           Dense(50, 7, σ));

julia> X = Float32.(X);

julia> size(X)
 (2250, 484)

julia> @btime m(X);
  10.718 ms (10 allocations: 2.06 MiB)

julia> X_gpu = X |> gpu;

julia> m_gpu = m |> gpu;

julia> @btime m_gpu(X_gpu);
  21.864 μs (134 allocations: 3.80 KiB)

```

And training the model on CPU was untolarably slow, and I am really confused.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [October 4, 2020, 2:36am UTC](https://discourse.julialang.org/t/flux-model-on-cpu-runs-slowly/47723/2 "2020-10-04T02:36:45Z")

</div>

That’s a really big matmul for a GPU 🤷‍♂️. It should be about the same cost on any CPU implementation since its all going to be in a BLAS kernel.

---

<div class="post-metadata">

### Author: ![AquaIndigo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaindigo/32/15820_2.png) [@AquaIndigo](https://discourse.julialang.org/u/AquaIndigo)
#### Post date: [October 4, 2020, 2:52am UTC](https://discourse.julialang.org/t/flux-model-on-cpu-runs-slowly/47723/3 "2020-10-04T02:52:02Z")

</div>

And when I trained the same Pytorch model on CPU, it seemed much faster than the Flux model on CPU.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [October 4, 2020, 2:54am UTC](https://discourse.julialang.org/t/flux-model-on-cpu-runs-slowly/47723/4 "2020-10-04T02:54:10Z")

</div>

Julia’s tanh is fairly slow, but the bottleneck really should be the matmul
