# LoadError: MethodError: no method matching size(::Pair{Symbol, Any}), when using Flux.loadparams!

**URL:** <https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-size-pair-symbol-any-when-using-flux-loadparams/69578>\
**Category:** Machine Learning\
**Created:** [October 11, 2021, 6:37pm UTC](https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-size-pair-symbol-any-when-using-flux-loadparams/69578 "2021-10-11T18:37:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxim\_Lubov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxim_lubov/32/29744_2.png) [@Maxim\_Lubov](https://discourse.julialang.org/u/Maxim_Lubov)\
**Post date:** [October 11, 2021, 6:37pm UTC](https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-size-pair-symbol-any-when-using-flux-loadparams/69578/1 "2021-10-11T18:37:49Z")

</div>

I try to use `Flux.loadparams!` as it is described in the documentation [loadparams!](https://fluxml.ai/Flux.jl/stable/saving/), and I get an error:

````julia
Closest candidates are:
  size(::Union{LinearAlgebra.QR, LinearAlgebra.QRCompactWY, LinearAlgebra.QRPivoted}) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\qr.jl:558
  size(::Union{LinearAlgebra.QR, LinearAlgebra.QRCompactWY, LinearAlgebra.QRPivoted}, ::Integer) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\qr.jl:557
  size(::Union{LinearAlgebra.Cholesky, LinearAlgebra.CholeskyPivoted}) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\cholesky.jl:442
  ...
Stacktrace:
 [1] loadparams!(m::Tuple{Flux.Chain{Tuple{Flux.Dense{typeof(NNlib.relu), Matrix{Float32}, Vector{Float32}}, Flux.Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}, typeof(NNlib.softmax)}}, Flux.Chain{Tuple{Flux.Dense{typeof(NNlib.relu), Matrix{Float32}, Vector{Float32}}, Flux.Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}, typeof(NNlib.softmax)}}}, xs::Dict{Symbol, Any})
   @ Flux C:\Users\User1\.julia\packages\Flux\ZnXxS\src\functor.jl:59
 [2] top-level scope
   @ c:\Users\User1\project\src\BERT.jl:180
in expression starting at c:\Users\User1\project\src\BERT.jl:1```
````

---

<div class="post-metadata">

**Author:** ![dermesser](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dermesser/32/27339_2.png) [@dermesser](https://discourse.julialang.org/u/dermesser)\
**Post date:** [February 26, 2022, 8:06pm UTC](https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-size-pair-symbol-any-when-using-flux-loadparams/69578/2 "2022-02-26T20:06:50Z")

</div>

I’ve encountered the same problem. Try saving the parameters as

```julia
weights = params(model)
@save "model.bson" weights

```

and read them back in with

```julia
@load "model.bson" weights
model = build_my_default_model()
loadparams!(model, weights)

```

The difference is in saving/loading the parameters as returned by `params()`, not the model itself. This is mentioned in the documentation, but I overlooked it as well.
