Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Gorgonia as a clean backend #9

Closed
owulveryck opened this issue Mar 26, 2019 · 2 comments
Closed

Gorgonia as a clean backend #9

owulveryck opened this issue Mar 26, 2019 · 2 comments

Comments

@owulveryck
Copy link
Owner

owulveryck commented Mar 26, 2019

For the POC, Gorgonia has been heavily tweaked to fit the gonum's GraphBuilder interface.

The tweaked version has been vendored as an example. This leads to a maintenance problem.
It's merely impossible to add new features to the backend.

The Gorgonia team is working on a significant refactor of the API.
Meanwhile, I am considering rewriting the Gorgonia backend to use the actual API.

My idea is to use something similar to what I did with gorgonnx some time ago.

We can create a simple GorgoniaGraph in the backend fulfilling the interfaces:

  • gonum.WeightedGraphBuilder
  • OperationCarrier
  • and issuing nodes compatible with TensorCarrier

and then a method

func (g *GorgoniaGraph) ToExprGraph() (*gorgonia.ExprGraph, error)

That would turn the graph into a gorgonia exprgraph by walking the graph starting from the input and creating the node accordingly.

Example. Assume an equation y = a * x + b that would produce this graph:

y -> add
add -> mul
add -> b
mul -> a
mul -> x

properly encoded into a Weighted Graph.

The ToExprGraph would then walk the graph (still have to figure out how to efficiently walk the graph) and create:

a := gorgonia.NodeFromAny(aT) // aT is already a tensor.Tensor
x := gorgonia.NodeFromAny(xT) // ...
// ...
m := gorgonia.Must(gorgonia.Mul(a,x))
add := gorgonia.Must(gorgonia.Add(m. b)

Do you get the drill?

What do you think?

@owulveryck owulveryck changed the title Gorgonia as a proper backend Gorgonia as a clean backend Mar 26, 2019
@owulveryck
Copy link
Owner Author

Branch gorgonia is a work in progress to make Gorgonia compatible with the backend.ComputationGraph interface

@owulveryck
Copy link
Owner Author

In progress:

cd $GOPATH/src/github.com/owulveryck/onnx-go/backend/x/gorgonnx

go test -v
=== RUN   TestAbs
=== RUN   TestAbs/TestAbs
--- PASS: TestAbs (0.00s)
    --- PASS: TestAbs/TestAbs (0.00s)
=== RUN   TestAdd
=== RUN   TestAdd/TestAdd
=== RUN   TestAdd/TestAddBcast
--- FAIL: TestAdd (0.00s)
    --- PASS: TestAdd/TestAdd (0.00s)
    --- FAIL: TestAdd/TestAddBcast (0.00s)
        test_structure.go:84: Failed to infer shape. Op: + false: Shape mismatch: (3, 4, 5) and (5)
=== RUN   TestCos
=== RUN   TestCos/TestCos
=== RUN   TestCos/TestCosExample
--- PASS: TestCos (0.00s)
    --- PASS: TestCos/TestCos (0.00s)
    --- PASS: TestCos/TestCosExample (0.00s)
FAIL
exit status 1
FAIL    github.com/owulveryck/onnx-go/backend/x/gorgonnx        0.034s

Obviously, the broadcast does not work out-of-the-box, but I will work on it.

Next:

  • implement an operation with attributes (convolution is a good choice)
  • refactor the existing code
  • create a skeleton and the associated doc to easily add new operators

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant