ONNX

import sol
import numpy as np

model  = sol.optimize("myModel.onnx") # no input description needed, as provided by model itself!
# or if you want to override the shape of the model
model  = sol.optimize("myModel.onnx", [np.rand(1, 3, 224, 224), ...], {'named_tensor': np.rand(3, 2, 1)})

input  = np.random.rand(1, 3, 224, 224)
output = model(input)

F.A.Q.

How can I execute an ONNX model on an accelerator device?

By default the ONNX frontend returns a Numpy executable model. You can either set sol.optimize("model.onnx", framework='pytorch') to a framework that supports accelerator devices or use the sol.device.set(‘device_type’, device_idx) API for transparent offloading.

How can I train an ONNX model?

The ONNX format does not store information about trainable parameters. However, you can set sol.optimize(“model.onnx”, framework=“pytorch”) to load the ONNX model into PyTorch. Then use iterate over model.parameters() and set the param.requires_grad = True for all parameters that shall be trained.

Supported Layers

Please refer to https://github.com/onnx/onnx/blob/master/docs/Operators.md for how these functions are used. This documentation only contains which layers, functions and tensor functionality are currently implemented within SOL.

Abs, Acos, Acosh, Add, And, ArgMax, ArgMin, Asin, Asinh, Atan, Atanh, AveragePool, BatchNormalization, Bernoulli, Cast, CastLike, Ceil, Celu, Clip, Concat, Constant, ConstantOfShape, Conv, ConvTranspose, Cos, Cosh, CumSum, DepthToSpace, Div, Dropout, Elu, Equal, Erf, Exp, Expand, Flatten, Floor, Gather, Gemm, GlobalAveragePool, GlobalMaxPool, Greater, GreaterOrEqual, HardSigmoid, HardSwish, Identity, InstanceNormalization, IsInf, IsNaN, LRN, LeakyRelu, Less, LessOrEqual, Log, LogSoftmax, MatMul, Max, MaxPool, MaxUnPool, Min, Mod, Mul, Neg, NonZero, Not, OneHot, Or, PRelu, Pad, Pow, RandomUniform, RandomUniformLike, Range, Reciprocal, ReduceL1, ReduceL2, ReduceMax, ReduceMean, ReduceMin, ReduceProd, ReduceSum, Relu, Reshape, Resize, Round, Selu, Shape, Shrink, Sigmoid, Sign, Sin, Sinh, Slice, Softmax, Softmin, Softplus, Softsign, Split, Sqrt, Squeeze, Sub, Sum, Tan, Tanh, Tile, Transpose, Trilu, Unsqueeze, Where, Xor