From 5186e3ba186f9df57e34aa16ab2f6acf5d6e44d6 Mon Sep 17 00:00:00 2001 From: Josh Christie Date: Sat, 11 Aug 2018 10:51:07 +0100 Subject: [PATCH 01/11] Updates for julia 1.0 --- src/layers/basic.jl | 4 ++-- src/tracker/back.jl | 5 +++-- src/tracker/idset.jl | 8 +++++--- test/runtests.jl | 3 ++- test/tracker.jl | 4 ++-- test/utils.jl | 3 ++- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/layers/basic.jl b/src/layers/basic.jl index d461c95c..f7344484 100644 --- a/src/layers/basic.jl +++ b/src/layers/basic.jl @@ -21,8 +21,8 @@ struct Chain Chain(xs...) = new([xs...]) end -@forward Chain.layers Base.getindex, Base.first, Base.last, Base.endof, Base.push! -@forward Chain.layers Base.start, Base.next, Base.done +@forward Chain.layers Base.getindex, Base.first, Base.last, Base.lastindex, Base.push! +@forward Chain.layers Base.iterate children(c::Chain) = c.layers mapchildren(f, c::Chain) = Chain(f.(c.layers)...) diff --git a/src/tracker/back.jl b/src/tracker/back.jl index 04f5c231..5c44a15a 100644 --- a/src/tracker/back.jl +++ b/src/tracker/back.jl @@ -70,7 +70,7 @@ struct Params Params(xs) = new(IdSet(xs)) end -@forward Params.params Base.start, Base.next, Base.done +@forward Params.params Base.iterate function Base.show(io::IO, ps::Params) print(io, "Params([") @@ -86,6 +86,8 @@ Base.show(io::IO, ps::Grads) = println(io, "Grads(...)") Grads() = Grads(IdDict()) +@forward Grads.grads Base.setindex!, Base.haskey, Base.length, Base.iterate + Grads(ps::Params) = Grads(IdDict(tracker(p) => init_grad(data(p)) for p in ps)) Base.getindex(g::Grads, x::Tracked) = g.grads[x] @@ -94,7 +96,6 @@ function Base.getindex(g::Grads, x) g[tracker(x)] end -@forward Grads.grads Base.setindex!, Base.haskey accum!(g::Grads, x, Δ) = g[x] = haskey(g, x) ? g[x] .+ Δ : Δ diff --git a/src/tracker/idset.jl b/src/tracker/idset.jl index 1bbfec09..442d5fa2 100644 --- a/src/tracker/idset.jl +++ b/src/tracker/idset.jl @@ -20,6 +20,8 @@ Base.similar(s::IdSet, T::Type) = IdSet{T}() @forward IdSet.dict Base.length -Base.start(s::IdSet) = start(keys(s.dict)) -Base.next(s::IdSet, st) = next(keys(s.dict), st) -Base.done(s::IdSet, st) = done(keys(s.dict), st) +function iterate(v::IdSet, state...) + y = iterate(keys(v.dict), state...) + y === nothing && return nothing + return (y[1], y[2]) +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 6d698784..fcda4e82 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using Flux, Test, Random +using Random -srand(0) +Random.seed!(0) @testset "Flux" begin diff --git a/test/tracker.jl b/test/tracker.jl index d504f0a4..768cc4f7 100644 --- a/test/tracker.jl +++ b/test/tracker.jl @@ -5,13 +5,13 @@ using NNlib: conv using Printf: @sprintf using LinearAlgebra: diagm, dot, LowerTriangular, norm using Statistics: mean, std +using Random # using StatsBase gradtest(f, xs::AbstractArray...) = gradcheck((xs...) -> sum(sin.(f(xs...))), xs...) -gradtest(f, dims...) = gradtest(f, rand.(dims)...) +gradtest(f, dims...) = gradtest(f, rand.(Float64, dims)...) @testset "Tracker" begin - @test gradtest((x, W, b) -> σ.(W*x .+ b), 5, (2,5), 2) @test gradtest((x, W, b) -> σ.(W*x .+ b), (5,3), (2,5), 2) @test gradtest((x, W, b) -> logσ.(W*x .+ b), 5, (2,5), 2) diff --git a/test/utils.jl b/test/utils.jl index 6fb28e31..5e1b0ef0 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -1,6 +1,7 @@ using Flux: throttle, initn, glorot_uniform, glorot_normal, jacobian using StatsBase: std using Dates +using Random @testset "Throttle" begin @testset "default behaviour" begin @@ -61,7 +62,7 @@ end @testset "Initialization" begin # Set random seed so that these tests don't fail randomly - srand(0) + Random.seed!(0) # initn() should yield a kernel with stddev ~= 1e-2 v = initn(10, 10) @test std(v) > 0.9*1e-2 From d3c78a80be7d4b3dfb7eeb1f1f42e04f10e2ee8c Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Sat, 11 Aug 2018 17:20:27 +0530 Subject: [PATCH 02/11] Fix layers errors --- src/layers/normalise.jl | 8 ++++---- test/layers/normalisation.jl | 6 +++--- test/layers/stateless.jl | 4 ++-- test/runtests.jl | 8 +++++++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/layers/normalise.jl b/src/layers/normalise.jl index f6297034..164f6fa7 100644 --- a/src/layers/normalise.jl +++ b/src/layers/normalise.jl @@ -130,13 +130,13 @@ function (BN::BatchNorm)(x) ϵ = data(convert(T, BN.ϵ)) axes = [1:dims-2; dims] # axes to reduce along (all but channels axis) - μ = mean(x, axes) - σ = sqrt.(mean((x .- μ).^2, axes) .+ ϵ) + μ = mean(x, dims = axes) + σ = sqrt.(mean((x .- μ).^2, dims = axes) .+ ϵ) # update moving mean/std mtm = data(convert(T, BN.momentum)) - BN.μ = (1 - mtm) .* BN.μ .+ mtm .* squeeze(data(μ), (axes...,)) - BN.σ = (1 - mtm) .* BN.σ .+ mtm .* squeeze(data(σ), (axes...,)) .* m ./ (m - 1) + BN.μ = (1 - mtm) .* BN.μ .+ mtm .* dropdims(data(μ), dims = (axes...,)) + BN.σ = (1 - mtm) .* BN.σ .+ mtm .* dropdims(data(σ), dims = (axes...,)) .* m ./ (m - 1) end let λ = BN.λ diff --git a/test/layers/normalisation.jl b/test/layers/normalisation.jl index a7a7ada2..b17120b0 100644 --- a/test/layers/normalisation.jl +++ b/test/layers/normalisation.jl @@ -53,17 +53,17 @@ end # .1 * 4 + 0 = .4 @test m.μ ≈ reshape([0.3, 0.4], 2, 1) - # julia> .1 .* std(x, 2, corrected=false) .* (3 / 2).+ .9 .* [1., 1.] + # julia> .1 .* std(x, dims = 2, corrected=false) .* (3 / 2).+ .9 .* [1., 1.] # 2×1 Array{Float64,2}: # 1.14495 # 1.14495 - @test m.σ ≈ .1 .* std(x.data, 2, corrected=false) .* (3 / 2).+ .9 .* [1., 1.] + @test m.σ ≈ .1 .* std(x.data, dims = 2, corrected=false) .* (3 / 2).+ .9 .* [1., 1.] testmode!(m) @test !m.active x′ = m(x).data - @test x′[1] ≈ (1 - 0.3) / 1.1449489742783179 + @test x′[1] ≈ (1 .- 0.3) / 1.1449489742783179 end # with activation function diff --git a/test/layers/stateless.jl b/test/layers/stateless.jl index 7c1d3efa..d4599908 100644 --- a/test/layers/stateless.jl +++ b/test/layers/stateless.jl @@ -42,8 +42,8 @@ const ϵ = 1e-7 logŷ, y = randn(3), rand(3) @testset "binarycrossentropy" begin - @test binarycrossentropy.(σ.(logŷ), y; ϵ=0) ≈ -y.*log.(σ.(logŷ)) - (1 - y).*log.(1 - σ.(logŷ)) - @test binarycrossentropy.(σ.(logŷ), y) ≈ -y.*log.(σ.(logŷ) .+ eps.(σ.(logŷ))) - (1 - y).*log.(1 - σ.(logŷ) .+ eps.(σ.(logŷ))) + @test binarycrossentropy.(σ.(logŷ), y; ϵ=0) ≈ -y.*log.(σ.(logŷ)) - (1 .- y).*log.(1 .- σ.(logŷ)) + @test binarycrossentropy.(σ.(logŷ), y) ≈ -y.*log.(σ.(logŷ) .+ eps.(σ.(logŷ))) - (1 .- y).*log.(1 .- σ.(logŷ) .+ eps.(σ.(logŷ))) end @testset "logitbinarycrossentropy" begin diff --git a/test/runtests.jl b/test/runtests.jl index fcda4e82..2ce0e63b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,11 +5,17 @@ Random.seed!(0) @testset "Flux" begin +println("Testing") include("utils.jl") -include("tracker.jl") +# println("Testing") +# include("tracker.jl") +println("Testing") include("layers/normalisation.jl") +println("Testing") include("layers/stateless.jl") +println("Testing") include("optimise.jl") +println("Testing") include("data.jl") # if Base.find_in_path("CuArrays") ≠ nothing From 837e03613f98ff9b949815018cba02a3682dab3c Mon Sep 17 00:00:00 2001 From: Josh Christie Date: Sat, 11 Aug 2018 10:51:07 +0100 Subject: [PATCH 03/11] Updates for julia 1.0 --- REQUIRE | 2 +- src/layers/basic.jl | 4 ++-- src/tracker/back.jl | 5 +++-- src/tracker/idset.jl | 8 +++++--- test/runtests.jl | 3 ++- test/tracker.jl | 4 ++-- test/utils.jl | 3 ++- 7 files changed, 17 insertions(+), 12 deletions(-) diff --git a/REQUIRE b/REQUIRE index df9c6322..7164de5a 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.7- +julia 0.7 Juno MacroTools 0.3.3 NNlib diff --git a/src/layers/basic.jl b/src/layers/basic.jl index d461c95c..f7344484 100644 --- a/src/layers/basic.jl +++ b/src/layers/basic.jl @@ -21,8 +21,8 @@ struct Chain Chain(xs...) = new([xs...]) end -@forward Chain.layers Base.getindex, Base.first, Base.last, Base.endof, Base.push! -@forward Chain.layers Base.start, Base.next, Base.done +@forward Chain.layers Base.getindex, Base.first, Base.last, Base.lastindex, Base.push! +@forward Chain.layers Base.iterate children(c::Chain) = c.layers mapchildren(f, c::Chain) = Chain(f.(c.layers)...) diff --git a/src/tracker/back.jl b/src/tracker/back.jl index 04f5c231..774123b4 100644 --- a/src/tracker/back.jl +++ b/src/tracker/back.jl @@ -70,7 +70,7 @@ struct Params Params(xs) = new(IdSet(xs)) end -@forward Params.params Base.start, Base.next, Base.done +@forward Params.params Base.iterate, Base.length function Base.show(io::IO, ps::Params) print(io, "Params([") @@ -86,6 +86,8 @@ Base.show(io::IO, ps::Grads) = println(io, "Grads(...)") Grads() = Grads(IdDict()) +@forward Grads.grads Base.setindex!, Base.haskey, Base.length, Base.iterate + Grads(ps::Params) = Grads(IdDict(tracker(p) => init_grad(data(p)) for p in ps)) Base.getindex(g::Grads, x::Tracked) = g.grads[x] @@ -94,7 +96,6 @@ function Base.getindex(g::Grads, x) g[tracker(x)] end -@forward Grads.grads Base.setindex!, Base.haskey accum!(g::Grads, x, Δ) = g[x] = haskey(g, x) ? g[x] .+ Δ : Δ diff --git a/src/tracker/idset.jl b/src/tracker/idset.jl index 1bbfec09..62d5190e 100644 --- a/src/tracker/idset.jl +++ b/src/tracker/idset.jl @@ -20,6 +20,8 @@ Base.similar(s::IdSet, T::Type) = IdSet{T}() @forward IdSet.dict Base.length -Base.start(s::IdSet) = start(keys(s.dict)) -Base.next(s::IdSet, st) = next(keys(s.dict), st) -Base.done(s::IdSet, st) = done(keys(s.dict), st) +function Base.iterate(v::IdSet, state...) + y = Base.iterate(keys(v.dict), state...) + y === nothing && return nothing + return (y[1], y[2]) +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 6d698784..fcda4e82 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using Flux, Test, Random +using Random -srand(0) +Random.seed!(0) @testset "Flux" begin diff --git a/test/tracker.jl b/test/tracker.jl index d504f0a4..768cc4f7 100644 --- a/test/tracker.jl +++ b/test/tracker.jl @@ -5,13 +5,13 @@ using NNlib: conv using Printf: @sprintf using LinearAlgebra: diagm, dot, LowerTriangular, norm using Statistics: mean, std +using Random # using StatsBase gradtest(f, xs::AbstractArray...) = gradcheck((xs...) -> sum(sin.(f(xs...))), xs...) -gradtest(f, dims...) = gradtest(f, rand.(dims)...) +gradtest(f, dims...) = gradtest(f, rand.(Float64, dims)...) @testset "Tracker" begin - @test gradtest((x, W, b) -> σ.(W*x .+ b), 5, (2,5), 2) @test gradtest((x, W, b) -> σ.(W*x .+ b), (5,3), (2,5), 2) @test gradtest((x, W, b) -> logσ.(W*x .+ b), 5, (2,5), 2) diff --git a/test/utils.jl b/test/utils.jl index 6fb28e31..5e1b0ef0 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -1,6 +1,7 @@ using Flux: throttle, initn, glorot_uniform, glorot_normal, jacobian using StatsBase: std using Dates +using Random @testset "Throttle" begin @testset "default behaviour" begin @@ -61,7 +62,7 @@ end @testset "Initialization" begin # Set random seed so that these tests don't fail randomly - srand(0) + Random.seed!(0) # initn() should yield a kernel with stddev ~= 1e-2 v = initn(10, 10) @test std(v) > 0.9*1e-2 From 5db7a3a3ad8f805cd1f7c84369404b43dda678f7 Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Sat, 11 Aug 2018 18:23:47 +0530 Subject: [PATCH 04/11] Fix Optimizers --- src/optimise/Optimise.jl | 5 +++-- src/tracker/idset.jl | 7 +------ test/runtests.jl | 14 ++++---------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/optimise/Optimise.jl b/src/optimise/Optimise.jl index 6765a778..ee7723bc 100644 --- a/src/optimise/Optimise.jl +++ b/src/optimise/Optimise.jl @@ -9,7 +9,7 @@ struct Param{T} Δ::T end -Base.convert(::Type{Param}, x::AbstractArray) = Param(x, zero(x)) +Param(x::AbstractArray) = Param(x, zero(x)) include("optimisers.jl") include("interface.jl") @@ -17,6 +17,7 @@ include("train.jl") using Flux.Tracker: TrackedArray -Base.convert(::Type{Param}, x::TrackedArray) = Param(x.data, x.grad) +Param(x::TrackedArray) = Param(x.data, x.grad) +# Base.convert(::Type{Param}, x::TrackedArray) = Param(x.data, x.grad) end diff --git a/src/tracker/idset.jl b/src/tracker/idset.jl index 940db15d..d1c507b4 100644 --- a/src/tracker/idset.jl +++ b/src/tracker/idset.jl @@ -20,13 +20,8 @@ Base.similar(s::IdSet, T::Type) = IdSet{T}() @forward IdSet.dict Base.length -<<<<<<< HEAD -function iterate(v::IdSet, state...) - y = iterate(keys(v.dict), state...) -======= function Base.iterate(v::IdSet, state...) y = Base.iterate(keys(v.dict), state...) ->>>>>>> 837e03613f98ff9b949815018cba02a3682dab3c y === nothing && return nothing return (y[1], y[2]) -end \ No newline at end of file +end diff --git a/test/runtests.jl b/test/runtests.jl index 2ce0e63b..15f59459 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,21 +5,15 @@ Random.seed!(0) @testset "Flux" begin -println("Testing") include("utils.jl") -# println("Testing") -# include("tracker.jl") -println("Testing") +include("tracker.jl") include("layers/normalisation.jl") -println("Testing") include("layers/stateless.jl") -println("Testing") include("optimise.jl") -println("Testing") include("data.jl") -# if Base.find_in_path("CuArrays") ≠ nothing -# include("cuda/cuda.jl") -# end +if Base.find_in_path("CuArrays") ≠ nothing + include("cuda/cuda.jl") +end end From 89881a9b21b4ab05ec903229bfd9fb6c67698885 Mon Sep 17 00:00:00 2001 From: ayush1999 Date: Sat, 11 Aug 2018 18:24:59 +0530 Subject: [PATCH 05/11] utils errors fixed --- test/optimise.jl | 2 +- test/utils.jl | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/optimise.jl b/test/optimise.jl index c896bb39..7e99c294 100644 --- a/test/optimise.jl +++ b/test/optimise.jl @@ -1,6 +1,6 @@ using Flux.Optimise using Flux.Tracker - +using Test @testset "Optimise" begin w = randn(10, 10) @testset for Opt in [SGD, Nesterov, Momentum, ADAM, AdaMax, RMSProp, ps -> ADAGrad(ps, 0.1), ADADelta, AMSGrad, NADAM] diff --git a/test/utils.jl b/test/utils.jl index 5e1b0ef0..119baaff 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -1,7 +1,10 @@ -using Flux: throttle, initn, glorot_uniform, glorot_normal, jacobian +using Flux +using Flux: throttle, jacobian, initn, glorot_uniform, glorot_normal using StatsBase: std using Dates using Random +using Test +using Dates: now @testset "Throttle" begin @testset "default behaviour" begin From 710a65fe72f22225b4c1ddfbf83647ea38e7135a Mon Sep 17 00:00:00 2001 From: Josh Christie Date: Sat, 11 Aug 2018 14:27:56 +0100 Subject: [PATCH 06/11] Fix back scalar with a Ref and fix diagonal test --- src/tracker/back.jl | 2 +- test/tracker.jl | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/tracker/back.jl b/src/tracker/back.jl index 774123b4..e5a84a71 100644 --- a/src/tracker/back.jl +++ b/src/tracker/back.jl @@ -137,7 +137,7 @@ end function forward(f, args...) args = param.(args) y, back = forward(() -> f(args...), Params(args)) - y, Δ -> getindex.(back(Δ), args) + y, Δ -> getindex.(Ref(back(Δ)), args) end function losscheck(x) diff --git a/test/tracker.jl b/test/tracker.jl index 768cc4f7..6cf4aba8 100644 --- a/test/tracker.jl +++ b/test/tracker.jl @@ -3,23 +3,20 @@ using Flux.Tracker, Test, NNlib using Flux.Tracker: TrackedReal, gradcheck, grad, derivative, checkpoint using NNlib: conv using Printf: @sprintf -using LinearAlgebra: diagm, dot, LowerTriangular, norm +using LinearAlgebra: Diagonal, dot, LowerTriangular, norm using Statistics: mean, std using Random # using StatsBase gradtest(f, xs::AbstractArray...) = gradcheck((xs...) -> sum(sin.(f(xs...))), xs...) gradtest(f, dims...) = gradtest(f, rand.(Float64, dims)...) - @testset "Tracker" begin @test gradtest((x, W, b) -> σ.(W*x .+ b), 5, (2,5), 2) @test gradtest((x, W, b) -> σ.(W*x .+ b), (5,3), (2,5), 2) @test gradtest((x, W, b) -> logσ.(W*x .+ b), 5, (2,5), 2) @test gradtest((x, W, b) -> logσ.(W*x .+ b), (5,3), (2,5), 2) - @test gradtest((w, x) -> w'*x, randn(Float64,10, 2), randn(Float64,10)) @test gradtest((w, x) -> w*x', randn(Float64,5,5), randn(Float64,5,5)) - @test gradtest(x -> sum(x, dims = (2, 3)), (3,4,5)) @test gradtest(x -> sum(x, dims = 1), randn(Float64,2,3)) @test gradtest(x -> sum(x, dims = [1,2]), randn(Float64,2,3)) @@ -36,7 +33,6 @@ gradtest(f, dims...) = gradtest(f, rand.(Float64, dims)...) @test gradtest(Flux.crossentropy, rand(5,5), rand(5, 5)) @test gradtest(x -> x', rand(5)) - function promotiontest(f, A, B, C) r0 = f(A, B, C) r1 = f(param(A), B, C) @@ -69,6 +65,7 @@ end @test gradtest(vcatf, rand(5)', rand(2,5)) end + @testset for hcatf in [hcat, cat2] @test gradtest(hcatf, rand(5), rand(5)) @test gradtest(hcatf, rand(5)', rand(5)') @@ -97,7 +94,7 @@ end @test !isa(vcat(rand(2)), TrackedArray) @test !isa(hcat(rand(2)), TrackedArray) - @test !isa(cat(1,rand(2)), TrackedArray) + @test !isa(cat(rand(2), dims=1), TrackedArray) @test gradtest((a,b)->cat(a, b, dims = (2,3,5)), rand(2,3), rand(2,4,2,1)) @@ -115,6 +112,7 @@ end promotiontest(hcat, rand(4,3,5), rand(4,1,5), rand(4,2,5)) promotiontest((x...) -> cat(x..., dims = 3), rand(4,5,3), rand(4,5,1), rand(4,5,2)) end + end @test gradtest(x -> permutedims(x, [3,1,2]), rand(4,5,6)) @@ -128,7 +126,7 @@ end @test gradtest(kron, rand(5,1), rand(3,1), rand(8,1)) @test gradtest(kron, rand(5,2), rand(3,2), rand(8,2)) -@test gradtest(diagm, rand(3)) +@test gradtest(f-> Matrix(Diagonal(f)), rand(3)) @testset "mean" begin @test gradtest(mean, rand(2, 3)) From c8307a06272b66735f01aa4ee21aaadbf1df6389 Mon Sep 17 00:00:00 2001 From: Josh Christie Date: Sat, 11 Aug 2018 14:42:33 +0100 Subject: [PATCH 07/11] Use @info for logging --- src/data/mnist.jl | 2 +- src/data/sentiment.jl | 2 +- src/optimise/train.jl | 2 +- test/cuda/cuda.jl | 2 +- test/cuda/cudnn.jl | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/data/mnist.jl b/src/data/mnist.jl index 34bcd50c..3322df84 100644 --- a/src/data/mnist.jl +++ b/src/data/mnist.jl @@ -14,7 +14,7 @@ function load() "t10k-images-idx3-ubyte", "t10k-labels-idx1-ubyte"] isfile(file) && continue - info("Downloading MNIST dataset") + @info "Downloading MNIST dataset" download("https://cache.julialang.org/http://yann.lecun.com/exdb/mnist/$file.gz", "$file.gz") open(file, "w") do io write(io, GZip.open(read, "$file.gz")) diff --git a/src/data/sentiment.jl b/src/data/sentiment.jl index 570fcf5d..a269107f 100644 --- a/src/data/sentiment.jl +++ b/src/data/sentiment.jl @@ -5,7 +5,7 @@ using ..Data: deps function load() isfile(deps("sentiment.zip")) || return - info("Downloading sentiment treebank dataset") + @info "Downloading sentiment treebank dataset" download("https://cache.julialang.org/https://nlp.stanford.edu/sentiment/trainDevTestTrees_PTB.zip", deps("sentiment.zip")) end diff --git a/src/optimise/train.jl b/src/optimise/train.jl index 8ad8573e..95009444 100644 --- a/src/optimise/train.jl +++ b/src/optimise/train.jl @@ -59,7 +59,7 @@ hello """ macro epochs(n, ex) :(@progress for i = 1:$(esc(n)) - info("Epoch $i") + @info "Epoch $i" $(esc(ex)) end) end diff --git a/test/cuda/cuda.jl b/test/cuda/cuda.jl index f515a2bc..fd860189 100644 --- a/test/cuda/cuda.jl +++ b/test/cuda/cuda.jl @@ -1,7 +1,7 @@ using Flux, Flux.Tracker, CuArrays, Test using Flux: gpu -info("Testing Flux/GPU") +@info "Testing Flux/GPU" @testset "CuArrays" begin diff --git a/test/cuda/cudnn.jl b/test/cuda/cudnn.jl index c67fc060..d5cf442b 100644 --- a/test/cuda/cudnn.jl +++ b/test/cuda/cudnn.jl @@ -1,6 +1,6 @@ using Flux, CuArrays, Test -info("Testing Flux/CUDNN") +@info "Testing Flux/CUDNN" @testset "RNN" begin @testset for R in [RNN, GRU, LSTM] From 59bdff2cae30e1afc75623bf65394da7bea6bfaf Mon Sep 17 00:00:00 2001 From: Josh Christie Date: Sat, 11 Aug 2018 14:50:11 +0100 Subject: [PATCH 08/11] Test 0.7 and 1.0 --- .travis.yml | 2 ++ src/data/cmudict.jl | 2 +- test/runtests.jl | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bef19a3e..dfdc0496 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ os: # - osx julia: - 0.7 + - 1.0 + - nightly # uncomment the following lines to override the default test script # script: # - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi diff --git a/src/data/cmudict.jl b/src/data/cmudict.jl index 3ac0634d..926f2342 100644 --- a/src/data/cmudict.jl +++ b/src/data/cmudict.jl @@ -14,7 +14,7 @@ function load() return end end - info("Downloading CMUDict dataset") + @info "Downloading CMUDict dataset" mkpath(deps("cmudict")) for x in suffixes download("$cache_prefix/http://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict-$version$x", diff --git a/test/runtests.jl b/test/runtests.jl index 15f59459..f751c1f2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,7 +12,7 @@ include("layers/stateless.jl") include("optimise.jl") include("data.jl") -if Base.find_in_path("CuArrays") ≠ nothing +if Base.find_package("CuArrays") ≠ nothing include("cuda/cuda.jl") end From 69ccaf044f9d996a393bf4d960e9b7d5ffe02cb4 Mon Sep 17 00:00:00 2001 From: Josh Christie Date: Sat, 11 Aug 2018 15:46:01 +0100 Subject: [PATCH 09/11] Allow failures on nightly --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index dfdc0496..9bf07dd6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,9 @@ julia: # script: # - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi # - julia -e 'Pkg.clone(pwd()); Pkg.build("Flux"); Pkg.test("Flux"; coverage=true)' +matrix: + allow_failures: + - julia: nightly after_success: - julia -e 'Pkg.add("Documenter")' - julia -e 'cd(Pkg.dir("Flux")); include(joinpath("docs", "make.jl"))' From 4683e925d408fa20c99acd435aad58bf6e4ff154 Mon Sep 17 00:00:00 2001 From: ayush1999 Date: Sat, 11 Aug 2018 20:55:14 +0530 Subject: [PATCH 10/11] Final changes --- src/layers/conv.jl | 4 ++-- src/tracker/Tracker.jl | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index e73e582f..78509c84 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -1,6 +1,6 @@ using NNlib: conv -@generated sub2(::Type{Val{N}}) where N = :(Val{$(N-2)}) +@generated sub2(::Type{Val{N}}) where N = :(Val($(N-2))) expand(N, i::Tuple) = i expand(N, i::Integer) = ntuple(_ -> i, N) @@ -32,7 +32,7 @@ Conv(w::AbstractArray{T,N}, b::AbstractVector{T}, σ = identity; Conv(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity; init = initn, stride = 1, pad = 0, dilation = 1) where N = - Conv(param(init(k..., ch...)), param(zero(ch[2])), σ, + Conv(param(init(k..., ch...)), param(zeros(ch[2])), σ, stride = stride, pad = pad, dilation = dilation) @treelike Conv diff --git a/src/tracker/Tracker.jl b/src/tracker/Tracker.jl index 2c4951a9..190837ab 100644 --- a/src/tracker/Tracker.jl +++ b/src/tracker/Tracker.jl @@ -77,8 +77,7 @@ include("numeric.jl") Hook into gradient backpropagation. `x` is unmodified, but when backpropagating `f` will be applied to the incoming gradient. For example, `hook(-, x)` will reverse -the sign of the gradient applied to `x`. -""" +the sign of the gradient applied to `x`.""" hook(f, x) = istracked(x) ? track(hook, f, x) : x @grad hook(f, x) = data(x), Δ -> (nothing, f(Δ)) From a43127f8811836a12ef82a72f767d6a71a7b8412 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 15 Aug 2018 12:16:12 +0200 Subject: [PATCH 11/11] fix copy_transpose! --- src/cuda/cudnn.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cuda/cudnn.jl b/src/cuda/cudnn.jl index 585b948d..01a368c7 100644 --- a/src/cuda/cudnn.jl +++ b/src/cuda/cudnn.jl @@ -1,6 +1,8 @@ using CuArrays.CUDNN: @check, libcudnn, cudnnStatus_t, libcudnn_handle, cudnnDataType, TensorDesc, FilterDesc +using LinearAlgebra + mutable struct DropoutDesc ptr::Ptr{Nothing} states::CuVector{UInt8} @@ -244,14 +246,14 @@ import ..Tracker: TrackedArray using CUDAnative using CuArrays: @cuindex, cudims -function copy_transpose!(dst::CuArray, src::CuArray) +function LinearAlgebra.copy_transpose!(dst::CuArray, src::CuArray) function kernel(dst, src) I = @cuindex dst dst[I...] = src[reverse(I)...] return end blk, thr = cudims(dst) - @cuda (blk, thr) kernel(dst, src) + @cuda blocks=blk threads=thr kernel(dst, src) return dst end