# Flux:the trainable parameter is empty

**URL:** <https://discourse.julialang.org/t/flux-the-trainable-parameter-is-empty/77903>\
**Category:** New to Julia\
**Tags:** question, flux\
**Created:** [March 15, 2022, 7:36am UTC](https://discourse.julialang.org/t/flux-the-trainable-parameter-is-empty/77903 "2022-03-15T07:36:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chen2021](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chen2021/32/32214_2.png) [@chen2021](https://discourse.julialang.org/u/chen2021)\
**Post date:** [March 15, 2022, 7:36am UTC](https://discourse.julialang.org/t/flux-the-trainable-parameter-is-empty/77903/1 "2022-03-15T07:36:25Z")

</div>

Hi everyone!I am trying to create a custom layer, and customize the parameter collection to train, the following is my code

```julia
using Flux

struct Linear{F,S<:AbstractArray,T<:AbstractArray}
    W::S
    b::T
    σ::F
end

function Linear(in::Integer, out::Integer, σ = identity;
                initW = Flux.glorot_uniform, initb = zeros)
    return Linear(initW(out, in), initb(out), σ)
end

function (a::Linear)(x::AbstractArray)
    W, b, σ = a.W, a.b, a.σ
    σ.(W*x .+ b)
end
Flux.@functor Linear (W,)
# Flux.trainable(m::Linear) = (m.W)

m = Linear(2,1)
ps = Flux.params(m) # always get Params([])

```

But the `ps` is always empty, Where is wrong?

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [March 15, 2022, 3:40pm UTC](https://discourse.julialang.org/t/flux-the-trainable-parameter-is-empty/77903/2 "2022-03-15T15:40:55Z")

</div>

Running exactly your code above:

```julia-repl
julia> Flux.params(m)
Params([Float32[1.1857293 -0.41868022]])

```

Can you replicate this on a fresh Julia session? If so, what versions of Flux, Zygote, Julia, etc. are you running?

---

<div class="post-metadata">

**Author:** ![chen2021](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chen2021/32/32214_2.png) [@chen2021](https://discourse.julialang.org/u/chen2021)\
**Post date:** [March 16, 2022, 4:52am UTC](https://discourse.julialang.org/t/flux-the-trainable-parameter-is-empty/77903/3 "2022-03-16T04:52:30Z")

</div>

Yes, I changed the environment then it does work.  
Thanks！
