deprecations
This commit is contained in:
parent
b18b51656c
commit
88a265154c
2
REQUIRE
2
REQUIRE
@ -1,4 +1,4 @@
|
|||||||
julia 0.6.0
|
julia 0.7-
|
||||||
Juno
|
Juno
|
||||||
MacroTools 0.3.3
|
MacroTools 0.3.3
|
||||||
NNlib
|
NNlib
|
||||||
|
@ -16,7 +16,7 @@ m(x) == m[2](m[1](x))
|
|||||||
`Chain` also supports indexing and slicing, e.g. `m[2]` or `m[1:end-1]`.
|
`Chain` also supports indexing and slicing, e.g. `m[2]` or `m[1:end-1]`.
|
||||||
`m[1:3](x)` will calculate the output of the first three layers.
|
`m[1:3](x)` will calculate the output of the first three layers.
|
||||||
"""
|
"""
|
||||||
type Chain
|
struct Chain
|
||||||
layers::Vector{Any}
|
layers::Vector{Any}
|
||||||
Chain(xs...) = new([xs...])
|
Chain(xs...) = new([xs...])
|
||||||
end
|
end
|
||||||
|
@ -135,8 +135,8 @@ function (BN::BatchNorm)(x)
|
|||||||
|
|
||||||
# update moving mean/std
|
# update moving mean/std
|
||||||
mtm = data(convert(T, BN.momentum))
|
mtm = data(convert(T, BN.momentum))
|
||||||
BN.μ = (1 - mtm) .* BN.μ .+ mtm .* squeeze(data(μ), (axes...))
|
BN.μ = (1 - mtm) .* BN.μ .+ mtm .* squeeze(data(μ), (axes...,))
|
||||||
BN.σ = (1 - mtm) .* BN.σ .+ mtm .* squeeze(data(σ), (axes...)) .* m ./ (m - 1)
|
BN.σ = (1 - mtm) .* BN.σ .+ mtm .* squeeze(data(σ), (axes...,)) .* m ./ (m - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
let λ = BN.λ
|
let λ = BN.λ
|
||||||
|
@ -178,7 +178,7 @@ function (m::GRUCell)(h, x)
|
|||||||
r = σ.(gate(gx, o, 1) .+ gate(gh, o, 1) .+ gate(b, o, 1))
|
r = σ.(gate(gx, o, 1) .+ gate(gh, o, 1) .+ gate(b, o, 1))
|
||||||
z = σ.(gate(gx, o, 2) .+ gate(gh, o, 2) .+ gate(b, o, 2))
|
z = σ.(gate(gx, o, 2) .+ gate(gh, o, 2) .+ gate(b, o, 2))
|
||||||
h̃ = tanh.(gate(gx, o, 3) .+ r .* gate(gh, o, 3) .+ gate(b, o, 3))
|
h̃ = tanh.(gate(gx, o, 3) .+ r .* gate(gh, o, 3) .+ gate(b, o, 3))
|
||||||
h′ = (1.-z).*h̃ .+ z.*h
|
h′ = (1 .- z).*h̃ .+ z.*h
|
||||||
return h′, h′
|
return h′, h′
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
using LinearAlgebra
|
||||||
|
|
||||||
struct TrackedArray{T,N,A<:AbstractArray{T,N}} <: AbstractArray{T,N}
|
struct TrackedArray{T,N,A<:AbstractArray{T,N}} <: AbstractArray{T,N}
|
||||||
tracker::Tracked{A}
|
tracker::Tracked{A}
|
||||||
data::A
|
data::A
|
||||||
@ -77,26 +79,9 @@ Base.:-(xs::TrackedArray) = track(-, xs)
|
|||||||
Base.transpose(xs::TrackedArray) = track(transpose, xs)
|
Base.transpose(xs::TrackedArray) = track(transpose, xs)
|
||||||
Base.ctranspose(xs::TrackedArray) = track(ctranspose, xs)
|
Base.ctranspose(xs::TrackedArray) = track(ctranspose, xs)
|
||||||
|
|
||||||
@grad transpose(xs) = data(xs).', Δ -> (reshape(Δ.', size(xs)),)
|
@grad transpose(xs) = transpose(data(xs)), Δ -> (reshape(transpose(Δ), size(xs)),)
|
||||||
@grad ctranspose(xs) = data(xs)', Δ -> (reshape(Δ', size(xs)),)
|
@grad ctranspose(xs) = data(xs)', Δ -> (reshape(Δ', size(xs)),)
|
||||||
|
|
||||||
Base.repmat(x::TrackedVecOrMat, a::Integer...) = track(repmat, x, a...)
|
|
||||||
Base.repmat(x::TrackedVecOrMat, a::Int64...) = track(repmat, x, a...)
|
|
||||||
|
|
||||||
@grad function repmat(xs, m, n = 1)
|
|
||||||
repmat(data(xs), m, n), function (Δ)
|
|
||||||
Δ′ = similar(xs)
|
|
||||||
S = size(xs)
|
|
||||||
for (i,v) in enumerate(data(Δ))
|
|
||||||
d1 = divrem(i-1, S[1]*m)
|
|
||||||
x = d1[2] % S[1]+1
|
|
||||||
y = d1[1] % S[2]+1
|
|
||||||
Δ′[x, y] += v
|
|
||||||
end
|
|
||||||
return (nobacksies(:repmat, Δ′), nothing, nothing)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Base.repeat(A::TrackedArray; kw...) = track_kw(repeat, A; kw...)
|
Base.repeat(A::TrackedArray; kw...) = track_kw(repeat, A; kw...)
|
||||||
|
|
||||||
@grad function repeat(xs; inner=ntuple(x->1, ndims(A)), outer=ntuple(x->1, ndims(A)))
|
@grad function repeat(xs; inner=ntuple(x->1, ndims(A)), outer=ntuple(x->1, ndims(A)))
|
||||||
@ -115,7 +100,6 @@ Base.repeat(A::TrackedArray; kw...) = track_kw(repeat, A; kw...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
for f in [:vcat, :hcat]
|
for f in [:vcat, :hcat]
|
||||||
@eval begin
|
@eval begin
|
||||||
# This section is a bit of a hack since julia doesn't have a standardised
|
# This section is a bit of a hack since julia doesn't have a standardised
|
||||||
@ -241,9 +225,11 @@ Base.maximum(xs::TrackedArray, region) = track(maximum, xs, region)
|
|||||||
Base.minimum(xs::TrackedArray) = track(minimum, xs)
|
Base.minimum(xs::TrackedArray) = track(minimum, xs)
|
||||||
Base.minimum(xs::TrackedArray, region) = track(minimum, xs, region)
|
Base.minimum(xs::TrackedArray, region) = track(minimum, xs, region)
|
||||||
|
|
||||||
LinAlg.dot(xs::TrackedVector, ys::TrackedVector) = track(dot, xs, ys)
|
import LinearAlgebra: dot
|
||||||
LinAlg.dot(xs::AbstractVector, ys::TrackedVector) = track(dot, xs, ys)
|
|
||||||
LinAlg.dot(xs::TrackedVector, ys::AbstractVector) = track(dot, xs, ys)
|
dot(xs::TrackedVector, ys::TrackedVector) = track(dot, xs, ys)
|
||||||
|
dot(xs::AbstractVector, ys::TrackedVector) = track(dot, xs, ys)
|
||||||
|
dot(xs::TrackedVector, ys::AbstractVector) = track(dot, xs, ys)
|
||||||
|
|
||||||
@grad dot(xs, ys) = dot(data(xs), data(ys)), Δ -> (Δ .* ys, Δ .* xs)
|
@grad dot(xs, ys) = dot(data(xs), data(ys)), Δ -> (Δ .* ys, Δ .* xs)
|
||||||
|
|
||||||
@ -253,7 +239,7 @@ Base.std(x::TrackedArray; mean = Base.mean(x)) =
|
|||||||
Base.std(x::TrackedArray, dim; mean = Base.mean(x, dim)) =
|
Base.std(x::TrackedArray, dim; mean = Base.mean(x, dim)) =
|
||||||
sqrt.(sum((x .- mean).^2, dim) ./ (size(x, dim)-1))
|
sqrt.(sum((x .- mean).^2, dim) ./ (size(x, dim)-1))
|
||||||
|
|
||||||
Base.vecnorm(x::TrackedArray, p::Real = 2) =
|
LinearAlgebra.vecnorm(x::TrackedArray, p::Real = 2) =
|
||||||
sum(abs.(x).^p .+ eps(0f0))^(1/p) # avoid d(sqrt(x))/dx == Inf at 0
|
sum(abs.(x).^p .+ eps(0f0))^(1/p) # avoid d(sqrt(x))/dx == Inf at 0
|
||||||
|
|
||||||
@grad mean(xs) = mean(data(xs)), Δ -> (Δ / length(xs),)
|
@grad mean(xs) = mean(data(xs)), Δ -> (Δ / length(xs),)
|
||||||
@ -278,7 +264,7 @@ end
|
|||||||
|
|
||||||
# BLAS
|
# BLAS
|
||||||
|
|
||||||
Base.diagm(x::TrackedVector) = track(diagm, x)
|
LinearAlgebra.diagm(x::TrackedVector) = track(diagm, x)
|
||||||
@grad diagm(x) = diagm(data(x)), Δ -> (diag(Δ),)
|
@grad diagm(x) = diagm(data(x)), Δ -> (diag(Δ),)
|
||||||
|
|
||||||
for f in :[*, Ac_mul_B, A_mul_Bc, A_mul_Bt, At_mul_B].args
|
for f in :[*, Ac_mul_B, A_mul_Bc, A_mul_Bt, At_mul_B].args
|
||||||
|
@ -119,7 +119,7 @@ function throttle(f, timeout; leading=true, trailing=false)
|
|||||||
end
|
end
|
||||||
|
|
||||||
cooldown = false
|
cooldown = false
|
||||||
@schedule try
|
@async try
|
||||||
while (sleep(timeout); later != nothing)
|
while (sleep(timeout); later != nothing)
|
||||||
later()
|
later()
|
||||||
later = nothing
|
later = nothing
|
||||||
|
@ -111,10 +111,6 @@ end
|
|||||||
|
|
||||||
@test gradtest(x -> permutedims(x, [3,1,2]), rand(4,5,6))
|
@test gradtest(x -> permutedims(x, [3,1,2]), rand(4,5,6))
|
||||||
|
|
||||||
# TODO unreliable
|
|
||||||
@test gradtest(x -> repmat(x, 5,5), rand(4,5))
|
|
||||||
@test gradtest(x -> repmat(x, 5), rand(4,5))
|
|
||||||
|
|
||||||
@test gradtest(x -> repeat(x; inner=2, outer=3), rand(5))
|
@test gradtest(x -> repeat(x; inner=2, outer=3), rand(5))
|
||||||
@test gradtest(x -> repeat(x; inner=(2,2,1), outer=(1,1,3)), rand(5,4,3))
|
@test gradtest(x -> repeat(x; inner=(2,2,1), outer=(1,1,3)), rand(5,4,3))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user