# Flux train all parameters except those equal to 0

**URL:** <https://discourse.julialang.org/t/flux-train-all-parameters-except-those-equal-to-0/55665>\
**Category:** Machine Learning\
**Created:** [February 20, 2021, 8:48am UTC](https://discourse.julialang.org/t/flux-train-all-parameters-except-those-equal-to-0/55665 "2021-02-20T08:48:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![anon74562486](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@anon74562486](https://discourse.julialang.org/u/anon74562486)\
**Post date:** [April 2, 2021, 7:43pm UTC](https://discourse.julialang.org/t/flux-train-all-parameters-except-those-equal-to-0/55665/3 "2021-04-02T19:43:53Z")

</div>

```julia
p = params(model)
ott = ADAM()
for epoch in 1:epochs
    for (x, y) in data
        gr = gradient(p) do 
            loss(x, y)
        end

        for i in 1:length(p)
            gr[p[i]][p[i] .== 0f0] .= 0f0    
        end
        Flux.update!(ott, p, gr)
    end
end

```

this solution is inspired by this one: [How to freeze a single weight of a layer? - Usage - JuliaLang](https://discourse.julialang.org/t/how-to-freeze-a-single-weight-of-a-layer/58279/4)

---

_[View the full topic](https://discourse.julialang.org/t/flux-train-all-parameters-except-those-equal-to-0/55665)._
