
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!
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
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)
}
}
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.
Any kind of contribution is welcome. Try to keep the style consistent and make sure all linter checks succeed before opening a pull request.
Our workflow is based on the github-flow .
Clone your fork and add the upstream.
bash
git remote add upstream https://github.com/AdvancedClimateSystems/gonnx.git
Pull new changes from the upstream.
bash
git checkout main
git fetch upstream
git merge upstream/main
Create a feature branch
bash
git checkout -b <branch-name>
Commit your changes and reference the issue number in your comment.
bash
git commit -m "Issue #<issue-ref> : <your message>"
Push the feature branch to your remote repository.
bash
git push origin <branch-name>
Open new pull request.
Welcome to the GONNX community! To make sure everyone has a blast while working together, here's our quick code of conduct:
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!
$ claude mcp add gonnx \
-- python -m otcore.mcp_server <graph>