# Flux Chain function

**URL:** <https://discourse.julialang.org/t/flux-chain-function/89369>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [October 27, 2022, 1:08pm UTC](https://discourse.julialang.org/t/flux-chain-function/89369 "2022-10-27T13:08:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwerty](https://avatars.discourse-cdn.com/v4/letter/q/4491bb/32.png) [@qwerty](https://discourse.julialang.org/u/qwerty)\
**Post date:** [October 27, 2022, 1:08pm UTC](https://discourse.julialang.org/t/flux-chain-function/89369/1 "2022-10-27T13:08:56Z")

</div>

Why does the Chain function not warn if the output of one layer is not compatible with the imput of the next?

---

<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:** [October 27, 2022, 11:12pm UTC](https://discourse.julialang.org/t/flux-chain-function/89369/2 "2022-10-27T23:12:03Z")

</div>

`Chain` can take arbitrary functions. Given that, how would you check the inputs/outputs of the following are compatible?

```julia
f1(x) = sum(x, dims=1)
function f2(x)
  ndims(x) == 1 && error("too few dims")
  return x .+ 1
end

c = Chain(f1, f2)

```

Without actually calling `c`, there is no way to know whether you’ll get a size mismatch. Thankfully, Flux provides a way to do this and get inferred output sizes without having to run a full forward pass of your model. See [`outputsize`](https://fluxml.ai/Flux.jl/stable/utilities/#Flux.outputsize).
