# How to stop taking gradient of neural network in Flux.jl?

**URL:** https://discourse.julialang.org/t/how-to-stop-taking-gradient-of-neural-network-in-flux-jl/46062
**Category:** General Usage
**Created:** [September 4, 2020, 1:52pm UTC](https://discourse.julialang.org/t/how-to-stop-taking-gradient-of-neural-network-in-flux-jl/46062 "2020-09-04T13:52:09Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![DeepQ](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@DeepQ](https://discourse.julialang.org/u/DeepQ)
#### Post date: [September 4, 2020, 1:52pm UTC](https://discourse.julialang.org/t/how-to-stop-taking-gradient-of-neural-network-in-flux-jl/46062/1 "2020-09-04T13:52:09Z")

</div>

This is my neural network:

```julia
net = Chain(Dense(6, 16, relu), Dense(16, 16, relu), Dense(16, 8))

```

Consider that I have a function like:

```julia
f(x) = sum(net(x))

```

If I want to stop taking gradient of `f(x)` with respect to `x`, I only need to run this line of code:

```julia
Zygote.@nograd f

```

How could I stop taking gradient of `f(x)` with respect to weights and biases of `net`?

---

<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: [September 5, 2020, 5:27pm UTC](https://discourse.julialang.org/t/how-to-stop-taking-gradient-of-neural-network-in-flux-jl/46062/2 "2020-09-05T17:27:09Z")

</div>

Just don’t include the net params in your call to gradient? Are there other parameters that should be differentiated? A MWE (or minimal intended example in this case) would be appreciated.
