2018-06-22 12:49:18 +00:00
|
|
|
|
using Flux, Flux.Tracker, CuArrays, Base.Test
|
2018-06-23 05:33:15 +00:00
|
|
|
|
using Flux.Tracker: TrackedArray
|
2018-06-22 12:49:18 +00:00
|
|
|
|
using Flux: gpu
|
2018-01-30 13:12:33 +00:00
|
|
|
|
|
2018-06-22 12:49:18 +00:00
|
|
|
|
@testset "CUDNN BatchNorm" begin
|
2018-06-23 05:33:15 +00:00
|
|
|
|
x = TrackedArray(rand(10, 10, 3, 1))
|
|
|
|
|
m = BatchNorm(3)
|
|
|
|
|
cx = gpu(x)
|
|
|
|
|
cm = gpu(m)
|
|
|
|
|
|
|
|
|
|
y = m(x)
|
|
|
|
|
cy = cm(cx)
|
|
|
|
|
|
|
|
|
|
@test cy isa TrackedArray{Float32,4,CuArray{Float32,4}}
|
|
|
|
|
|
|
|
|
|
@test cpu(cy) ≈ y
|
|
|
|
|
|
|
|
|
|
Flux.back!(y, ones(y))
|
|
|
|
|
Flux.back!(cy, ones(cy))
|
|
|
|
|
|
|
|
|
|
@test m.γ.grad ≈ cpu(cm.γ.grad)
|
|
|
|
|
@test m.β.grad ≈ cpu(cm.β.grad)
|
|
|
|
|
@test m.x.grad ≈ cpu(cm.x.grad)
|
2018-01-30 13:12:33 +00:00
|
|
|
|
end
|