# Flux.Chain vs expand everything in a function

**URL:** https://discourse.julialang.org/t/flux-chain-vs-expand-everything-in-a-function/66982
**Category:** Machine Learning
**Created:** [August 25, 2021, 2:39pm UTC](https://discourse.julialang.org/t/flux-chain-vs-expand-everything-in-a-function/66982 "2021-08-25T14:39:25Z")
**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, 2:59pm UTC](https://discourse.julialang.org/t/flux-chain-vs-expand-everything-in-a-function/66982/2 "2021-08-25T14:59:47Z")

</div>

They are not exactly the same, because the second example immediately discards the 3 `Dense` layers after `f` returns. If you constructed them beforehand, passed them into the function and passed their parameters when taking a gradient, then the behaviour will be the same. You’ll also have re-invented most of the functionality of `Chain`!

---

_[View the full topic](https://discourse.julialang.org/t/flux-chain-vs-expand-everything-in-a-function/66982)._
