Skip to content

Commit

Permalink
Updated docstring examples for loadmodel! to cover more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
darsnack committed Apr 5, 2022
1 parent a59f688 commit d08072a
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,23 @@ Zero bias vectors and `bias=false` are considered equivalent
# Examples
```julia
julia> using Flux: loadmodel!
julia> dst = Chain(Dense(Flux.ones32(2, 5)), Dense(2 => 1))
julia> dst = Chain(Dense(Flux.ones32(2, 5, tanh)), Dense(2 => 1; bias = [1f0]))
Chain(
Dense(5 => 2), # 12 parameters
Dense(5 => 2, tanh), # 12 parameters
Dense(2 => 1), # 3 parameters
) # Total: 4 arrays, 15 parameters, 316 bytes.
julia> src = Chain(Dense(5 => 2), Dense(2 => 1));
julia> all(isone, dst[1].weight)
julia> dst[1].weight ≈ ones(2, 5) # by construction
true
julia> loadmodel!(dst, src);
julia> src = Chain(Dense(5 => 2, relu), Dense(2 => 1, bias=false));
julia> dst[1].weight ≈ ones(2, 5)
false
julia> Flux.loadmodel!(dst, src);
julia> dst[1].weight == src[1].weight
true
julia> dst[1].weight ≈ ones(2, 5) # values changed
false
julia> dst[2].bias == src[2].bias
julia> iszero(dst[2].bias)
true
```
Expand Down

0 comments on commit d08072a

Please sign in to comment.