MCPcopy Index your code
hub / github.com/AdvancedClimateSystems/gonnx

github.com/AdvancedClimateSystems/gonnx @v1.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.0 ↗ · + Follow
1,272 symbols 3,549 edges 135 files 660 documented · 52%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

GONNX

image info

License: MPL 2.0

The goal of this package is to provide an easy way of running ONNX models in Go. This package is intended for inference usage of ONNX models. The package can be used to load an .onnx file and perform inference using the model described by this file.

Currently, we are implementing ONNX operation set 13, and we plan to add all opsets following this one as well. Feel free to contribute by implementing operators!

Getting started

Installation & setup

First, install Go on your machine. Then, clone the repository:

git clone https://github.com/AdvancedClimateSystems/gonnx.git
cd gonnx

Then, install the dependencies as follows:

make install
make install_lint
make install_gotestsum

Usage

A simple example is shown below:

package main

import (
    "github.com/advancedclimatesystems/gonnx"
    "gorgonia.org/tensor"
)


func main() {
    model, err := gonnx.NewModel("./path_to_onnx/model.onnx")
    if err != nil {
        log.Fatal(err)
    }

    var inputs map[string]*tensor.Tensor
    inputs = // However you construct inputs. It must have a tensor for all inputs.

    result, err := model.Run(inputs)
    if err != nil {
        log.Fatal(err)
    }
}

Tests

Most of the code should be tested. If you add operators (or an entire opset version) make sure you add unit tests as wel as tests for the ONNX test suite

The GONNX test suite consists of unit tests and integration tests, the standard provided by ONNX.

The ONNX test data is not stored in the repository, hence one needs to download it first:

make test_data

Now, one can run all tests using (which runs both integration and unit tests):

make test

Because the current implementation is lacking certain opset versions, some of the tests from ONNX will not run. All tests that are skipped can be found in ops_test.go, as well as the reason that particular test is skipped. We try to be explicit in which tests are ran and which are skipped.

How to Contribute

Any kind of contribution is welcome. Try to keep the style consistent and make sure all linter checks succeed before opening a pull request.

Pull requests

Our workflow is based on the github-flow .

  1. Create a new issue.
  2. Fork the project.
  3. Clone your fork and add the upstream. bash git remote add upstream https://github.com/AdvancedClimateSystems/gonnx.git

  4. Pull new changes from the upstream. bash git checkout main git fetch upstream git merge upstream/main

  5. Create a feature branch bash git checkout -b <branch-name>

  6. Commit your changes and reference the issue number in your comment. bash git commit -m "Issue #<issue-ref> : <your message>"

  7. Push the feature branch to your remote repository. bash git push origin <branch-name>

  8. Open new pull request.

Code of conduct

Welcome to the GONNX community! To make sure everyone has a blast while working together, here's our quick code of conduct:

  1. Be respectful and kind to everyone. No hate speech or harassment allowed.
  2. Keep conversations on topic and respectful.
  3. Respect other people's work and intellectual property rights.
  4. Follow the guidelines for contributing to the project and make your first pull request! Anything is welcome :slightly_smiling_face:
  5. If you see something, say something. Report any violations to the maintainers.
  6. Have fun! We're all here to work on something awesome together, so let's make the most of it!

By participating in the GONNX project, you're agreeing to follow these guidelines and make sure everyone has a good time. Whether you're a seasoned veteran or a newcomer, we're excited to have you here. Let's make something amazing!

Authors

Extension points exported contracts — how you extend this code

Operator (Interface)
Operator is the base interface for all operators. [51 implementers]
ops/operator.go
OpGetter (FuncType)
OpGetter is a function that gets an operator based on a string.
opset.go
Number (Interface)
Number is a type which represents a number.
ops/convert.go
Activation (FuncType)
Activation is an activation function.
ops/activation.go
BinaryOp (FuncType)
BinaryOp describes a general operation between 2 tensors with 1 tensor as result.
ops/binary_op.go
FloatType (Interface)
FloatType is a type that describes a float value. Can be either float32 or float64.
ops/types.go
InputFixture (FuncType)
InputFixture is a function that generates inputs for ops. Useful in testing.
ops/fixtures.go
BooleanOp (FuncType)
BooleanOp describes a binary operation between two booleans that also returns a boolean.
ops/binary_op.go

Core symbols most depended-on inside this repo

TensorWithBackingFixture
called by 566
ops/fixtures.go
ErrInvalidInputType
called by 81
ops/errors.go
Apply
called by 64
ops/operator.go
ValidateInputs
called by 51
ops/validate_inputs.go
ErrInvalidInputCount
called by 44
ops/errors.go
RandomFloat32TensorFixture
called by 29
ops/fixtures.go
NElements
called by 26
ops/utils.go
Float32TensorFixture
called by 22
ops/fixtures.go

Shape

Method 680
Function 474
Struct 91
TypeAlias 15
FuncType 5
Interface 5
Class 2

Languages

Go99%
Python1%

Modules by API surface

onnx/onnx.proto3.pb.go288 symbols
onnx/graph_proto.go44 symbols
ops/errors.go35 symbols
ops/opset13/conv.go23 symbols
model.go20 symbols
ops/opset13/conv_test.go16 symbols
ops/binary_op.go16 symbols
ops/utils_test.go15 symbols
ops/utils.go15 symbols
ops/opset13/lstm.go15 symbols
ops/opset13/gru.go15 symbols
ops/opset13/squeeze.go13 symbols

For agents

$ claude mcp add gonnx \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact