Skip to content

Commit 1602441

Browse files
committed
human-readable loadparams tests, same results
1 parent fc3eff4 commit 1602441

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

test/utils.jl

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -350,17 +350,6 @@ end
350350
loadparams!(m, params(m))
351351
testdense(m, bt)
352352
end
353-
354-
# @testset "$b1 to $b2" for (b1, b2, be) in (
355-
# (Flux.zeros32, Flux.ones32, Flux.ones32), # Load ones as bias to a model with zeros as bias -> model gets ones as bias
356-
# (Flux.ones32, nobias, Flux.zeros32), # Load Zeros as bias to a model with ones as bias-> model gets zeros as bias
357-
# (nobias, Flux.ones32, nobias), # Load ones as bias to a model with Zeros as bias-> model bias does not change
358-
# )
359-
# m1 = dm(b1)
360-
# m2 = dm(b2)
361-
# loadparams!(m1, b1 == nobias ? weights(m2) : pararray(m2))
362-
# testdense(m1, be)
363-
# end
364353
end
365354

366355
@testset "destructure" begin
@@ -386,6 +375,26 @@ end
386375
end
387376
end
388377

378+
@testset "loadparams! & absent bias" begin
379+
m0 = Dense(2,3; bias=false, init = Flux.ones32)
380+
m1 = Dense(2,3; bias = Flux.randn32(3))
381+
m2 = Dense(Float32[1 2; 3 4; 5 6], Float32[7, 8, 9])
382+
383+
Flux.loadparams!(m1, Flux.params(m2))
384+
@test m1.bias == 7:9
385+
@test sum(m1.weight) == 21
386+
387+
# load from a model without bias:
388+
Flux.loadparams!(m1, Flux.params(m0))
389+
@test_broken iszero(m1.bias) # should ideally recognise the false but Params doesn't store it.
390+
@test sum(m1.weight) == 6
391+
392+
# load into a model without bias:
393+
Flux.loadparams!(m0, Flux.params(m2)) # ignore the parameter which has nowhere to go? Or error?
394+
@test iszero(m0.bias) # obviously unchanged
395+
@test sum(m0.weight) == 21
396+
end
397+
389398
@testset "Train and test mode" begin
390399
mutable struct DummyLayer
391400
testing::Bool

0 commit comments

Comments
 (0)