# Freeze model parameters with FluxTraining.jl

**URL:** https://discourse.julialang.org/t/freeze-model-parameters-with-fluxtraining-jl/115119
**Category:** General Usage
**Tags:** flux, fluxtraining
**Created:** [June 3, 2024, 1:18pm UTC](https://discourse.julialang.org/t/freeze-model-parameters-with-fluxtraining-jl/115119 "2024-06-03T13:18:00Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![cirobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cirobr/32/219994_2.png) [@cirobr](https://discourse.julialang.org/u/cirobr)
#### Post date: [June 3, 2024, 1:18pm UTC](https://discourse.julialang.org/t/freeze-model-parameters-with-fluxtraining-jl/115119/1 "2024-06-03T13:18:00Z")

</div>

Cheers,

Training a model with FluxTraining.jl requires building up a learner where the optimizer is declared. For instance:

```julia
opt = Flux.Adam(eta)
learner = Learner(model, lossfn, optimizer=opt)
epoch!(learner, TrainingPhase(), trainset)

```

Given that the optimizer **state** is not part of the arguments, as opposite to what happens with the new syntax of `Flux.train!`, I wonder if freezing model parameters as below would work:

```julia
opt = Flux.Adam(eta) # opt is argument for Learner
opt_state = Flux.setup(opt, model) # opt_state is not argument for Learner
Flux.freeze!(opt_state.encoder)
learner = Learner(model, lossfn, optimizer=opt)
epoch!(learner, TrainingPhase(), trainset)

```

Thanks in advance for advise/clarification.
