From 825532783c2e1df7e3868f71f821bbe31f2d0f7f Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 29 May 2019 18:22:36 -0700 Subject: [PATCH 1/6] Test Tracker.jacobian on GPU --- test/cuda/cuda.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/cuda/cuda.jl b/test/cuda/cuda.jl index 96d04c284b..1ed8345285 100644 --- a/test/cuda/cuda.jl +++ b/test/cuda/cuda.jl @@ -48,6 +48,13 @@ end @test y[3,:] isa CuArray end +@testset "Jacobian on GPU" begin + # https://github.com/FluxML/Tracker.jl/pull/33 + @test collect(jacobian(identity, gpu([0.0, 0.0]))) == [1 0; 0 1] + @test collect(gradient(x -> sum(jacobian(y -> y .^ 2, x) .^ 2), + gpu([1.0, 2.0, 3.0]))) == [8.0, 16.0, 24.0] +end + if CuArrays.libcudnn != nothing @info "Testing Flux/CUDNN" include("cudnn.jl") From 8c6ef2048c842557feec3c0b012b0ec1299f615f Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 29 May 2019 18:25:57 -0700 Subject: [PATCH 2/6] [DON'T MERGE] Use Tracker#remotes/cache/pull/33/head --- Manifest.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 8f2f0fadf8..13dcbbbd11 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -272,9 +272,11 @@ version = "0.5.3" [[Tracker]] deps = ["Adapt", "DiffRules", "ForwardDiff", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Printf", "Random", "Requires", "SpecialFunctions", "Statistics", "Test"] -git-tree-sha1 = "0bec1b68c63a0e8a58d3944261cbf4cc9577c8a1" +git-tree-sha1 = "2e516162af7f1e208b62ef3da3af0d094a44aab1" +repo-rev = "9c2c05ec6d785996d83f7f59e3209461fcc36c01" +repo-url = "https://github.com/FluxML/Tracker.jl.git" uuid = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" -version = "0.2.0" +version = "0.2.2" [[TranscodingStreams]] deps = ["Random", "Test"] From 277e05c2e6d917ad15e29e6a6b08d950d73c2780 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 29 May 2019 23:55:54 -0700 Subject: [PATCH 3/6] Test jacobian(softmax, ...) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `jacobian(softmax, ...)` didn't work because NNlib.jl defines the derivative by `∇softmax(Δ, xs) = ∇softmax!(similar(Δ), Δ, xs)` where `Δ` passed from `jacobian` was an array of bool. This is fixed in `jacobian` by creating float array. --- test/cuda/cuda.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cuda/cuda.jl b/test/cuda/cuda.jl index 1ed8345285..b3fbb26439 100644 --- a/test/cuda/cuda.jl +++ b/test/cuda/cuda.jl @@ -51,6 +51,7 @@ end @testset "Jacobian on GPU" begin # https://github.com/FluxML/Tracker.jl/pull/33 @test collect(jacobian(identity, gpu([0.0, 0.0]))) == [1 0; 0 1] + @test collect(jacobian(softmax, gpu(ones(2)))) == [0.25 -0.25; -0.25 0.25] @test collect(gradient(x -> sum(jacobian(y -> y .^ 2, x) .^ 2), gpu([1.0, 2.0, 3.0]))) == [8.0, 16.0, 24.0] end From 1e79ba035844890cdb235d75047d09926c6879ef Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 30 May 2019 00:11:01 -0700 Subject: [PATCH 4/6] Allow indexing in jacobian --- test/cuda/cuda.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/cuda/cuda.jl b/test/cuda/cuda.jl index b3fbb26439..5a5115e1cc 100644 --- a/test/cuda/cuda.jl +++ b/test/cuda/cuda.jl @@ -1,5 +1,6 @@ using Flux, Flux.Tracker, CuArrays, Test using Flux: gpu +using CuArrays: @allowscalar @info "Testing GPU Support" @@ -50,10 +51,11 @@ end @testset "Jacobian on GPU" begin # https://github.com/FluxML/Tracker.jl/pull/33 - @test collect(jacobian(identity, gpu([0.0, 0.0]))) == [1 0; 0 1] - @test collect(jacobian(softmax, gpu(ones(2)))) == [0.25 -0.25; -0.25 0.25] - @test collect(gradient(x -> sum(jacobian(y -> y .^ 2, x) .^ 2), - gpu([1.0, 2.0, 3.0]))) == [8.0, 16.0, 24.0] + @test collect(@allowscalar jacobian(identity, gpu([0.0, 0.0]))) == [1 0; 0 1] + @test collect(@allowscalar jacobian(softmax, gpu(ones(2)))) == + [0.25 -0.25; -0.25 0.25] + @test collect(@allowscalar gradient(x -> sum(jacobian(y -> y .^ 2, x) .^ 2), + gpu([1.0, 2.0, 3.0]))) == [8.0, 16.0, 24.0] end if CuArrays.libcudnn != nothing From f51b5b8f8980bf7d808917821ce1f9029f70768b Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 30 May 2019 00:21:19 -0700 Subject: [PATCH 5/6] Fix nested jacobian test --- test/cuda/cuda.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/cuda/cuda.jl b/test/cuda/cuda.jl index 5a5115e1cc..7b866015aa 100644 --- a/test/cuda/cuda.jl +++ b/test/cuda/cuda.jl @@ -55,7 +55,8 @@ end @test collect(@allowscalar jacobian(softmax, gpu(ones(2)))) == [0.25 -0.25; -0.25 0.25] @test collect(@allowscalar gradient(x -> sum(jacobian(y -> y .^ 2, x) .^ 2), - gpu([1.0, 2.0, 3.0]))) == [8.0, 16.0, 24.0] + gpu([1.0, 2.0, 3.0]))[1]) == + [8.0, 16.0, 24.0] end if CuArrays.libcudnn != nothing From 7541724bafe94dad088bde3f7d7d37478bc58290 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 30 May 2019 00:53:55 -0700 Subject: [PATCH 6/6] [DON'T MERGE] Use https://github.com/FluxML/Tracker.jl/commit/f6b0ad40a196059b50fd95045b97607ae82b0232 --- Manifest.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 13dcbbbd11..ac0a9ef6a4 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -272,8 +272,8 @@ version = "0.5.3" [[Tracker]] deps = ["Adapt", "DiffRules", "ForwardDiff", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Printf", "Random", "Requires", "SpecialFunctions", "Statistics", "Test"] -git-tree-sha1 = "2e516162af7f1e208b62ef3da3af0d094a44aab1" -repo-rev = "9c2c05ec6d785996d83f7f59e3209461fcc36c01" +git-tree-sha1 = "2b1ff1239e747816e9fb858a38f671ef794b2b2d" +repo-rev = "f6b0ad40a196059b50fd95045b97607ae82b0232" repo-url = "https://github.com/FluxML/Tracker.jl.git" uuid = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" version = "0.2.2"