Skip to content

Commit 3c82471

Browse files
darsnackmcabbott
andcommitted
Apply suggestions from code review
Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
1 parent 0d55c00 commit 3c82471

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/loading.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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));
5254
julia> all(isone, dst[1].weight)
5355
true
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)
6260
false
6361
6462
julia> dst[1].weight == src[1].weight

0 commit comments

Comments
 (0)