# Any suggestion on how to increase CPU usage in Flux?

**URL:** <https://discourse.julialang.org/t/any-suggestion-on-how-to-increase-cpu-usage-in-flux/90467>\
**Category:** Performance\
**Tags:** flux\
**Created:** [November 18, 2022, 5:26pm UTC](https://discourse.julialang.org/t/any-suggestion-on-how-to-increase-cpu-usage-in-flux/90467 "2022-11-18T17:26:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiZ](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tiz/32/211800_2.png) [@tiZ](https://discourse.julialang.org/u/tiZ)\
**Post date:** [November 18, 2022, 5:26pm UTC](https://discourse.julialang.org/t/any-suggestion-on-how-to-increase-cpu-usage-in-flux/90467/1 "2022-11-18T17:26:03Z")

</div>

Hi, I open this topic because I found that sometimes Flux can use 100% of the CPU, but sometimes it only uses half.

For example, here is two demo model, model A have fewer hidden layers than B. Trainning model A, the CPU% is alway 100%, but in model B, it drop down to about 50%,

```julia
using Flux
demodata = rand(Float32,10000,128)
model_A = Chain(
    Dense(10000 => 64, relu),
    Dense(64 => 10000,relu))
model_B = Chain(
    Dense(10000 => 512, relu),
    Dense(512 => 218,relu),
    Dense(218 => 64,relu),
    Dense(64 => 218,relu),
    Dense(218 => 512,relu),
    Dense(512 => 10000,relu))

myLoss(Model,X) = begin
    Flux.Losses.mse(Model(X),X)
end
# training model_A
ps = Flux.params(model_A);
for i in 1:100
    Flux.train!(myLoss, ps,[(model_A, demodata)], ADAM() )
end
# training model_B
ps = Flux.params(model_B);
for i in 1:100
    Flux.train!(myLoss, ps,[(model_B, demodata)], ADAM() )
end

```

here is the CPU% when the model A is runing

 ![2134](https://global.discourse-cdn.com/julialang/original/3X/8/b/8baa815725955a870b0038ef88baa3ac58edc262.png)

and this one is the model B 's

 ![12345](https://global.discourse-cdn.com/julialang/original/3X/b/0/b065311c10229f55d585fba02c5d80d4bc15ad5b.png)

I am not an expert in this area, but according to my understanding, model B requires more computational power, so, what limits it to using only 50% CPU? and any suggestion how to improve the CPU% in model B training?

Thank you for your patience in reading 😄😄

I also found this topic related to Flux and CPU, but it is more about multi-threads support.

> [@How can I make Flux use all my CPUs?](https://discourse.julialang.org/t/how-can-i-make-flux-use-all-my-cpus/21869):
>
> Hi all, I already set export JULIA\_NUM\_THREADS=12 and in REPL I checked Threads.nthreads() =12. But when I ran the training, I only saw Julia(Flux) using 8 CPUs, and, they were not in full power. How can I make Flux use all my CPUs and run in full power? Thanks!
