tests with gradients
This commit is contained in:
parent
1fc584102d
commit
8d6028e27a
|
@ -14,13 +14,11 @@ trainmode(f, x...) = forward(f, x...)[1]
|
|||
|
||||
@test cpu(data(cy)) ≈ data(y)
|
||||
|
||||
g = rand(size(y)...)
|
||||
# Flux.back!(y, g)
|
||||
# Flux.back!(cy, gpu(g))
|
||||
g = gradient(()->sum(m(x)), params(m))
|
||||
cg = gradient(()->sum(cm(cx), params(cm))
|
||||
|
||||
@test m.γ ≈ cpu(cm.γ)
|
||||
@test m.β ≈ cpu(cm.β)
|
||||
@test x ≈ cpu(x)
|
||||
@test g.grads[m.γ] ≈ cpu(cg.grads[cm.γ])
|
||||
@test g.grads[m.β] ≈ cpu(cg.grads[cm.β])
|
||||
end
|
||||
|
||||
@testset "2D Input" begin
|
||||
|
@ -36,12 +34,10 @@ trainmode(f, x...) = forward(f, x...)[1]
|
|||
|
||||
@test cpu(data(cy)) ≈ data(y)
|
||||
|
||||
g = rand(size(y)...)
|
||||
#Flux.back!(y, g)
|
||||
#Flux.back!(cy, gpu(g))
|
||||
g = gradient(()->sum(m(x)), params(m))
|
||||
cg = gradient(()->sum(cm(cx), params(cm))
|
||||
|
||||
@test m.γ ≈ cpu(cm.γ)
|
||||
@test m.β ≈ cpu(cm.β)
|
||||
@test x ≈ cpu(x)
|
||||
@test g.grads[m.γ] ≈ cpu(cg.grads[cm.γ])
|
||||
@test g.grads[m.β] ≈ cpu(cg.grads[cm.β])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,8 +6,8 @@ trainmode(f, x...) = forward(f, x...)[1]
|
|||
@testset "Dropout" begin
|
||||
x = [1.,2.,3.]
|
||||
@test x == Dropout(0.1)(x)
|
||||
@test x == trainmode(Dropout(0), (x))
|
||||
@test zero(x) == trainmode(Dropout(1), (x))
|
||||
@test x == trainmode(Dropout(0), x)
|
||||
@test zero(x) == trainmode(Dropout(1), x)
|
||||
|
||||
x = rand(100)
|
||||
m = Dropout(0.9)
|
||||
|
|
Loading…
Reference in New Issue