Skip to content

ONNX model conversion

Converting models to the ONNX format

ONNX is the Open Neural Network eXchange. You can read more about it here and explore how it is leveraged by the IBM Z Deep Learning Compiler here.

Converting or exporting trained deep learning models to the ONNX format is a requirement for leveraging the IBM Z Deep Learning Compiler, whether stand-alone or as part of Machine Learning for z/OS.

The approach in deep learning frameworks varies - for example:

  • TensorFlow models must be converted using the open-source tensorflow-onnx package.
  • PyTorch models can be exported directly to ONNX using PyTorch APIs.

Information on exporting models from other frameworks can be found on the ONNX community page.

Best practices

  • To avoid endian issues, we strongly recommend converting models to the ONNX format on the platform on which they were trained. (e.g., if a model was trained on an x86 environment, convert the model to ONNX on an x86 environment before transmitting to IBM Z or LinuxONE).

  • For Deep Learning Compiler usage: to determine which ONNX opset to specify for model conversion, see the following references:

  • On z16 or LinuxONE 4 machines, we recommend using the highest opset level as specified under NNPA operator support. This will generally be the first statement in the file linked above; for example as of July 2023 "Onnx-mlir currently supports ONNX operations targeting up to opset 18".

Determining whether model operations will target the IBM z16 or LinuxONE 4 on-chip accelerator:

When compiling with the IBM Z Deep Learning Compiler, you can get information and insights into various model operations and whether they will run on the accelerator. This can be critical information to help explore model performance.

Samples

Additionally, IBM has published samples for both TensorFlow and ONNX, available here: https://github.com/IBM/ai-on-z-samples