From 7feb7d45676fe379df0db73dc9f357e54c774d39 Mon Sep 17 00:00:00 2001 From: EvilDunk Date: Wed, 11 Dec 2024 16:20:43 -0500 Subject: [PATCH 01/16] Adding support for And --- src/load.jl | 4 ++++ src/ops.jl | 7 +++++++ src/save.jl | 5 +++++ test/saveload.jl | 10 ++++++++++ 4 files changed, 26 insertions(+) diff --git a/src/load.jl b/src/load.jl index 0c26d4e..6184976 100644 --- a/src/load.jl +++ b/src/load.jl @@ -67,6 +67,10 @@ function load_node!(tape::Tape, ::OpConfig{:ONNX, :Acosh}, args::VarVec, attrs:: return push_call!(tape, _acosh, args[1]) end +function load_node!(tape::Tape, ::OpConfig{:ONNX, :And}, args::VarVec, attrs::AttrDict) + return push_call!(tape, and, args[1], args[2]) +end + function load_node!(tape::Tape, nd::NodeProto, backend::Symbol) args = [tape.c.name2var[name] for name in nd.input] attrs = convert(Dict{Symbol, Any}, Dict(nd.attribute)) diff --git a/src/ops.jl b/src/ops.jl index 0653e58..36c11d0 100644 --- a/src/ops.jl +++ b/src/ops.jl @@ -45,6 +45,13 @@ function onnx_flatten(x; axis = 1) return flatten(x; dim = dim) end +function and(A, B) + # Numpy type broadcasting + if size(A != B) + A = A' + return A .&& B +end + add(xs...) = .+(xs...) sub(xs...) = .-(xs...) _sin(x) = sin.(x) diff --git a/src/save.jl b/src/save.jl index 9944e55..0663b31 100644 --- a/src/save.jl +++ b/src/save.jl @@ -136,6 +136,11 @@ function save_node!(g::GraphProto, ::OpConfig{:ONNX, typeof(_acosh)}, op::Umlaut push!(g.node, nd) end +function save_node!(g::GraphProto, ::OpConfig{:ONNX, typeof(and)}, op::Umlaut.Call) + nd = NodeProto("And", op) + push!(g.node, nd) +end + function save_node!(g::GraphProto, ::OpConfig{:ONNX, typeof(*)}, op::Umlaut.Call) nd = NodeProto( input=[onnx_name(v) for v in reverse(op.args)], diff --git a/test/saveload.jl b/test/saveload.jl index 33df215..19ab7ce 100644 --- a/test/saveload.jl +++ b/test/saveload.jl @@ -50,6 +50,16 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name ort_test(ONNX._acosh, A) end + @testset "And" begin + A = Matrix{Bool}(undef, 3, 4) + B = Matrix{Bool}(undef, 3, 4) + ort_test(ONNX.and, A, B) + # Test implementation for Numpy-type broadcasting + C = Matrix{Bool}(undef, 4, 3) + ort_test(ONNX.and, A, C) + + end + @testset "Gemm" begin A, B, C = (rand(3, 4), rand(3, 4), rand(3, 3)) ort_test(ONNX.onnx_gemm, A, B') From dfb62eb4f39e8c80a030ad66559d3337de053b64 Mon Sep 17 00:00:00 2001 From: EvilDunk Date: Wed, 11 Dec 2024 16:23:23 -0500 Subject: [PATCH 02/16] Adding support for And --- src/ops.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ops.jl b/src/ops.jl index 36c11d0..6878992 100644 --- a/src/ops.jl +++ b/src/ops.jl @@ -49,6 +49,7 @@ function and(A, B) # Numpy type broadcasting if size(A != B) A = A' + end return A .&& B end From 52e86da53e08f448a18006a0b90f89ad86c5fc55 Mon Sep 17 00:00:00 2001 From: EvilDunk Date: Wed, 11 Dec 2024 16:25:42 -0500 Subject: [PATCH 03/16] Adding support for And --- src/ops.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ops.jl b/src/ops.jl index 6878992..441f390 100644 --- a/src/ops.jl +++ b/src/ops.jl @@ -47,7 +47,7 @@ end function and(A, B) # Numpy type broadcasting - if size(A != B) + if (size(A) != size(B)) A = A' end return A .&& B From 1a955926d126bf9383d279fde22e5ca31c9083c1 Mon Sep 17 00:00:00 2001 From: EvilDunk Date: Wed, 11 Dec 2024 16:33:24 -0500 Subject: [PATCH 04/16] Adding support for And --- test/saveload.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/saveload.jl b/test/saveload.jl index 19ab7ce..a946a48 100644 --- a/test/saveload.jl +++ b/test/saveload.jl @@ -51,11 +51,15 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name end @testset "And" begin - A = Matrix{Bool}(undef, 3, 4) - B = Matrix{Bool}(undef, 3, 4) + A = [0 1 0; 1 1 0; 0 1 1; 1 1 1] + A = Bool(A) + B = [1 0 0; 1 0 0; 0 0 1; 1 1 0] + B = Bool(B) ort_test(ONNX.and, A, B) + # Test implementation for Numpy-type broadcasting - C = Matrix{Bool}(undef, 4, 3) + C = [1 0 0 1; 1 0 0 1; 0 0 1 0] + C = Bool(C) ort_test(ONNX.and, A, C) end From 923e9ef3b7a278f085a4c9bbc09db2d6ca540e84 Mon Sep 17 00:00:00 2001 From: EvilDunk Date: Wed, 11 Dec 2024 16:35:02 -0500 Subject: [PATCH 05/16] Adding support for And --- test/saveload.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/saveload.jl b/test/saveload.jl index a946a48..1a56b28 100644 --- a/test/saveload.jl +++ b/test/saveload.jl @@ -52,14 +52,14 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name @testset "And" begin A = [0 1 0; 1 1 0; 0 1 1; 1 1 1] - A = Bool(A) + A = Bool.(A) B = [1 0 0; 1 0 0; 0 0 1; 1 1 0] - B = Bool(B) + B = Bool.(B) ort_test(ONNX.and, A, B) # Test implementation for Numpy-type broadcasting C = [1 0 0 1; 1 0 0 1; 0 0 1 0] - C = Bool(C) + C = Bool.(C) ort_test(ONNX.and, A, C) end From c86b0338e994234f11dbbf3aba00bed7667510ac Mon Sep 17 00:00:00 2001 From: EvilDunk Date: Wed, 11 Dec 2024 16:37:34 -0500 Subject: [PATCH 06/16] Adding support for And --- test/saveload.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/saveload.jl b/test/saveload.jl index 1a56b28..ce5d069 100644 --- a/test/saveload.jl +++ b/test/saveload.jl @@ -52,14 +52,14 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name @testset "And" begin A = [0 1 0; 1 1 0; 0 1 1; 1 1 1] - A = Bool.(A) + A = Int8.(A) B = [1 0 0; 1 0 0; 0 0 1; 1 1 0] - B = Bool.(B) + B = Int8.(B) ort_test(ONNX.and, A, B) # Test implementation for Numpy-type broadcasting C = [1 0 0 1; 1 0 0 1; 0 0 1 0] - C = Bool.(C) + C = Int8.(C) ort_test(ONNX.and, A, C) end From 714337bc3c1f0d828194b5222e6e55a9e539d1a4 Mon Sep 17 00:00:00 2001 From: EvilDunk Date: Wed, 11 Dec 2024 16:42:08 -0500 Subject: [PATCH 07/16] Adding support for And --- test/saveload.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/saveload.jl b/test/saveload.jl index ce5d069..1fd1a3c 100644 --- a/test/saveload.jl +++ b/test/saveload.jl @@ -52,14 +52,14 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name @testset "And" begin A = [0 1 0; 1 1 0; 0 1 1; 1 1 1] - A = Int8.(A) + A = Matrix{Bool}(A) B = [1 0 0; 1 0 0; 0 0 1; 1 1 0] - B = Int8.(B) + B = Matrix{Bool}(B) ort_test(ONNX.and, A, B) # Test implementation for Numpy-type broadcasting C = [1 0 0 1; 1 0 0 1; 0 0 1 0] - C = Int8.(C) + C = Matrix{Bool}(C) ort_test(ONNX.and, A, C) end From 03376b88e9fc9d1382f2ae0d622653af5d110d65 Mon Sep 17 00:00:00 2001 From: Duncan Starkenburg Date: Thu, 26 Dec 2024 16:37:52 -0800 Subject: [PATCH 08/16] Changes (Adding support for And) --- .gitignore | 3 ++- Project.toml | 1 + src/load.jl | 4 ++-- src/ops.jl | 10 +++++----- test/saveload.jl | 32 ++++++++++++++++++-------------- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index aebeeb7..0b68cda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ *.jl.cov *.jl.*.cov *.jl.mem +*.Identifier test/models test/onnx/ Manifest.toml .vscode/ *.onnx -/test/backend_tests/ +/test/backend_tests/ \ No newline at end of file diff --git a/Project.toml b/Project.toml index 9329a20..a89f1a7 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,7 @@ version = "0.2.7" EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +ONNXRunTime = "e034b28e-924e-41b2-b98f-d2bbeb830c6a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" ProtoBuf = "3349acd9-ac6a-5e09-bcdb-63829b23a429" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/src/load.jl b/src/load.jl index 6184976..b65b056 100644 --- a/src/load.jl +++ b/src/load.jl @@ -67,8 +67,8 @@ function load_node!(tape::Tape, ::OpConfig{:ONNX, :Acosh}, args::VarVec, attrs:: return push_call!(tape, _acosh, args[1]) end -function load_node!(tape::Tape, ::OpConfig{:ONNX, :And}, args::VarVec, attrs::AttrDict) - return push_call!(tape, and, args[1], args[2]) +function load_node!(tape::Tape, ::OpConfig{:ONNX, :And}, args::VarVec, attrs::AttrDict) + return push_call!(tape, and, args...) end function load_node!(tape::Tape, nd::NodeProto, backend::Symbol) diff --git a/src/ops.jl b/src/ops.jl index 441f390..c51dfb5 100644 --- a/src/ops.jl +++ b/src/ops.jl @@ -45,12 +45,12 @@ function onnx_flatten(x; axis = 1) return flatten(x; dim = dim) end -function and(A, B) - # Numpy type broadcasting - if (size(A) != size(B)) - A = A' +function and(x, y) + if (size(x)[2] == size(y)[1] && size(x)[1] == size(y)[2]) + z = permutedims(x) + return y .&& z end - return A .&& B + return y .&& x end add(xs...) = .+(xs...) diff --git a/test/saveload.jl b/test/saveload.jl index 1fd1a3c..9d602ef 100644 --- a/test/saveload.jl +++ b/test/saveload.jl @@ -14,6 +14,24 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name ort_test(tape, args...) end + @testset "And" begin + args = [0 1 0; 1 1 0; 0 1 1; 1 1 1], [1 0 0; 1 0 0; 0 0 1; 1 1 0] + args = Tuple(convert(Matrix{Bool}, A) for A in args) + tape = Tape(ONNXCtx()) + inp = [push!(tape, Input(arg)) for arg in args] + out1 = push_call!(tape, ONNX.and, inp...) + tape.result = out1 + ort_test(tape, args...) + + args = [1 0 0 1; 0 0 0 0; 1 1 1 0], [0 1 0; 1 1 0; 0 1 1; 1 1 1] + args = Tuple(convert(Matrix{Bool}, A) for A in args) + tape = Tape(ONNXCtx()) + inp = [push!(tape, Input(arg)) for arg in args] + out1 = push_call!(tape, ONNX.and, inp...) + tape.result = out1 + ort_test(tape, args...) + end + @testset "Basic ops" begin args = (rand(3, 4), rand(3, 4)) ort_test(ONNX.add, args...) @@ -50,20 +68,6 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name ort_test(ONNX._acosh, A) end - @testset "And" begin - A = [0 1 0; 1 1 0; 0 1 1; 1 1 1] - A = Matrix{Bool}(A) - B = [1 0 0; 1 0 0; 0 0 1; 1 1 0] - B = Matrix{Bool}(B) - ort_test(ONNX.and, A, B) - - # Test implementation for Numpy-type broadcasting - C = [1 0 0 1; 1 0 0 1; 0 0 1 0] - C = Matrix{Bool}(C) - ort_test(ONNX.and, A, C) - - end - @testset "Gemm" begin A, B, C = (rand(3, 4), rand(3, 4), rand(3, 3)) ort_test(ONNX.onnx_gemm, A, B') From ce59382bc33f16fba4a86a32a1871b055ce759ba Mon Sep 17 00:00:00 2001 From: Duncan Starkenburg Date: Thu, 9 Jan 2025 14:09:43 -0800 Subject: [PATCH 09/16] Adding support for And --- src/ops.jl | 6 +----- test/saveload.jl | 20 +++++++------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/ops.jl b/src/ops.jl index c51dfb5..705331c 100644 --- a/src/ops.jl +++ b/src/ops.jl @@ -46,11 +46,7 @@ function onnx_flatten(x; axis = 1) end function and(x, y) - if (size(x)[2] == size(y)[1] && size(x)[1] == size(y)[2]) - z = permutedims(x) - return y .&& z - end - return y .&& x + return x .&& y end add(xs...) = .+(xs...) diff --git a/test/saveload.jl b/test/saveload.jl index 9d602ef..0ff3834 100644 --- a/test/saveload.jl +++ b/test/saveload.jl @@ -15,21 +15,15 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name end @testset "And" begin + # Testing matricies of similar shape args = [0 1 0; 1 1 0; 0 1 1; 1 1 1], [1 0 0; 1 0 0; 0 0 1; 1 1 0] - args = Tuple(convert(Matrix{Bool}, A) for A in args) - tape = Tape(ONNXCtx()) - inp = [push!(tape, Input(arg)) for arg in args] - out1 = push_call!(tape, ONNX.and, inp...) - tape.result = out1 - ort_test(tape, args...) + args = convert.(Matrix{Bool}, args) + ort_test(ONNX.and, args...) - args = [1 0 0 1; 0 0 0 0; 1 1 1 0], [0 1 0; 1 1 0; 0 1 1; 1 1 1] - args = Tuple(convert(Matrix{Bool}, A) for A in args) - tape = Tape(ONNXCtx()) - inp = [push!(tape, Input(arg)) for arg in args] - out1 = push_call!(tape, ONNX.and, inp...) - tape.result = out1 - ort_test(tape, args...) + # Testing Numpy-style broadcasting + args = [1 0 0; 0 0 1; 1 1 1], [0 1 0] + args = convert.(Matrix{Bool}, args) + ort_test(ONNX.and, args...) end @testset "Basic ops" begin From 81e77f005c8fa51effc03fd8eb8c359457b985b8 Mon Sep 17 00:00:00 2001 From: Duncan Starkenburg <45837337+dstarkenburg@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:31:43 -0800 Subject: [PATCH 10/16] Update .gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0b68cda..aebeeb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,9 @@ *.jl.cov *.jl.*.cov *.jl.mem -*.Identifier test/models test/onnx/ Manifest.toml .vscode/ *.onnx -/test/backend_tests/ \ No newline at end of file +/test/backend_tests/ From a561d56c42aa9787cf623b10fabdb63bdacd68fb Mon Sep 17 00:00:00 2001 From: Duncan Starkenburg <45837337+dstarkenburg@users.noreply.github.com> Date: Fri, 10 Jan 2025 00:02:07 -0800 Subject: [PATCH 11/16] Update Project.toml --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index a89f1a7..9329a20 100644 --- a/Project.toml +++ b/Project.toml @@ -6,7 +6,6 @@ version = "0.2.7" EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" -ONNXRunTime = "e034b28e-924e-41b2-b98f-d2bbeb830c6a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" ProtoBuf = "3349acd9-ac6a-5e09-bcdb-63829b23a429" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" From 1b3d0fbe7c31e95735fe6f898418b7139601e97f Mon Sep 17 00:00:00 2001 From: Duncan Starkenburg Date: Fri, 10 Jan 2025 00:08:24 -0800 Subject: [PATCH 12/16] Changes --- src/ops.jl | 2 +- test/saveload.jl | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ops.jl b/src/ops.jl index 705331c..9765fa4 100644 --- a/src/ops.jl +++ b/src/ops.jl @@ -46,7 +46,7 @@ function onnx_flatten(x; axis = 1) end function and(x, y) - return x .&& y + return x .& y end add(xs...) = .+(xs...) diff --git a/test/saveload.jl b/test/saveload.jl index 0ff3834..4379e4b 100644 --- a/test/saveload.jl +++ b/test/saveload.jl @@ -16,13 +16,11 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name @testset "And" begin # Testing matricies of similar shape - args = [0 1 0; 1 1 0; 0 1 1; 1 1 1], [1 0 0; 1 0 0; 0 0 1; 1 1 0] - args = convert.(Matrix{Bool}, args) + args = rand(Bool, 3, 4), rand(Bool, 3, 4) ort_test(ONNX.and, args...) # Testing Numpy-style broadcasting - args = [1 0 0; 0 0 1; 1 1 1], [0 1 0] - args = convert.(Matrix{Bool}, args) + args = rand(Bool, 3, 3), rand(Bool, 1, 3) ort_test(ONNX.and, args...) end From 04d9d8209ca56e85702c3722bbdf6c3415e31e2b Mon Sep 17 00:00:00 2001 From: Duncan Starkenburg Date: Fri, 17 Jan 2025 21:23:21 -0500 Subject: [PATCH 13/16] Bump minimal version --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 9329a20..4bbe845 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ONNX" uuid = "d0dd6a25-fac6-55c0-abf7-829e0c774d20" -version = "0.2.7" +version = "0.3.0" [deps] EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56" @@ -19,4 +19,4 @@ NNlib = "0.8, 0.9" ProtoBuf = "1.0" StaticArrays = "1" Umlaut = "0.4, 0.5, 0.6, 0.7" -julia = "1.6" +julia = "1.10" From db4bc257dd479bc0dc819f566a90703dbc4ca67c Mon Sep 17 00:00:00 2001 From: Duncan Starkenburg <45837337+dstarkenburg@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:25:06 -0500 Subject: [PATCH 14/16] Update Test.yml --- .github/workflows/Test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 018d473..fed8942 100755 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -12,8 +12,8 @@ jobs: fail-fast: false matrix: version: - - '1.6' - - '1.9' + - '1.10' + - '1' os: - ubuntu-latest arch: From f1d2b86e82ad82d080dc5f03d7d453973b6b9a1b Mon Sep 17 00:00:00 2001 From: Duncan Starkenburg <45837337+dstarkenburg@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:34:58 -0500 Subject: [PATCH 15/16] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 4bbe845..54a504f 100644 --- a/Project.toml +++ b/Project.toml @@ -18,5 +18,5 @@ EnumX = "1" NNlib = "0.8, 0.9" ProtoBuf = "1.0" StaticArrays = "1" -Umlaut = "0.4, 0.5, 0.6, 0.7" +Umlaut = "0.7" julia = "1.10" From ea7f49324d4ac46f39a2626e2be2ef7e03f6fb41 Mon Sep 17 00:00:00 2001 From: Duncan Starkenburg <45837337+dstarkenburg@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:37:00 -0500 Subject: [PATCH 16/16] Update Project.toml --- test/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index 7e5a271..8efc08c 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -7,4 +7,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Umlaut = "92992a2b-8ce5-4a9c-bb9d-58be9a7dc841" [compat] -Umlaut = "0.4" +Umlaut = "0.7"