diff --git a/.buildkite/pipeline.yaml b/.buildkite/pipeline.yaml index 4b40ac4..5450e3d 100644 --- a/.buildkite/pipeline.yaml +++ b/.buildkite/pipeline.yaml @@ -6,27 +6,28 @@ steps: - JuliaCI/julia-test#v1: ~ agents: queue: "juliagpu" - cuda: "*" - timeout_in_minutes: 60 + cuda: "true" + cap: sm_75 + command: | + TMP_PROJECT=`mktemp -d` + + cd $$TMP_PROJECT - - label: "GPU integration with julia v1" - plugins: - - JuliaCI/julia#v1: - version: "1" - - JuliaCI/julia-test#v1: ~ - agents: - queue: "juliagpu" - cuda: "*" - env: - JULIA_CUDA_USE_BINARYBUILDER: "true" - timeout_in_minutes: 60 + touch Project.toml + cat < LocalPreferences.toml + [CUDA_Runtime_jll] + version = "10.2" + EOT + + export CUDA_RUNTIME_ROOT=`julia --project --eval ' + using Pkg + Pkg.add(name="CUDA_Runtime_jll", version="0.2") + using CUDA_Runtime_jll + println(CUDA_Runtime_jll.artifact_dir) + '` - # - label: "GPU nightly" - # plugins: - # - JuliaCI/julia#v1: - # version: "nightly" - # - JuliaCI/julia-test#v1: ~ - # agents: - # queue: "juliagpu" - # cuda: "*" - # timeout_in_minutes: 60 + ls -1 $$CUDA_RUNTIME_ROOT/lib/libcudart* + export LD_LIBRARY_PATH=$$CUDA_RUNTIME_ROOT/lib + + cd $$BUILDKITE_BUILD_CHECKOUT_PATH + timeout_in_minutes: 60 diff --git a/.gitignore b/.gitignore index 598ae79..ccad2ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +/Manifest.toml /.vscode diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index 36868c8..0000000 --- a/Manifest.toml +++ /dev/null @@ -1,134 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -[[Artifacts]] -deps = ["Pkg"] -git-tree-sha1 = "c30985d8821e0cd73870b17b0ed0ce6dc44cb744" -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" -version = "1.3.0" - -[[Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[ChainRulesCore]] -deps = ["LinearAlgebra", "MuladdMacro", "SparseArrays"] -git-tree-sha1 = "15081c431bb25848ad9b0d172a65794f3a3e197a" -uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" -version = "0.9.24" - -[[CompilerSupportLibraries_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "8e695f735fca77e9708e795eda62afdb869cbb70" -uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" -version = "0.3.4+0" - -[[Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[FillArrays]] -deps = ["LinearAlgebra", "Random", "SparseArrays"] -git-tree-sha1 = "8bd8e47ff5d34b20f0aa9641988eb660590008bc" -uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.11.0" - -[[InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[JLLWrappers]] -git-tree-sha1 = "04b49c556240b62d5a799e94c63d5fc14d3c07cd" -uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" -version = "1.1.4" - -[[LibGit2]] -deps = ["Printf"] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[MacroTools]] -deps = ["Markdown", "Random"] -git-tree-sha1 = "6a8a2a625ab0dea913aba95c11370589e0239ff0" -uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.6" - -[[Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[MuladdMacro]] -git-tree-sha1 = "c6190f9a7fc5d9d5915ab29f2134421b12d24a68" -uuid = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" -version = "0.2.2" - -[[NNlib]] -deps = ["ChainRulesCore", "LinearAlgebra", "Pkg", "Requires", "Statistics"] -git-tree-sha1 = "6af947f07c12f7c2f965b3145208b7b0df03bb34" -uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" -version = "0.7.10" - -[[Pkg]] -deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[Requires]] -deps = ["UUIDs"] -git-tree-sha1 = "cfbac6c1ed70c002ec6361e7fd334f02820d6419" -uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "1.1.2" - -[[SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[Torch_jll]] -deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] -git-tree-sha1 = "e5ba45e41a25b732f3bfd3d85b976f538d7d4ad6" -uuid = "c12fb04c-f5e9-5c82-b5d6-b53f8f8d9a32" -version = "1.4.0+0" - -[[UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[ZygoteRules]] -deps = ["MacroTools"] -git-tree-sha1 = "9e7a1e8ca60b742e508a315c17eef5211e7fbfd7" -uuid = "700de1a5-db45-46bc-99cf-38207098b444" -version = "0.2.1" diff --git a/Project.toml b/Project.toml index 7e1010f..ec54e86 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Torch" uuid = "6a2ea274-3061-11ea-0d63-ff850051a295" -authors = ["dhairyagandhi96 "] +authors = ["Dhairya Gandhi "] version = "0.1.2" [deps] @@ -15,19 +15,19 @@ ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444" [compat] FillArrays = "0.8, 0.11, 0.13" -NNlib = "0.6, 0.7" +Flux = "0.11" +NNlib = "0.6, 0.7.0 - 0.7.24" Requires = "1" Torch_jll = "~1.4" +Zygote = "0.5" ZygoteRules = "0" julia = "1.4" [extras] -Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" -IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e" -LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Metalhead = "dbeba491-748d-5e0e-a39e-b530a07fa0cc" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [targets] -test = ["Test", "Flux", "Metalhead", "Documenter", "IterTools", "LinearAlgebra"] +test = ["Flux", "Metalhead", "Test", "Zygote"] diff --git a/test/flux_tests.jl b/test/flux_tests.jl new file mode 100644 index 0000000..1cba2a0 --- /dev/null +++ b/test/flux_tests.jl @@ -0,0 +1,21 @@ +using Flux +using Metalhead +using Test +using Torch +using Torch: Tensor, tensor + +@testset "Flux" begin + resnet = ResNet() + tresnet = Flux.fmap(Torch.to_tensor, resnet.layers) + + ip = rand(Float32, 224, 224, 3, 1) # An RGB Image + tip = tensor(ip, dev = 0) # 0 => GPU:0 in Torch + + top = tresnet(tip) + op = resnet.layers(ip) + + gs = gradient(() -> sum(tresnet(tip)), Flux.params(tresnet)) + @test top isa Tensor + @test size(top) == size(op) + @test gs isa Flux.Zygote.Grads +end diff --git a/test/runtests.jl b/test/runtests.jl index 80aa3da..8547b05 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,29 +1,7 @@ -using Test, Flux, Metalhead -using Torch -using Torch: Tensor, tensor +using Test -@testset "Movement" begin - r = rand(Float32, 3,3) - tr = tensor(r, dev = 0) - @test tr isa Tensor - @test tr .* tr isa Tensor - - cr = collect(tr) - @test cr isa Array -end - -@testset "Flux" begin - resnet = ResNet() - tresnet = Flux.fmap(Torch.to_tensor, resnet.layers) - - ip = rand(Float32, 224, 224, 3, 1) # An RGB Image - tip = tensor(ip, dev = 0) # 0 => GPU:0 in Torch - - top = tresnet(tip) - op = resnet.layers(ip) - - gs = gradient(() -> sum(tresnet(tip)), Flux.params(tresnet)) - @test top isa Tensor - @test size(top) == size(op) - @test gs isa Flux.Zygote.Grads +@testset verbose=true "Torch" begin + include("flux_tests.jl") + include("tensor_movement_tests.jl") + include("tensor_nnlib_tests.jl") end diff --git a/test/tensor_movement_tests.jl b/test/tensor_movement_tests.jl new file mode 100644 index 0000000..4e53fbb --- /dev/null +++ b/test/tensor_movement_tests.jl @@ -0,0 +1,12 @@ +using Test +using Torch: Tensor, tensor + +@testset "Movement" begin + r = rand(Float32, 3,3) + tr = tensor(r, dev = 0) + @test tr isa Tensor + @test tr .* tr isa Tensor + + cr = collect(tr) + @test cr isa Array +end diff --git a/test/test_nnlib.jl b/test/tensor_nnlib_tests.jl similarity index 95% rename from test/test_nnlib.jl rename to test/tensor_nnlib_tests.jl index db9eeff..d217347 100644 --- a/test/test_nnlib.jl +++ b/test/tensor_nnlib_tests.jl @@ -22,7 +22,7 @@ using Torch: tensor test_output = NNlib.depthwiseconv(x, w, pad = (0,0), stride = (1,1 ), dilation = (1, 1)) test_output = Array(test_output) - @test maximum(abs.(test_output - expected_output)) < 10 * eps(Float32) + @test maximum(abs.(test_output - expected_output)) < 1e3 * eps(Float32) # Numerical accuracy adjusted wrt. CI end end end @@ -58,7 +58,7 @@ end test_output = NNlib.conv(x, w, cdims) test_output = Array(test_output) - @test maximum(abs.(test_output - expected_output)) < 10 * eps(Float32) + @test maximum(abs.(test_output - expected_output)) < 1e6 * eps(Float32) # Numerical accuracy adjusted wrt. CI end end end @@ -95,7 +95,7 @@ end test_output = NNlib.conv(x, w, cdims) test_output = Array(test_output) - @test maximum(abs.(test_output - expected_output)) < 10 * eps(Float32) + @test maximum(abs.(test_output - expected_output)) < 1e4 * eps(Float32) # Numerical accuracy adjusted wrt. CI end end end @@ -138,7 +138,7 @@ end test_output = NNlib.conv(x, w, cdims) test_output = Array(test_output) - @test maximum(abs.(test_output - expected_output)) < 10 * eps(Float32) + @test maximum(abs.(test_output - expected_output)) < 1e2 * eps(Float32) # Numerical accuracy adjusted wrt. CI end end end @@ -174,7 +174,7 @@ end test_output = fn(x, pdims) test_output = Array(test_output) - @test maximum(abs.(test_output - expected_output)) < 10 * eps(Float32) + @test maximum(abs.(test_output - expected_output)) < 1e1 * eps(Float32) end end end @@ -198,6 +198,6 @@ end end test_output = Array(test_output) - @test maximum(abs.(test_output - expected_output)) < 10 * eps(Float32) + @test maximum(abs.(test_output - expected_output)) < 1e1 * eps(Float32) end end