<p><b>ONNX (Open Neural Network eXchange) is an open format for the sharing of neural network and other machine learned models between various machine learning and deep learning frameworks. As the open big data serving engine, Vespa aims to make it simple to evaluate machine learned models at serving time at scale. By adding ONNX support in Vespa in addition to our existing TensorFlow support, we’ve made it possible to evaluate models from all the commonly used ML frameworks with low latency over large amounts of data.</b></p>
<p>With the rise of deep learning in the last few years, we’ve naturally enough seen an increase of deep learning frameworks as well: TensorFlow, PyTorch/Caffe2, MxNet etc. One reason for these different frameworks to exist is that they have been developed and optimized around some characteristic, such as fast training on distributed systems or GPUs, or efficient evaluation on mobile devices. Previously, complex projects with non-trivial data pipelines have been unable to pick the best framework for any given subtask due to lacking interoperability between these frameworks. ONNX is a solution to this problem.</p>
<p><a href="https://onnx.ai/">ONNX</a> is an open format for AI models, and represents an effort to push open standards in AI forward. The goal is to help increase the speed of innovation in the AI community by enabling interoperability between different frameworks and thus streamlining the process of getting models from research to production.</p>
<p>There is one commonality between the frameworks mentioned above that enables an open format such as ONNX, and that is that they all make use of dataflow graphs in one way or another. While there are differences between each framework, they all provide APIs enabling developers to construct computational graphs and runtimes to process these graphs. Even though these graphs are conceptually similar, each framework has been a siloed stack of API, graph and runtime. The goal of ONNX is to empower developers to select the framework that works best for their project, by providing an extensible computational graph model that works as a common intermediate representation at any stage of development or deployment. </p>
<p>Vespa is an open source project which fits well within such an ecosystem, and we aim to make the process of deploying and serving models to production that have been trained on any framework as smooth as possible. Vespa is optimized toward serving and evaluating over potentially very large datasets while still responding in real time. In contrast to other ML model serving options, Vespa <a href="http://blog.vespa.ai/post/173669458506/scaling-tensorflow-model-evaluation-with-vespa">can more efficiently evaluate models over many data points</a>. As such, Vespa is an excellent choice when combining model evaluation with serving of various types of content.</p>
<p>Our ONNX support is quite similar to our <a href="http://blog.vespa.ai/post/171861434281/introducing-tensorflow-support">TensorFlow support</a>. Importing ONNX models is as simple as adding the model to the Vespa application package (under “models/”) and referencing the model using the new ONNX ranking feature:</p>
<pre>expression: sum(onnx("my_model.onnx"))</pre>
<p>The above expression runs the model and sums it to a single scalar value to use in ranking. You will have to provide the inputs to the graph. Vespa expects you to provide a macro with the same name as the input tensor. In the macro you can specify where the input should come from, be it a document field, constant or a parameter sent along with the query. More information can be had <a href="http://docs.vespa.ai/documentation/onnx.html">in the documentation about ONNX import</a>.</p>
<p>Internally, Vespa converts the ONNX operations to Vespa’s tensor API. We do the same for TensorFlow import. So the cost of evaluating ONNX and TensorFlow models are the same. We have put a lot of effort in optimizing the evaluation of tensors, and <a href="http://docs.vespa.ai/documentation/onnx.html">evaluating neural network models can be quite efficient</a>.</p>
<p>ONNX support is also quite new to Vespa, so we do not support all <a href="https://github.com/onnx/onnx/blob/master/docs/Operators.md">current ONNX operations</a>. Part of the reason we don’t support all operations yet is that some are potentially too expensive to evaluate per document, such as convolutional neural networks and recurrent networks (LSTMs etc). ONNX also contains an extension, <a href="https://github.com/onnx/onnx/blob/master/docs/Operators-ml.md">ONNX-ML</a>, which contains additional operations for non-neural network cases. Support for this extension will come later at some point. We are continually working to add functionality, so please reach out to us if there is something you would like to have added.</p>
<p>Going forward we are continually working on improving performance as well as supporting more of the ONNX (and ONNX-ML) standard. You can read more about ranking with <a href="http://docs.vespa.ai/documentation/onnx.html">ONNX models in the Vespa documentation</a>. We are excited to announce ONNX support. Let us know what you are building with it!</p>