|
1 | 1 | loadleaf!(dst, src, err) = dst
|
| 2 | +loadleaf!(dst::AbstractArray, src, err) = |
| 3 | + error("Tried to copy $src into an array destination; this is not allowed.") |
| 4 | +loadleaf!(dst, src::AbstractArray, err) = |
| 5 | + error("Tried to copy an array to $dst; this is not allowed.") |
2 | 6 | function loadleaf!(dst::AbstractArray, src::Bool, err)
|
3 | 7 | if iszero(src)
|
4 | 8 | dst .= src
|
@@ -30,20 +34,12 @@ _bool_tie_check(dst, src) = true
|
30 | 34 | Copy all the parameters (trainable and non-trainable) from `src` into `dst`.
|
31 | 35 |
|
32 | 36 | 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) are not copied |
35 |
| -and do not need to match between `dst` and `src`. |
36 |
| -Inactive parameters can be encoded by using the boolean value `false` instead of an array. |
37 |
| -If `dst == false` and `src` is an all-zero array, no error will be raised (and no values copied); |
38 |
| -however, attempting to copy a non-zero array to an inactive parameter will throw an error. |
39 |
| -Likewise, copying `src == false` to any `dst` array is valid, but copying `src == true` will error. |
40 |
| -
|
41 |
| -Throws an error when: |
42 |
| -- `dst` and `src` do not share the same fields (at any level) |
43 |
| -- the sizes of leaf nodes are mismatched between `dst` and `src` |
44 |
| -- `dst` is a "tied" parameter (i.e. refers to another parameter) and |
45 |
| - loaded into multiple times with mismatched source values |
| 37 | +and calling `copyto!` on parameter arrays or throwing an error when there is a mismatch. |
| 38 | +Non-array elements (such as activation functions) are not copied and need not match. |
| 39 | +Zero bias vectors and `bias=false` are considered equivalent |
| 40 | +(see extended help for more details). |
46 | 41 |
|
| 42 | +# Examples |
47 | 43 | ```julia
|
48 | 44 | julia> using Flux: loadmodel!
|
49 | 45 |
|
|
69 | 65 | julia> dst[2].bias == src[2].bias
|
70 | 66 | true
|
71 | 67 | ```
|
| 68 | +
|
| 69 | +# Extended help |
| 70 | +
|
| 71 | +Throws an error when: |
| 72 | +- `dst` and `src` do not share the same fields (at any level) |
| 73 | +- the sizes of leaf nodes are mismatched between `dst` and `src` |
| 74 | +- copying non-array values to/from an array parameter |
| 75 | + (except inactive parameters described below) |
| 76 | +- `dst` is a "tied" parameter (i.e. refers to another parameter) and |
| 77 | + loaded into multiple times with mismatched source values |
| 78 | +
|
| 79 | +Inactive parameters can be encoded by using the boolean value `false` instead of an array. |
| 80 | +If `dst == false` and `src` is an all-zero array, no error will be raised (and no values copied); |
| 81 | +however, attempting to copy a non-zero array to an inactive parameter will throw an error. |
| 82 | +Likewise, copying a `src` value of `false` to any `dst` array is valid, |
| 83 | +but copying a `src` value of `true` will error. |
72 | 84 | """
|
73 | 85 | function loadmodel!(dst, src; cache = Base.IdSet())
|
74 | 86 | ldsts, _ = functor(dst)
|
|
0 commit comments