# Do I have to implement Flux.testmode! for my own models?

**URL:** https://discourse.julialang.org/t/do-i-have-to-implement-flux-testmode-for-my-own-models/52038
**Category:** Machine Learning
**Created:** [December 18, 2020, 11:21am UTC](https://discourse.julialang.org/t/do-i-have-to-implement-flux-testmode-for-my-own-models/52038 "2020-12-18T11:21:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![maxfreu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxfreu/32/17468_2.png) [@maxfreu](https://discourse.julialang.org/u/maxfreu)
#### Post date: [December 18, 2020, 11:21am UTC](https://discourse.julialang.org/t/do-i-have-to-implement-flux-testmode-for-my-own-models/52038/1 "2020-12-18T11:21:22Z")

</div>

Hi, I implemented a U-Net and would like to switch between train and test mode for the BN layers.

```julia
struct Unet
    encoder # tuple of chains
    decoder # tuple of UpBlocks
    segmentation_head # normal conv layer
end

Flux.@functor Unet
...

```

As of now `testmode!(unet)` just returns the input with nothing changed. Do I have to manually implement it for the building blocks and the model itself or is there some smart way to circumvent this? Some models are simply not a `Chain` in their structure…

Edit: By chance I found [this](https://github.com/FluxML/Flux.jl/issues/1429) issue, which suggests that I have to do so. Can the user somehow be warned if testmode! changes nothing?

---

<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: [December 18, 2020, 6:00pm UTC](https://discourse.julialang.org/t/do-i-have-to-implement-flux-testmode-for-my-own-models/52038/2 "2020-12-18T18:00:58Z")

</div>

As I mentioned on the issue thread, the straightforward fix would be to recurse via `trainable` in `testmode!` so that it automatically works with functors. However, this would mean that most of the recursive calls are no-ops, so warning on them would likely generate a great deal of superfluous warnings.
