Skip to content

Commit

Permalink
work around extreme slowdown due julia performance bug
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Feb 6, 2019
1 parent 8386a49 commit 9914c53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/layers/normalise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ function (BN::BatchNorm)(x)
end

let λ = BN.λ
λ.(reshape(γ, affine_shape...) .* ((x .- μ) ./ sqrt.(σ² .+ BN.ϵ)) .+ reshape(β, affine_shape...))
temp = reshape(γ, affine_shape...) .* ((x .- μ) ./ sqrt.(σ² .+ BN.ϵ))
# This is intentionally not fused because of an extreme slowdown doing so
λ.(temp .+ reshape(β, affine_shape...))
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/layers/normalisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ end
y = permutedims(reshape(m(y), 2, 2, 2, 3, 1), [2, 3, 4, 1, 5])
@test m(x) == y
end

let m = BatchNorm(32), x = randn(Float32, 416, 416, 32, 1);
m(x)
@test (@allocated m(x)) < 100_000_000
end
end

0 comments on commit 9914c53

Please sign in to comment.