# Take gradient of parameters not working

**URL:** <https://discourse.julialang.org/t/take-gradient-of-parameters-not-working/53250>\
**Category:** Machine Learning\
**Tags:** question, flux\
**Created:** [January 12, 2021, 8:20pm UTC](https://discourse.julialang.org/t/take-gradient-of-parameters-not-working/53250 "2021-01-12T20:20:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)\
**Post date:** [January 12, 2021, 8:20pm UTC](https://discourse.julialang.org/t/take-gradient-of-parameters-not-working/53250/1 "2021-01-12T20:20:58Z")

</div>

Hi all! I am trying to construct a loss function in Flux (v0.11.2) that regularizes the parameters relative to some number (not 0). Below is a minimal working example, does anybody know why the gradients are `nothing`?

```julia
using Flux

m = Chain(Dense(2, 10, relu), Dense(10, 10, relu), Dense(10, 1))

ps = Flux.params(m)

function project_norm() # basically trying to do sum(||x - p|| for all p in params) given a specific x
   t = 0.0f0
    
    for k=1:length(ps)
        for j=1:length(ps[k])
            t += (1.0f0 - ps[k][j])^2
        end
    end
    
    return t
end

gs = gradient(ps) do
    project_norm()
end

gs[ps[1]] # returns nothing?

```
