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

I try to use Flux.loadparams! as it is described in the documentation loadparams!, and I get an error:

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```

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

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

and read them back in with

@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.