@@ -27,12 +27,14 @@ _bool_tie_check(dst, src) = true
27
27
"""
28
28
loadmodel!(dst, src)
29
29
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`.
31
31
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:
36
38
- `dst` and `src` do not share the same fields (at any level)
37
39
- the sizes of leaf nodes are mismatched between `dst` and `src`
38
40
- `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));
52
54
julia> all(isone, dst[1].weight)
53
55
true
54
56
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);
60
58
61
- julia> all(isone, dst[1].weight)
59
+ julia> dst[1].weight ≈ ones(2, 5 )
62
60
false
63
61
64
62
julia> dst[1].weight == src[1].weight
0 commit comments