@@ -27,12 +27,14 @@ _bool_tie_check(dst, src) = true
2727"""
2828 loadmodel!(dst, src)
2929
30- Copy all the parameters (trainable and non-trainable) from `src` to `dst`.
30+ Copy all the parameters (trainable and non-trainable) from `src` into `dst`.
3131
32- `loadmodel!` recursively walks the [`Functors.children`](@ref) of `dst` and `src`
33- calling `copyto!` on any pair of children where [`Functors.isleaf`](@ref) is true.
34- It also handles "absent" parameters such as `bias == false`.
35- It throws an error whenever:
32+ Recursively walks `dst` and `src` together using [`Functors.children`](@ref),
33+ and calling `copyto!` on parameter arrays.
34+ Non-array elements (such as activation functions) need not match.
35+ An all-zero bias array can be copied to or from absent bias, encoded `bias = false`.
36+
37+ Throws an error when:
3638- `dst` and `src` do not share the same fields (at any level)
3739- the sizes of leaf nodes are mismatched between `dst` and `src`
3840- `dst` is a "tied" parameter (e.g. `transpose` of another parameter) and
@@ -52,13 +54,9 @@ julia> src = Chain(Dense(5 => 2), Dense(2 => 1));
5254julia> all(isone, dst[1].weight)
5355true
5456
55- julia> dst = loadmodel!(dst, src)
56- Chain(
57- Dense(5 => 2), # 12 parameters
58- Dense(2 => 1), # 3 parameters
59- ) # Total: 4 arrays, 15 parameters, 316 bytes.
57+ julia> loadmodel!(dst, src);
6058
61- julia> all(isone, dst[1].weight)
59+ julia> dst[1].weight ≈ ones(2, 5 )
6260false
6361
6462julia> dst[1].weight == src[1].weight
0 commit comments