# How to make parameters of function within Flux.Chain trainable?

**URL:** https://discourse.julialang.org/t/how-to-make-parameters-of-function-within-flux-chain-trainable/66983
**Category:** Machine Learning
**Created:** [August 25, 2021, 2:57pm UTC](https://discourse.julialang.org/t/how-to-make-parameters-of-function-within-flux-chain-trainable/66983 "2021-08-25T14:57:06Z")
**Posts on this page:** 1
**Showing post:** 2

<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: [August 25, 2021, 3:05pm UTC](https://discourse.julialang.org/t/how-to-make-parameters-of-function-within-flux-chain-trainable/66983/2 "2021-08-25T15:05:06Z")

</div>

Related to your [other question](https://discourse.julialang.org/t/flux-chain-vs-expand-everything-in-a-function/66982/2), Flux layers are _stateful_ and need to be kept around instead of re-created on every forward pass. If you want to run something through two branches without writing a custom layer/function, use [`Parallel`](https://fluxml.ai/Flux.jl/stable/models/layers/#Flux.Parallel):

```julia
dudt = Parallel(+, Dense(10, 20, tanh), Dense(10, 20, tanh))

```

For documentation on how Flux layers work and what it takes to make a model trainable, see [Basics · Flux](https://fluxml.ai/Flux.jl/stable/models/basics/#Building-Layers) and [Advanced Model Building · Flux](https://fluxml.ai/Flux.jl/stable/models/advanced/).

---

_[View the full topic](https://discourse.julialang.org/t/how-to-make-parameters-of-function-within-flux-chain-trainable/66983)._
